Enable NewRelic monitoring [for Rails] on specific hosts only

Posted . Visible to the public.

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:

  1. Put the attached file into your config directory (config/custom_new_relic_configuration.rb).
  2. Specify on which hosts NewRelic should be enabled (see NEWRELIC_HOSTS constant and list the full hostnames (FQDN) of the machines).
  3. Put this on top of your NewRelic configuration (which is config/newrelic.yml usually): require 'custom_new_relic_configuration'
  4. 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.

Thomas Eisenbarth
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Thomas Eisenbarth to makandra dev (2013-10-19 16:09)