Targeting New Relic to run only on 1 (of 3) app servers
Asked Answered
C

2

7

Our medium-sized rails app runs (in production) on three servers. We've just finished a trial period, using New Relic as a gem. During the trial period we tracked all three servers, but to continue with a subscription we only need (and only have the budget) to track app1.

So we need to disable new relic on app2 and app3. In communication with their customer service I'm told this is possible and have been directed to the last entry on this page but I can't quite figure out how this helps me to disable new relic tracking on the other two servers, in particular because there's no newrelic_rpm mentioned in environment.rb - it's a gem, after all, and is therefore only mentioned in the Gemfile.

There is a agent_enabled boolean option in newrelic.yml which I thought we could set on a per-server basis, but I don't know how to do this. Is there a way to find out which server we're on in rails, similar to the RAILS_ENV variable?

Cameroncameroon answered 14/3, 2012 at 12:0 Comment(2)
What are you using for deployments? capistrano?Halitosis
Yep, via the capper gem. We have a monitor in our capfile that notifies new relic when we deploy, otherwise everything is configured via the gem and newrelic.ymlCameroncameroon
L
11

The newrelic.yml file is rendered with ERB before the agent reads the config values. So you can do this:

monitor_mode: <%= 'app1' == Socket.gethostname ? 'true' : 'false' %>

That will enable the agent reporting to New Relic only for that one host.

Leucoderma answered 16/3, 2012 at 15:29 Comment(2)
This would be fantastic if it worked but it has disabled tracking on all servers, including app1. How/where exactly is the ERB rendering taking place?Cameroncameroon
I should have noticed that too...stupid HAML making me forget things!Cameroncameroon
H
1

I would suggest linking newrelic.yml only on the server where it is needed. To make this happen remove config/newrelic.yml from you repository completely and put in into the shared directory in your servers instead.

Then link this file only for a certain role in capistrano again into config/newrelic.yml. You may introduce a new role that only contains your app1 server.

The new relic gem is build fail-safe. So it's just disabled in that case.

Halitosis answered 14/3, 2012 at 12:49 Comment(3)
Removing config/newrelic.yml altogether makes newrelic_rpm throw an error every time it is loaded, which gets pretty tiresome in development. Otherwise this would be a great solution. Our current plan is to have two additional files, newrelic_disabled/_enabled.yml, and to overwrite newrelic.yml with these on deploy.Cameroncameroon
You mean a warning right? If you ignore that file via git an put on there in you development copy you would also get around the warning.Halitosis
Yep, a warning, not an error, sorry. That's a cool trick! I'll definitely bear it in mind for the future, I'm always surprised to remember that files can exist outside of the git repo as well :) In this case we'll stick with our deploy method to avoid having to transfer files between the team the old-fashioned way tho, it might become a headache later. Thanks very much for your help!Cameroncameroon

© 2022 - 2024 — McMap. All rights reserved.