LoginSignup
4
2

More than 5 years have passed since last update.

New Relic APMで監視するホストの限定方法[Rails]

Last updated at Posted at 2018-01-17

RailsにNew Relic APMを導入する時に監視対象のホストを限定する方法を紹介します。

New Relic APMの導入方法と設定

なんで監視するホストを限定したいのか

New Relic APM のProはホスト課金です。
契約台数の都合上、特定のサーバーだけに限定したいときがあるからです。

設定手順

production環境の特定ホストのみ監視させたい場合の例

  1. config/custom_new_relic_configuration.rbを読み込む設定を追加します

    config/application.rb
    require_relative './custom_new_relic_configuration'
    
  2. 特定ホストか判定するメソッドを作成します。

    config/custom_new_relic_configuration.rb
    require 'socket'
    
    class CustomNewRelicConfiguration
      ENABLED_NEWRELIC_HOST = 'host.example.com'
    
      def self.enable_on_current_host?
        ENABLED_NEWRELIC_HOST == Socket.gethostname
      end
    end
    
  3. デフォルトでは監視させないようにして、productionだけ作成したメソッドで判定させます。

    config/newrelic.yml
    common: &default_settings
      monitor_mode: false
    
    production:
      <<: *default_settings
      monitor_mode: <%= CustomNewRelicConfiguration.enable_on_current_host? %>
    
    

参考

4
2
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
4
2