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/server_closed.rb,
lib/mongo/monitoring/sdam_log_subscriber.rb,
lib/mongo/monitoring/event/command_failed.rb,
lib/mongo/monitoring/event/server_opening.rb,
lib/mongo/monitoring/event/command_started.rb,
lib/mongo/monitoring/event/topology_closed.rb,
lib/mongo/monitoring/command_log_subscriber.rb,
lib/mongo/monitoring/event/topology_changed.rb,
lib/mongo/monitoring/event/topology_opening.rb,
lib/mongo/monitoring/event/command_succeeded.rb,
lib/mongo/monitoring/server_closed_log_subscriber.rb,
lib/mongo/monitoring/server_opening_log_subscriber.rb,
lib/mongo/monitoring/topology_changed_log_subscriber.rb,
lib/mongo/monitoring/topology_opening_log_subscriber.rb,
lib/mongo/monitoring/event/server_description_changed.rb,
lib/mongo/monitoring/server_description_changed_log_subscriber.rb
Overview
The class defines behaviour for the performance monitoring API.
Defined Under Namespace
Modules: Event, Global, Publishable Classes: CommandLogSubscriber, SDAMLogSubscriber, ServerClosedLogSubscriber, ServerDescriptionChangedLogSubscriber, ServerOpeningLogSubscriber, TopologyChangedLogSubscriber, TopologyOpeningLogSubscriber
Constant Summary collapse
- COMMAND =
The command topic.
'Command'.freeze
- SERVER_CLOSED =
Server closed topic.
'ServerClosed'.freeze
- SERVER_DESCRIPTION_CHANGED =
Server description changed topic.
'ServerDescriptionChanged'.freeze
- SERVER_OPENING =
Server opening topic.
'ServerOpening'.freeze
- TOPOLOGY_CHANGED =
Topology changed topic.
'TopologyChanged'.freeze
- TOPOLOGY_CLOSED =
Topology closed topic.
'TopologyClosed'.freeze
- TOPOLOGY_OPENING =
Topology opening topic.
'TopologyOpening'.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.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mongo/monitoring.rb', line 132 def initialize( = {}) if [:monitoring] != false Global.subscribers.each do |topic, subscribers| subscribers.each do |subscriber| subscribe(topic, subscriber) end end subscribe(COMMAND, CommandLogSubscriber.new()) subscribe(SERVER_OPENING, ServerOpeningLogSubscriber.new()) subscribe(SERVER_CLOSED, ServerClosedLogSubscriber.new()) subscribe(SERVER_DESCRIPTION_CHANGED, ServerDescriptionChangedLogSubscriber.new()) subscribe(TOPOLOGY_OPENING, TopologyOpeningLogSubscriber.new()) subscribe(TOPOLOGY_CHANGED, TopologyChangedLogSubscriber.new()) end end |
Class Method Details
.next_operation_id ⇒ Integer
Used for generating unique operation ids to link events together.
78 79 80 81 82 |
# File 'lib/mongo/monitoring.rb', line 78 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.
183 184 185 |
# File 'lib/mongo/monitoring.rb', line 183 def failed(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.failed(event) } end |
#started(topic, event) ⇒ Object
Publish a started event.
157 158 159 |
# File 'lib/mongo/monitoring.rb', line 157 def started(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.started(event) } end |
#subscribe(topic, subscriber) ⇒ Object
Subscribe a listener to an event topic.
196 197 198 |
# File 'lib/mongo/monitoring.rb', line 196 def subscribe(topic, subscriber) subscribers_for(topic).push(subscriber) end |
#subscribers ⇒ Hash<String, Object>
Get all the subscribers.
208 209 210 |
# File 'lib/mongo/monitoring.rb', line 208 def subscribers @subscribers ||= {} end |
#subscribers?(topic) ⇒ true, false
Determine if there are any subscribers for a particular event.
222 223 224 |
# File 'lib/mongo/monitoring.rb', line 222 def subscribers?(topic) !subscribers_for(topic).empty? end |
#succeeded(topic, event) ⇒ Object
Publish a succeeded event.
170 171 172 |
# File 'lib/mongo/monitoring.rb', line 170 def succeeded(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.succeeded(event) } end |