Class: RorVsWild::Plugin::Mongo
- Inherits:
-
Object
- Object
- RorVsWild::Plugin::Mongo
- Defined in:
- lib/rorvswild/plugin/mongo.rb
Constant Summary collapse
- QUERY_ROOT_KEYS =
%w[ insert update delete findAndModify bulkWrite find aggregate count distinct create drop listCollections listDatabases dropDatabase startSession commitTransaction abortTransaction filter getMore collection sort ]
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Class Method Summary collapse
Instance Method Summary collapse
- #after_query(event) ⇒ Object
- #failed(event) ⇒ Object
- #normalize_array(array) ⇒ Object
- #normalize_hash(hash) ⇒ Object
- #normalize_query(query) ⇒ Object
- #normalize_value(value) ⇒ Object
- #started(event) ⇒ Object
- #succeeded(event) ⇒ Object
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
15 16 17 |
# File 'lib/rorvswild/plugin/mongo.rb', line 15 def commands @commands end |
Class Method Details
.setup(agent) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/rorvswild/plugin/mongo.rb', line 8 def self.setup(agent) return if @installed return if !defined?(::Mongo::Monitoring::Global) ::Mongo::Monitoring::Global.subscribe(::Mongo::Monitoring::COMMAND, Mongo.new) @installed = true end |
Instance Method Details
#after_query(event) ⇒ Object
31 32 33 |
# File 'lib/rorvswild/plugin/mongo.rb', line 31 def after_query(event) RorVsWild::Section.stop end |
#failed(event) ⇒ Object
23 24 25 |
# File 'lib/rorvswild/plugin/mongo.rb', line 23 def failed(event) after_query(event) end |
#normalize_array(array) ⇒ Object
54 55 56 |
# File 'lib/rorvswild/plugin/mongo.rb', line 54 def normalize_array(array) array.map { |value| normalize_value(value) } end |
#normalize_hash(hash) ⇒ Object
50 51 52 |
# File 'lib/rorvswild/plugin/mongo.rb', line 50 def normalize_hash(hash) (hash = hash.to_h).each { |key, val| hash[key] = normalize_value(val) } end |
#normalize_query(query) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rorvswild/plugin/mongo.rb', line 43 def normalize_query(query) query = query.slice(*QUERY_ROOT_KEYS) query["filter"] = normalize_hash(query["filter"]) if query["filter"] query["getMore"] = normalize_value(query["getMore"]) if query["getMore"] query end |
#normalize_value(value) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rorvswild/plugin/mongo.rb', line 58 def normalize_value(value) case value when Hash then normalize_hash(value.to_h) when Array then normalize_array(value) when FalseClass then false when TrueClass then true when NilClass then nil else "?" end end |
#started(event) ⇒ Object
17 18 19 20 21 |
# File 'lib/rorvswild/plugin/mongo.rb', line 17 def started(event) section = RorVsWild::Section.start section.kind = "mongo" section.commands << normalize_query(event.command).to_json end |
#succeeded(event) ⇒ Object
27 28 29 |
# File 'lib/rorvswild/plugin/mongo.rb', line 27 def succeeded(event) after_query(event) end |