LoginSignup
3
3

More than 5 years have passed since last update.

NewRelic APMを任意のホストのみに導入する方法

Last updated at Posted at 2016-05-12

TL:DR

NewRelic は1ホストあたり $149/month なので、全サーバーに導入することは難しい。
なので、全体の中から必要なホストのみ抽出し、監視する等のテクニックが必要となる。

itamaeが整っている環境では、rails_configのgemを使って、
settings.ymlをホスト毎に書き換えるのが最もよいだろう.

とはいえ、itamaeがそこまで整ってないプロダクトもあると思うので、
ここでは application.rbで指定する方法を用意した.

CODE

application.rb
module SampleProject
  class Application < Rails::Application
    config.newrelic_monitor_mode = (`hostname -f`).strip.in? %w(NEWRELIC_HOST)
  end
end
newrelic.yml
common: &default_settings
  license_key: <%= Settings.newrelic.license_key %>
  log_level: info
  developer_mode: false
  monitor_mode: false
production:
  <<: *default_settings
  monitor_mode: <%= SampleProject::Application.config.newrelic_monitor_mode %>

確認

deploy後に、下記のようなログが流れればOK.
log/newrelic_agent.log

[2016-05-11 xx:xx:xx +0900 URL (nn)] INFO : Reporting to: https://rpm.newrelic.com/accounts/:account_id/applications/
[2016-05-11 xx:xx:xx +0900 URL (nn)] INFO : Reporting to: https://rpm.newrelic.com/accounts/:account_id/applications/:application_id

そうでない場合は設定ファイルが間違っているかも知れないので、
Agentのconfigを確認する。

bundle exec rails c

irb(main):00n:0> NewRelic::Agent.config[:monitor_mode]
=> true
irb(main):00n:0> NewRelic::Agent.config[:license_key]
=> 'xxxxxxxxxxxxxxx'
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3