module NewRelic::Agent::Datastores::MetricHelper
Constants
- ALL
- ALL_OTHER
- ALL_WEB
- OTHER
- ROLLUP_METRIC
Public Class Methods
all_suffix()
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 40 def self.all_suffix if NewRelic::Agent::Transaction.recording_web_transaction? ALL_WEB else ALL_OTHER end end
instance_metric_for(product, host, port_path_or_id)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 24 def self.instance_metric_for(product, host, port_path_or_id) "Datastore/instance/#{product}/#{host}/#{port_path_or_id}" end
metrics_for(product, operation, collection = nil, generic_product = nil, host = nil, port_path_or_id = nil)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 84 def self.metrics_for(product, operation, collection = nil, generic_product = nil, host = nil, port_path_or_id = nil) product, operation, collection = product_operation_collection_for(product, operation, collection, generic_product) # 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 = unscoped_metrics_for(product, operation, collection, host, port_path_or_id) metrics.unshift(scoped_metric_for(product, operation, collection)) metrics end
metrics_from_sql(product, sql)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 95 def self.metrics_from_sql(product, sql) operation = operation_from_sql(sql) metrics_for(product, operation) end
operation_from_sql(sql)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 100 def self.operation_from_sql(sql) operation = NewRelic::Agent::Database.parse_operation_from_query(sql) operation = OTHER if operation.eql?(NewRelic::Agent::Database::OTHER_OPERATION) operation end
operation_metric_for(product, operation)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 20 def self.operation_metric_for(product, operation) "Datastore/operation/#{product}/#{operation}" end
overridden_operation_and_collection()
click to toggle source
Allow Transaction#with_database_metric_name
to override our collection and operation
# File lib/new_relic/agent/datastores/metric_helper.rb, line 108 def self.overridden_operation_and_collection # THREAD_LOCAL_ACCESS txn = Tracer.current_transaction txn ? txn.instrumentation_state[:datastore_override] : nil end
product_operation_collection_for(product, operation, collection = nil, generic_product = nil)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 74 def self.product_operation_collection_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 [product, operation, collection] end
product_rollup(product)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 32 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 28 def self.product_suffixed_rollup(product, suffix) "Datastore/#{product}/#{suffix}" end
scoped_metric_for(product, operation, collection = nil)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 48 def self.scoped_metric_for(product, operation, collection = nil) if collection statement_metric_for(product, collection, operation) else operation_metric_for(product, operation) end 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 116 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 16 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 36 def self.suffixed_rollup(suffix) "Datastore/#{suffix}" end
unscoped_metrics_for(product, operation, collection = nil, host = nil, port_path_or_id = nil)
click to toggle source
# File lib/new_relic/agent/datastores/metric_helper.rb, line 56 def self.unscoped_metrics_for(product, operation, collection = nil, host = nil, port_path_or_id = nil) suffix = all_suffix metrics = [ product_suffixed_rollup(product, suffix), product_rollup(product), suffixed_rollup(suffix), ROLLUP_METRIC ] if NewRelic::Agent.config[:'datastore_tracer.instance_reporting.enabled'] && host && port_path_or_id metrics.unshift(instance_metric_for(product, host, port_path_or_id)) end metrics.unshift(operation_metric_for(product, operation)) if collection metrics end