Class: Mongo::Monitoring
- Inherits:
-
Object
- Object
- Mongo::Monitoring
- Defined in:
- lib/mongo/monitoring.rb,
lib/mongo/monitoring/publishable.rb,
lib/mongo/monitoring/event/secure.rb,
lib/mongo/monitoring/event/command_failed.rb,
lib/mongo/monitoring/event/command_started.rb,
lib/mongo/monitoring/command_log_subscriber.rb,
lib/mongo/monitoring/event/command_succeeded.rb
Overview
The class defines behaviour for the performance monitoring API.
Defined Under Namespace
Modules: Event, Global, Publishable Classes: CommandLogSubscriber
Constant Summary collapse
- COMMAND =
The command topic.
'Command'.freeze
- @@operation_id =
0
- @@operation_id_lock =
Mutex.new
Class Method Summary collapse
-
.next_operation_id ⇒ Integer
Used for generating unique operation ids to link events together.
Instance Method Summary collapse
-
#failed(topic, event) ⇒ Object
Publish a failed event.
-
#initialize(options = {}) ⇒ Monitoring
constructor
private
Initialize the monitoring.
-
#started(topic, event) ⇒ Object
Publish a started event.
-
#subscribe(topic, subscriber) ⇒ Object
Subscribe a listener to an event topic.
-
#subscribers ⇒ Hash<String, Object>
Get all the subscribers.
-
#subscribers?(topic) ⇒ true, false
Determine if there are any subscribers for a particular event.
-
#succeeded(topic, event) ⇒ Object
Publish a succeeded event.
Constructor Details
#initialize(options = {}) ⇒ Monitoring
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the monitoring.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mongo/monitoring.rb', line 96 def initialize( = {}) if [:monitoring] != false Global.subscribers.each do |topic, subscribers| subscribers.each do |subscriber| subscribe(topic, subscriber) end end subscribe(COMMAND, CommandLogSubscriber.new()) end end |
Class Method Details
.next_operation_id ⇒ Integer
Used for generating unique operation ids to link events together.
42 43 44 45 46 |
# File 'lib/mongo/monitoring.rb', line 42 def self.next_operation_id @@operation_id_lock.synchronize do @@operation_id += 1 end end |
Instance Method Details
#failed(topic, event) ⇒ Object
Publish a failed event.
142 143 144 |
# File 'lib/mongo/monitoring.rb', line 142 def failed(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.failed(event) } end |
#started(topic, event) ⇒ Object
Publish a started event.
116 117 118 |
# File 'lib/mongo/monitoring.rb', line 116 def started(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.started(event) } end |
#subscribe(topic, subscriber) ⇒ Object
Subscribe a listener to an event topic.
155 156 157 |
# File 'lib/mongo/monitoring.rb', line 155 def subscribe(topic, subscriber) subscribers_for(topic).push(subscriber) end |
#subscribers ⇒ Hash<String, Object>
Get all the subscribers.
167 168 169 |
# File 'lib/mongo/monitoring.rb', line 167 def subscribers @subscribers ||= {} end |
#subscribers?(topic) ⇒ true, false
Determine if there are any subscribers for a particular event.
181 182 183 |
# File 'lib/mongo/monitoring.rb', line 181 def subscribers?(topic) !subscribers_for(topic).empty? end |
#succeeded(topic, event) ⇒ Object
Publish a succeeded event.
129 130 131 |
# File 'lib/mongo/monitoring.rb', line 129 def succeeded(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.succeeded(event) } end |