Skip to content

Instantly share code, notes, and snippets.

@benweint
Created February 18, 2015 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benweint/ba3069415d453b190f04 to your computer and use it in GitHub Desktop.
Save benweint/ba3069415d453b190f04 to your computer and use it in GitHub Desktop.
DB metrics broken out by host
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start_time, end_time, guid, opts|
connection_id = opts[:connection_id]
if connection_id
conn = ObjectSpace._id2ref(connection_id)
if conn
config = conn.instance_variable_get(:@config)
if config
host = config[:host]
adapter = config[:adapter]
if host && adapter
metric = "ShardQueries/sql/#{adapter}/#{host}"
duration = end_time - start_time
NewRelic::Agent.record_metric(metric, duration)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment