Module: NewRelic::Agent::Datastores::MetricHelper
- Defined in:
- lib/new_relic/agent/datastores/metric_helper.rb
Constant Summary collapse
- ROLLUP_METRIC =
'Datastore/all'.freeze
- OTHER =
'Other'.freeze
- ALL =
'all'.freeze
- ALL_WEB =
'allWeb'.freeze
- ALL_OTHER =
'allOther'.freeze
Class Method Summary collapse
- .all_suffix ⇒ Object
- .instance_metric_for(product, host, port_path_or_id) ⇒ Object
- .metrics_for(product, operation, collection = nil, generic_product = nil, host = nil, port_path_or_id = nil) ⇒ Object
- .metrics_from_sql(product, sql) ⇒ Object
- .operation_from_sql(sql) ⇒ Object
- .operation_metric_for(product, operation) ⇒ Object
-
.overridden_operation_and_collection ⇒ Object
Allow Transaction#with_database_metric_name to override our collection and operation.
- .product_operation_collection_for(product, operation, collection = nil, generic_product = nil) ⇒ Object
- .product_rollup(product) ⇒ Object
- .product_suffixed_rollup(product, suffix) ⇒ Object
- .scoped_metric_for(product, operation, collection = nil) ⇒ Object
-
.should_override?(overrides, product, generic_product) ⇒ Boolean
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.
- .statement_metric_for(product, collection, operation) ⇒ Object
- .suffixed_rollup(suffix) ⇒ Object
- .unscoped_metrics_for(product, operation, collection = nil, host = nil, port_path_or_id = nil) ⇒ Object
Class Method Details
.all_suffix ⇒ Object
40 41 42 43 44 45 46 |
# 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) ⇒ Object
24 25 26 |
# 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) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
95 96 97 98 |
# 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) ⇒ Object
100 101 102 103 104 |
# 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) ⇒ Object
20 21 22 |
# 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 ⇒ Object
Allow Transaction#with_database_metric_name to override our collection and operation
108 109 110 111 |
# 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) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# 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) ⇒ Object
32 33 34 |
# 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) ⇒ Object
28 29 30 |
# 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) ⇒ Object
48 49 50 51 52 53 54 |
# 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) ⇒ Boolean
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.
116 117 118 119 120 121 122 |
# 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) ⇒ Object
16 17 18 |
# 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) ⇒ Object
36 37 38 |
# 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) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# 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 |