Class: Mongo::Monitoring
- Inherits:
-
Object
- Object
- Mongo::Monitoring
- Includes:
- Id, Subscribable
- Defined in:
- lib/mongo/monitoring.rb,
lib/mongo/monitoring/publishable.rb,
lib/mongo/monitoring/event/secure.rb,
lib/mongo/monitoring/event/cmap/base.rb,
lib/mongo/monitoring/cmap_log_subscriber.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/cmap/pool_ready.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/cmap/pool_closed.rb,
lib/mongo/monitoring/event/topology_changed.rb,
lib/mongo/monitoring/event/topology_opening.rb,
lib/mongo/monitoring/event/cmap/pool_cleared.rb,
lib/mongo/monitoring/event/cmap/pool_created.rb,
lib/mongo/monitoring/event/command_succeeded.rb,
lib/mongo/monitoring/event/cmap/connection_ready.rb,
lib/mongo/monitoring/unified_sdam_log_subscriber.rb,
lib/mongo/monitoring/event/cmap/connection_closed.rb,
lib/mongo/monitoring/server_closed_log_subscriber.rb,
lib/mongo/monitoring/event/cmap/connection_created.rb,
lib/mongo/monitoring/event/server_heartbeat_failed.rb,
lib/mongo/monitoring/server_opening_log_subscriber.rb,
lib/mongo/monitoring/event/server_heartbeat_started.rb,
lib/mongo/monitoring/topology_closed_log_subscriber.rb,
lib/mongo/monitoring/topology_changed_log_subscriber.rb,
lib/mongo/monitoring/topology_opening_log_subscriber.rb,
lib/mongo/monitoring/event/cmap/connection_checked_in.rb,
lib/mongo/monitoring/event/server_description_changed.rb,
lib/mongo/monitoring/event/server_heartbeat_succeeded.rb,
lib/mongo/monitoring/event/cmap/connection_checked_out.rb,
lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb,
lib/mongo/monitoring/event/cmap/connection_check_out_started.rb,
lib/mongo/monitoring/server_description_changed_log_subscriber.rb
Overview
The class defines behavior for the performance monitoring API.
Defined Under Namespace
Modules: Event, Global, Publishable, Subscribable Classes: CmapLogSubscriber, CommandLogSubscriber, SDAMLogSubscriber, ServerClosedLogSubscriber, ServerDescriptionChangedLogSubscriber, ServerOpeningLogSubscriber, TopologyChangedLogSubscriber, TopologyClosedLogSubscriber, TopologyOpeningLogSubscriber, UnifiedSdamLogSubscriber
Constant Summary collapse
- COMMAND =
The command topic.
'Command'- CONNECTION_POOL =
The connection pool topic.
'ConnectionPool'- SERVER_CLOSED =
Server closed topic.
'ServerClosed'- SERVER_DESCRIPTION_CHANGED =
Server description changed topic.
'ServerDescriptionChanged'- SERVER_OPENING =
Server opening topic.
'ServerOpening'- TOPOLOGY_CHANGED =
Topology changed topic.
'TopologyChanged'- TOPOLOGY_CLOSED =
Topology closed topic.
'TopologyClosed'- TOPOLOGY_OPENING =
Topology opening topic.
'TopologyOpening'- SERVER_HEARTBEAT =
Server heartbeat started topic.
'ServerHeartbeat'
Instance Attribute Summary collapse
- #options ⇒ Object readonly private
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.
- #monitoring? ⇒ Boolean private
- #publish_heartbeat(server, awaited: false) ⇒ Object private
-
#published(topic, event) ⇒ Object
Publish an event.
-
#started(topic, event) ⇒ Object
Publish a started event.
-
#succeeded(topic, event) ⇒ Object
Publish a succeeded event.
Methods included from Subscribable
#subscribe, #subscribers, #subscribers?, #unsubscribe
Methods included from Id
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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/mongo/monitoring.rb', line 218 def initialize( = {}) @options = return unless [:monitoring] != false Global.subscribers.each do |topic, subscribers| subscribers.each do |subscriber| subscribe(topic, subscriber) end end subscribe(COMMAND, CommandLogSubscriber.new()) # CMAP events are not logged by default because this will create # log entries for every operation performed by the driver. # subscribe(CONNECTION_POOL, CmapLogSubscriber.new(options)) 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()) subscribe(TOPOLOGY_CLOSED, TopologyClosedLogSubscriber.new()) end |
Instance Attribute Details
#options ⇒ Object (readonly)
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.
240 241 242 |
# File 'lib/mongo/monitoring.rb', line 240 def @options end |
Class Method Details
.next_operation_id ⇒ Integer
Used for generating unique operation ids to link events together.
77 78 79 |
# File 'lib/mongo/monitoring.rb', line 77 def self.next_operation_id next_id end |
Instance Method Details
#failed(topic, event) ⇒ Object
Publish a failed event.
This method is used for event types which have the started/succeeded/failed events in them, such as command and heartbeat events.
304 305 306 |
# File 'lib/mongo/monitoring.rb', line 304 def failed(topic, event) subscribers_for(topic).each { |subscriber| subscriber.failed(event) } end |
#monitoring? ⇒ Boolean
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.
243 244 245 |
# File 'lib/mongo/monitoring.rb', line 243 def monitoring? [:monitoring] != false end |
#publish_heartbeat(server, awaited: false) ⇒ Object
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.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/mongo/monitoring.rb', line 309 def publish_heartbeat(server, awaited: false) if monitoring? started_event = Event::ServerHeartbeatStarted.new( server.address, awaited: awaited ) started(SERVER_HEARTBEAT, started_event) end # The duration we publish in heartbeat succeeded/failed events is # the time spent on the entire heartbeat. This could include time # to connect the socket (including TLS handshake), not just time # spent on hello call itself. # The spec at https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.md # requires that the duration exposed here start from "sending the # message" (hello). This requirement does not make sense if, # for example, we were never able to connect to the server at all # and thus hello was never sent. start_time = Utils.monotonic_time begin result = yield rescue StandardError => e if monitoring? event = Event::ServerHeartbeatFailed.new( server.address, Utils.monotonic_time - start_time, e, awaited: awaited, started_event: started_event ) failed(SERVER_HEARTBEAT, event) end raise else if monitoring? event = Event::ServerHeartbeatSucceeded.new( server.address, Utils.monotonic_time - start_time, awaited: awaited, started_event: started_event ) succeeded(SERVER_HEARTBEAT, event) end result end end |
#published(topic, event) ⇒ Object
Publish an event.
This method is used for event types which only have a single event in them.
256 257 258 |
# File 'lib/mongo/monitoring.rb', line 256 def published(topic, event) subscribers_for(topic).each { |subscriber| subscriber.published(event) } end |
#started(topic, event) ⇒ Object
Publish a started event.
This method is used for event types which have the started/succeeded/failed events in them, such as command and heartbeat events.
272 273 274 |
# File 'lib/mongo/monitoring.rb', line 272 def started(topic, event) subscribers_for(topic).each { |subscriber| subscriber.started(event) } end |
#succeeded(topic, event) ⇒ Object
Publish a succeeded event.
This method is used for event types which have the started/succeeded/failed events in them, such as command and heartbeat events.
288 289 290 |
# File 'lib/mongo/monitoring.rb', line 288 def succeeded(topic, event) subscribers_for(topic).each { |subscriber| subscriber.succeeded(event) } end |