module NewRelic::Agent::Datastores::MetricHelper
Constants
- ALL
- ALL_OTHER
- ALL_WEB
- DEFAULT_PRODUCT_NAME
- OTHER
- OTHER_ROLLUP_METRIC
- ROLLUP_METRIC
- WEB_ROLLUP_METRIC
Public Class Methods
all_suffix()
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 38 def self.all_suffix if NewRelic::Agent::Transaction.recording_web_transaction? ALL_WEB else ALL_OTHER end end
metrics_for(product, operation, collection = nil, generic_product = nil)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 46 def self.metrics_for(product, operation, collection = nil, generic_product = nil) if overrides = overridden_operation_and_collection if should_override?(overrides, product, generic_product) operation = overrides[0] || operation collection = overrides[1] || collection end end suffix = all_suffix # Order of these metrics matters--the first metric in the list will # be treated as the scoped metric in a bunch of different cases. metrics = [ operation_metric_for(product, operation), product_suffixed_rollup(product, suffix), product_rollup(product), suffixed_rollup(suffix), ROLLUP_METRIC ] metrics.unshift statement_metric_for(product, collection, operation) if collection metrics end
metrics_from_sql(product, sql)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 71 def self.metrics_from_sql(product, sql) operation = NewRelic::Agent::Database.parse_operation_from_query(sql) || OTHER metrics_for(product, operation) end
operation_metric_for(product, operation)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 22 def self.operation_metric_for(product, operation) "Datastore/operation/#{product}/#{operation}" end
overridden_operation_and_collection()
click to toggle source
Allow NewRelic::Agent::Transaction#with_database_metric_name to override our collection and operation
# File lib/new_relic/agent/datastores/metric_helper.rb, line 78 def self.overridden_operation_and_collection #THREAD_LOCAL_ACCESS state = NewRelic::Agent::TransactionState.tl_get txn = state.current_transaction txn ? txn.instrumentation_state[:datastore_override] : nil end
product_rollup(product)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 30 def self.product_rollup(product) "Datastore/#{product}/all" end
product_suffixed_rollup(product, suffix)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 26 def self.product_suffixed_rollup(product, suffix) "Datastore/#{product}/#{suffix}" end
should_override?(overrides, product, generic_product)
click to toggle source
If the override declared a product affiliation, abide by that ActiveRecord has database-specific product names, so we recognize it by the generic_product it passes.
# File lib/new_relic/agent/datastores/metric_helper.rb, line 87 def self.should_override?(overrides, product, generic_product) override_product = overrides[2] override_product.nil? || override_product == product || override_product == generic_product end
statement_metric_for(product, collection, operation)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 18 def self.statement_metric_for(product, collection, operation) "Datastore/statement/#{product}/#{collection}/#{operation}" end
suffixed_rollup(suffix)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 34 def self.suffixed_rollup(suffix) "Datastore/#{suffix}" end