module Mmtrix::Agent::Datastores::Mongo::MetricTranslator
Constants
- CMD_COLLECTION
- MONGO_PRODUCT_NAME
- NAMES_IN_SELECTOR
Public Class Methods
build_metrics(name, collection)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 62 def self.build_metrics(name, collection) Mmtrix::Agent::Datastores::MetricHelper.metrics_for(MONGO_PRODUCT_NAME, name, collection) end
collection_in_selector?(payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 68 def self.collection_in_selector?(payload) payload[:collection] == '$cmd' && payload[:selector] end
collection_name_from_group_selector(payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 176 def self.collection_name_from_group_selector(payload) payload[:selector]["group"]["ns"] end
collection_name_from_index(payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 158 def self.collection_name_from_index(payload) if payload[:documents] if payload[:documents].is_a?(Array) # mongo gem versions pre 1.10.0 document = payload[:documents].first else # mongo gem versions 1.10.0 and later document = payload[:documents] end if document && document[:ns] return document[:ns].split('.').last end end 'system.indexes' end
collection_name_from_rename_selector(payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 180 def self.collection_name_from_rename_selector(payload) parts = payload[:selector][:renameCollection].split('.') parts.shift parts.join('.') end
command_key_from_selector(payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 91 def self.command_key_from_selector(payload) selector = payload[:selector] NAMES_IN_SELECTOR.find do |check_name| selector.key?(check_name) end end
create_index?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 134 def self.create_index?(name, payload) name == :insert && payload[:collection] == "system.indexes" end
create_indexes?(name, paylod)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 130 def self.create_indexes?(name, paylod) name == :createIndexes end
drop_index?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 142 def self.drop_index?(name, payload) name == :deleteIndexes end
drop_indexes?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 138 def self.drop_indexes?(name, payload) name == :deleteIndexes && payload[:selector] && payload[:selector][:index] == "*" end
find_and_modify?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 122 def self.find_and_modify?(name, payload) name == :findandmodify end
find_and_remove?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 126 def self.find_and_remove?(name, payload) name == :findandmodify && payload[:selector] && payload[:selector][:remove] end
find_one?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 118 def self.find_one?(name, payload) name == :find && payload[:limit] == -1 end
get_collection_from_selector(command_key, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 109 def self.get_collection_from_selector(command_key, payload) if command_key payload[:selector][command_key] else Mmtrix::Agent.increment_metric("Supportability/Mongo/UnknownCollection") CMD_COLLECTION end end
get_name_from_selector(command_key, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 98 def self.get_name_from_selector(command_key, payload) if command_key command_key.to_sym else Mmtrix::Agent.increment_metric("Supportability/Mongo/UnknownCollection") payload[:selector].first.first unless command_key end end
group?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 150 def self.group?(name, payload) name == :group end
metrics_for(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 13 def self.metrics_for(name, payload) payload ||= {} if collection_in_selector?(payload) command_key = command_key_from_selector(payload) name = get_name_from_selector(command_key, payload) collection = get_collection_from_selector(command_key, payload) else collection = payload[:collection] end # The 1.10.0 version of the mongo driver renamed 'remove' to # 'delete', but for metric consistency with previous versions we # want to keep it as 'remove'. name = 'remove' if name.to_s == 'delete' if self.find_one?(name, payload) name = 'findOne' elsif self.find_and_remove?(name, payload) name = 'findAndRemove' elsif self.find_and_modify?(name, payload) name = 'findAndModify' elsif self.create_indexes?(name, payload) name = 'createIndexes' elsif self.create_index?(name, payload) name = 'createIndex' collection = self.collection_name_from_index(payload) elsif self.drop_indexes?(name, payload) name = 'dropIndexes' elsif self.drop_index?(name, payload) name = 'dropIndex' elsif self.re_index?(name, payload) name = 'reIndex' elsif self.group?(name, payload) name = 'group' collection = collection_name_from_group_selector(payload) elsif self.rename_collection?(name, payload) name = 'renameCollection' collection = collection_name_from_rename_selector(payload) end build_metrics(name, collection) rescue => e Mmtrix::Agent.logger.debug("Failure during Mongo metric generation", e) [] end
re_index?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 146 def self.re_index?(name, payload) name == :reIndex && payload[:selector] && payload[:selector][:reIndex] end
rename_collection?(name, payload)
click to toggle source
# File lib/mmtrix/agent/datastores/mongo/metric_translator.rb, line 154 def self.rename_collection?(name, payload) name == :renameCollection end