views:

78

answers:

2

I'm using New Relic for Rails, but only need New Relic to monitor my one production environment. However, I have a staging server that also runs in Production mode. New Relic detects both as operating prod instances of my application (as it should), but I don't want to have to pay for monitoring two instances when I only want to keep an eye on the one.

New Relic accepts an environment variable for the license key:

license_key: <%= ENV['NEWRELIC_ACCOUNT_KEY'] %>

Is it possible to detect the hostname in the environment files (i.e. config/environments/production.rb) so that I can define this environment variable dynamically?

Both environments are deployed from the same Git repository, same source code base, so I can't really change it in the code for each deploy - it would be best to be able to define the environment variable dynamically somehow.

Any thoughts would be appreciated! Thanks!

A: 

The host name is only available in a request object, so no, it's not available when rails builds the environment.

I would just set up your staging deploy script to copy production.rb to staging.rb and start up the app in "staging". Another technique would be to not keep the newrelic.yml in your scm and instead copy it, or link it, from somewhere else to the current deploy directory.

BJ Clark
A: 

Have you created a separate environment for staging? i.e. development, test, production, and staging? See here for instructions…

Having done that, one can specify behaviour for that environment in config/newrelic.yml

common: &default_settings
  license_key: 'PASTE_YOUR_KEY_HERE'
  …

development:
  enabled: false
  …

test:
  enabled: false
  …

production:
  enabled: true
  …

staging: 
  enabled: false
  …

etc, etc

Steve Graham
Steve, thanks for your insights. I didn't realize that you could specify environments in the newrelic yml file. Interestingly, when I asked New Relic support about this same question, they didn't mention this either. I'll give this a whirl and see how it works. Thanks!
shedd