module TingYun::Agent::Datastore::MetricHelper

Constants

ALL
ALL_BACKGROUND
ALL_WEB
CACHE
NOSQL
UNKNOWN

Public Class Methods

checkNosql(product) click to toggle source
# File lib/ting_yun/agent/datastore/metric_helper.rb, line 17
def self.checkNosql(product)
  NOSQL.include?(product)
end
include_database?(name) click to toggle source
# File lib/ting_yun/agent/datastore/metric_helper.rb, line 82
def self.include_database?(name)
  CACHE.include?(name)
end
metric_name(product, collection, operation,host,port,dbname) click to toggle source
# 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}/#{dbname}/#{collection}/#{operation}" if product=="MongoDB"
    "#{product}/#{host}:#{port}/#{collection}/#{operation}"
  else
    "Database #{product}/#{host}:#{port}/#{dbname}/#{collection}/#{operation}"
  end
end
metric_name_others(product, collection, operation) click to toggle source
# 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}/#{collection}/#{operation}"
  else
    "Database #{product}/#{collection}/#{operation}"
  end
end
metrics_for(product, operation, host = UNKNOWN, port = 0, dbname = UNKNOWN, collection = nil, generic_product = nil ) click to toggle source
# 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}/#{dbname}/All" :
                    "#{product}/#{host}:#{port}/All")
  else
    metrics << "Database #{product}/#{host}:#{port}/#{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() click to toggle source

Allow Transaction#with_database_metric_name to override our collection and operation

# File lib/ting_yun/agent/datastore/metric_helper.rb, line 87
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) click to toggle source
# 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) 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/ting_yun/agent/datastore/metric_helper.rb, line 96
def self.should_override?(overrides, product, generic_product)
  override_product = overrides[2]

  override_product.nil? ||
      override_product == product ||
      override_product == generic_product
end