Module: NewRelic::Agent::Instrumentation::ActiveRecordHelper
- Included in:
- Sequel::NewRelicInstrumentation
- Defined in:
- lib/new_relic/agent/instrumentation/active_record_helper.rb
Class Method Summary collapse
- .metric_for_name(name) ⇒ Object
- .metric_for_sql(sql) ⇒ Object
-
.remote_service_metric(adapter, host) ⇒ Object
Given a database adapter name and a database server host this returns a metric name in the form: “RemoteService/sql/adapter/host” Host defaults to “localhost”.
-
.rollup_metrics_for(metric) ⇒ Object
Given a metric name such as “ActiveRecord/model/action” this returns an array of rollup metrics: [ “ActiveRecord/all”, “ActiveRecord/action” ] If the metric name is in the form of “ActiveRecord/action” this returns merely: [ “ActiveRecord/all” ].
Class Method Details
.metric_for_name(name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/new_relic/agent/instrumentation/active_record_helper.rb', line 10 def metric_for_name(name) return unless name parts = name.split(' ') if parts.size == 2 model = parts.first operation = parts.last.downcase case operation when 'load', 'count', 'exists' op_name = 'find' when 'indexes', 'columns' op_name = nil # fall back to DirectSQL when 'destroy', 'find', 'save', 'create' op_name = operation when 'update' op_name = 'save' else if model == 'Join' op_name = operation end end "ActiveRecord/#{model}/#{op_name}" if op_name end end |
.metric_for_sql(sql) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/new_relic/agent/instrumentation/active_record_helper.rb', line 34 def metric_for_sql(sql) metric = NewRelic::Agent::Transaction.database_metric_name if metric.nil? if sql =~ /^(select|update|insert|delete|show)/i # Could not determine the model/operation so let's find a better # metric. If it doesn't match the regex, it's probably a show # command or some DDL which we'll ignore. metric = "Database/SQL/#{$1.downcase}" else metric = "Database/SQL/other" end end metric end |
.remote_service_metric(adapter, host) ⇒ Object
Given a database adapter name and a database server host this returns a metric name in the form: “RemoteService/sql/adapter/host” Host defaults to “localhost”.
72 73 74 75 76 |
# File 'lib/new_relic/agent/instrumentation/active_record_helper.rb', line 72 def remote_service_metric(adapter, host) host ||= 'localhost' type = adapter.to_s.sub(/\d*/, '') "RemoteService/sql/#{type}/#{host}" end |
.rollup_metrics_for(metric) ⇒ Object
Given a metric name such as “ActiveRecord/model/action” this returns an array of rollup metrics:
- “ActiveRecord/all”, “ActiveRecord/action”
-
If the metric name is in the form of “ActiveRecord/action” this returns merely: [ “ActiveRecord/all” ]
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/new_relic/agent/instrumentation/active_record_helper.rb', line 54 def rollup_metrics_for(metric) metrics = [] # If we're outside of a web transaction, don't record any rollup # database metrics. This is to prevent metrics from background tasks # from polluting the metrics used to drive overview graphs. if NewRelic::Agent::Transaction.recording_web_transaction? metrics << "ActiveRecord/all" end metrics << "ActiveRecord/#{$1}" if metric =~ /ActiveRecord\/[\w|\:]+\/(\w+)/ metrics end |