Created
February 18, 2015 05:48
-
-
Save benweint/ba3069415d453b190f04 to your computer and use it in GitHub Desktop.
DB metrics broken out by host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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