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
- UNKNOWN =
'Unknown'.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, host, port, dbname) ⇒ Object
- .metric_name_others(product, collection, operation) ⇒ Object
- .metrics_for(product, operation, host = UNKNOWN, port = 0, dbname = UNKNOWN, 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
81 82 83 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 81 def self.include_database?(name) CACHE.include?(name) end |
.metric_name(product, collection, operation, host, port, dbname) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 21 def self.metric_name(product, collection, operation,host,port,dbname) if checkNosql(product) return "#{product}/#{host}:#{port}%2F#{dbname}%2F#{collection}/#{operation}" if product=="MongoDB" "#{product}/#{host}:#{port}%2F#{collection}/#{operation}" else "Database #{product}/#{host}:#{port}%2F#{dbname}%2F#{collection}/#{operation}" end end |
.metric_name_others(product, collection, operation) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 30 def self.metric_name_others(product, collection, operation) collection ||= 'NULL' if checkNosql(product) "#{product}%2F#{collection}/#{operation}" else "Database #{product}%2F#{collection}/#{operation}" end end |
.metrics_for(product, operation, host = UNKNOWN, port = 0, dbname = UNKNOWN, collection = nil, generic_product = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 47 def self.metrics_for(product, operation, host = UNKNOWN, port = 0, dbname = UNKNOWN, collection = nil, generic_product = nil ) dbname ||= UNKNOWN host ||= UNKNOWN port ||= UNKNOWN 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 if checkNosql(product) metrics << (product=="MongoDB" ? "#{product}/#{host}:#{port}%2F#{dbname}/All" : "#{product}/#{host}:#{port}/All") else metrics << "Database #{product}/#{host}:#{port}%2F#{dbname}/All" end metrics.unshift metric_name(product, collection, operation,host,port,dbname) if collection metrics.unshift "#{product}/#{host}:#{port}/#{operation}" if product=="Memcached" metrics.unshift metric_name_others(product, collection, operation) metrics end |
.overridden_operation_and_collection ⇒ Object
Allow Transaction#with_database_metric_name to override our collection and operation
86 87 88 89 90 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 86 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
39 40 41 42 43 44 45 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 39 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.
95 96 97 98 99 100 101 |
# File 'lib/ting_yun/agent/datastore/metric_helper.rb', line 95 def self.should_override?(overrides, product, generic_product) override_product = overrides[2] override_product.nil? || override_product == product || override_product == generic_product end |