Class: RorVsWild::Plugin::Mongo

Inherits:
Object
  • Object
show all
Defined in:
lib/rorvswild/plugin/mongo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMongo

Returns a new instance of Mongo.


13
14
15
# File 'lib/rorvswild/plugin/mongo.rb', line 13

def initialize
  @commands = {}
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands


11
12
13
# File 'lib/rorvswild/plugin/mongo.rb', line 11

def commands
  @commands
end

Class Method Details

.setupObject


4
5
6
7
8
9
# File 'lib/rorvswild/plugin/mongo.rb', line 4

def self.setup
  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


30
31
32
33
34
35
# File 'lib/rorvswild/plugin/mongo.rb', line 30

def after_query(event)
  RorVsWild::Section.stop do |section|
    section.kind = "mongo".freeze
    section.command = commands.delete(event.request_id).to_s
  end
end

#failed(event) ⇒ Object


22
23
24
# File 'lib/rorvswild/plugin/mongo.rb', line 22

def failed(event)
  after_query(event)
end

#started(event) ⇒ Object


17
18
19
20
# File 'lib/rorvswild/plugin/mongo.rb', line 17

def started(event)
  RorVsWild::Section.start
  commands[event.request_id] = event.command
end

#succeeded(event) ⇒ Object


26
27
28
# File 'lib/rorvswild/plugin/mongo.rb', line 26

def succeeded(event)
  after_query(event)
end