Module: OneApm::Agent::Instrumentation::ActiveRecordHelper
- Included in:
- Sequel::OneApmInstrumentation
- Defined in:
- lib/one_apm/agent/database/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 “Database/model/action” this returns an array of rollup metrics: [ “Database/all”, “Database/all”, “Database/action” ] If the metric name is in the form of “Database/action” this returns merely: [ “Database/all”, “Database/all” ].
Class Method Details
.metric_for_name(name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/one_apm/agent/database/active_record_helper.rb', line 9 def metric_for_name(name) return unless name && name.respond_to?(:split) parts = name.split(' ') if parts.size == 2 model = parts.first operation = parts.last.downcase case operation when 'find', 'load', 'count', 'exists' op_name = 'select' when 'destroy' op_name = 'delete' when 'create' op_name = 'insert' when 'update', 'save' op_name = 'update' else op_name = nil end "Database/#{model}/#{op_name}" if op_name end end |
.metric_for_sql(sql) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/one_apm/agent/database/active_record_helper.rb', line 31 def metric_for_sql(sql) txn = OneApm::Transaction.tl_current metric = txn && txn.database_metric_name if metric.nil? operation = OneApm::Agent::Database.parse_operation_from_query(sql) if operation # Could not determine the model/operation so use a fallback metric metric = "Database/SQL/#{operation}" 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”.
71 72 73 74 75 |
# File 'lib/one_apm/agent/database/active_record_helper.rb', line 71 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 “Database/model/action” this returns an array of rollup metrics:
- “Database/all”, “Database/all”, “Database/action”
-
If the metric name is in the form of “Database/action” this returns merely: [ “Database/all”, “Database/all” ]
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/one_apm/agent/database/active_record_helper.rb', line 51 def rollup_metrics_for(metric) metrics = ["Database/all"] # 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 OneApm::Transaction.recording_web_transaction? metrics << "Database/allWeb" else metrics << "Database/allOther" end metrics << "Database/#{$1}" if metric =~ /Database\/[\w|\:]+\/(\w+)/ metrics end |