Ruby on Kubernetes: Newrelic

– Report each environment as separate app
– Report namespace so we can track down where misbehaving pods live

    # config/application.rb (not in initializers)
    if ENV['POD_NAMESPACE'] # on kubernetes
      # report each env into a separate project
      NewRelic::Agent::Configuration::Manager.class_eval do
        undef app_names
        def app_names
          name = ENV.fetch('NEW_RELIC_APP_NAME')
          name += " #{Rails.env}" unless Rails.env.production?
          [name]
        end
      end

      # report namespace so we can track down where a troublesome pod lives
      # newrelic_rpm 3.18.0+ has a NEW_RELIC_PROCESS_HOST_DISPLAY_NAME setting which is supposed to do that, but did not work.
      class << NewRelic::Agent::Hostname
        def get
          "#{ENV.fetch('POD_NAME')}.#{ENV.fetch('POD_NAMESPACE')}"
        end
      end
    end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s