If you need to enable NewRelic monitoring on certain machines within the same Rails environment, a simple solution is to utilize the respective hostnames of you machines.
For example, if you have 8 application servers (e.g. app1.example.com
, app2.example.com
, ...) and want to enable NewRelic on app1
and app2
only, utilize those steps to do so:
config/custom_new_relic_configuration.rb
).NEWRELIC_HOSTS
constant and list the full hostnames (FQDN) of the machines).config/newrelic.yml
usually): require 'custom_new_relic_configuration'
newrelic.yml
(production environment in the example below), change your settings like this:production:
<<: *default_settings
# NewRelic should be enabled on some specific hosts on production only
# See config/new_relic_configuration.rb how to enable on a specific host.
monitor_mode: <%= CustomNewRelicConfiguration.enable_on_current_host? %>
FYI: The newrelic.yml
config file is ERB parsed when the Rails environment is booted, CustomNewRelicConfiguration.enable_on_current_host?
gets evaluated and NewRelic is enabled on the hosts specified in your custom configuration class only.