Read more

Enable NewRelic monitoring [for Rails] on specific hosts only

Thomas Eisenbarth
October 19, 2013Software engineer at makandra GmbH

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.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

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.

Posted by Thomas Eisenbarth to makandra dev (2013-10-19 18:09)