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:
- Put the attached file into your config directory (
config/custom_new_relic_configuration.rb
). - Specify on which hosts NewRelic should be enabled (see
NEWRELIC_HOSTS
constant and list the full hostnames (FQDN) of the machines). - Put this on top of your NewRelic configuration (which is
config/newrelic.yml
usually):require 'custom_new_relic_configuration'
- Finally, enable your custom configuration: In the respective environment section in
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.