Module: TingYun::Agent::Datastore::MetricHelper
- Defined in:
- lib/ting_yun/agent/datastore/metric_helper.rb
Constant Summary collapse
- ALL_WEB =
"AllWeb".freeze
- ALL_BACKGROUND =
"AllBackground".freeze
- ALL =
"All".freeze
- NOSQL =
%w(MongoDB Redis Memcached).freeze
- CACHE =
%w(Redis Memcached).freeze
Class Method Summary collapse
- .checkNosql(product) ⇒ Object
- .include_database?(name) ⇒ Boolean
- .metric_name(product, collection, operation) ⇒ Object
- .metrics_for(product, operation, collection = nil, generic_product = nil) ⇒ Object
-
.overridden_operation_and_collection ⇒ Object
Allow Transaction#with_database_metric_name to override our collection and operation.
- .product_suffixed_rollup(product, suffix) ⇒ 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.
Class Method Details
.checkNosql(product) ⇒ Object
17 18 19 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 17 def self.checkNosql(product) NOSQL.include?(product) end |
.include_database?(name) ⇒ Boolean
63 64 65 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 63 def self.include_database?(name) CACHE.include?(name) end |
.metric_name(product, collection, operation) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 21 def self.metric_name(product, collection, operation) if checkNosql(product) "#{product}/#{collection}/#{operation}" else "Database #{product}/#{collection}/#{operation}" end end |
.metrics_for(product, operation, collection = nil, generic_product = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 39 def self.metrics_for(product, operation, collection = nil, generic_product = nil) operation = operation.to_s.upcase if overrides = overridden_operation_and_collection # [method, model_name, product] if should_override?(overrides, product, generic_product) operation = overrides[0] || operation collection = overrides[1] || collection end end metrics = [operation] if TingYun::Agent::Transaction.recording_web_transaction? metrics = metrics + [ALL_WEB,ALL] else metrics = metrics + [ALL_BACKGROUND,ALL] end metrics = metrics.map do |suffix| product_suffixed_rollup(product,suffix) end metrics.unshift metric_name(product, collection, operation) if collection metrics end |
.overridden_operation_and_collection ⇒ Object
Allow Transaction#with_database_metric_name to override our collection and operation
68 69 70 71 72 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 68 def self.overridden_operation_and_collection #THREAD_LOCAL_ACCESS state = TingYun::Agent::TransactionState.tl_get txn = state.current_transaction txn ? txn.instrumentation_state[:datastore_override] : nil end |
.product_suffixed_rollup(product, suffix) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 29 def self.product_suffixed_rollup(product,suffix) if checkNosql(product) "#{product}/NULL/#{suffix}" else "Database #{product}/NULL/#{suffix}" 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.
77 78 79 80 81 82 83 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 77 def self.should_override?(overrides, product, generic_product) override_product = overrides[2] override_product.nil? || override_product == product || override_product == generic_product end |