module NewRelic::Agent::Datastores::Mongo::MetricTranslator
Constants
- CMD_COLLECTION
- NAMES_IN_SELECTOR
Public Class Methods
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 60 def self.collection_in_selector?(payload) payload[:collection] == '$cmd' && payload[:selector] end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 168 def self.collection_name_from_group_selector(payload) payload[:selector]['group']['ns'] end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 150 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
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 172 def self.collection_name_from_rename_selector(payload) parts = payload[:selector][:renameCollection].split('.') parts.shift parts.join('.') end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 83 def self.command_key_from_selector(payload) selector = payload[:selector] NAMES_IN_SELECTOR.find do |check_name| selector.key?(check_name) end end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 126 def self.create_index?(name, payload) name == :insert && payload[:collection] == 'system.indexes' end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 122 def self.create_indexes?(name, _payload) name == :createIndexes end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 134 def self.drop_index?(name, payload) name == :deleteIndexes end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 130 def self.drop_indexes?(name, payload) name == :deleteIndexes && payload[:selector] && payload[:selector][:index] == ASTERISK end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 114 def self.find_and_modify?(name, payload) name == :findandmodify end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 118 def self.find_and_remove?(name, payload) name == :findandmodify && payload[:selector] && payload[:selector][:remove] end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 110 def self.find_one?(name, payload) name == :find && payload[:limit] == -1 end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 101 def self.get_collection_from_selector(command_key, payload) if command_key payload[:selector][command_key] else NewRelic::Agent.increment_metric('Supportability/Mongo/UnknownCollection') CMD_COLLECTION end end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 90 def self.get_name_from_selector(command_key, payload) if command_key command_key.to_sym else NewRelic::Agent.increment_metric('Supportability/Mongo/UnknownCollection') payload[:selector].first.first unless command_key end end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 142 def self.group?(name, payload) name == :group end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 13 def self.operation_and_collection_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 [name.to_s, collection] rescue => e NewRelic::Agent.logger.debug('Failure during Mongo metric generation', e) nil end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 138 def self.re_index?(name, payload) name == :reIndex && payload[:selector] && payload[:selector][:reIndex] end
Source
# File lib/new_relic/agent/datastores/mongo/metric_translator.rb, line 146 def self.rename_collection?(name, payload) name == :renameCollection end