class Mongo::Monitoring
The class defines behavior for the performance monitoring API.
@since 2.1.0
Constants
- COMMAND
The command topic.
@since 2.1.0
- SERVER_CLOSED
Server
closed topic.@since 2.4.0
- SERVER_DESCRIPTION_CHANGED
Server
description changed topic.@since 2.4.0
- SERVER_HEARTBEAT
Server
heartbeat started topic.@since 2.7.0
- SERVER_OPENING
Server
opening topic.@since 2.4.0
- TOPOLOGY_CHANGED
Topology changed topic.
@since 2.4.0
- TOPOLOGY_CLOSED
Topology closed topic.
@since 2.4.0
- TOPOLOGY_OPENING
Topology opening topic.
@since 2.4.0
Attributes
@api private
Public Class Methods
Initialize the monitoring.
@example Create the new monitoring.
Monitoring.new(:monitoring => true)
@param [ Hash ] options Options
. Client
constructor forwards its
options to Monitoring constructor, although Monitoring recognizes only a subset of the options recognized by Client.
@option options [ true, false ] :monitoring If false is given, the
Monitoring instance is initialized without global monitoring event subscribers and will not publish SDAM events. Command monitoring events will still be published, and the driver will still perform SDAM and monitor its cluster in order to perform server selection. Built-in driver logging of SDAM events will be disabled because it is implemented through SDAM event subscription. Client#subscribe will succeed for all event types, but subscribers to SDAM events will not be invoked. Values other than false result in default behavior which is to perform normal SDAM event publication.
@since 2.1.0 @api private
# File lib/mongo/monitoring.rb, line 212 def initialize(options = {}) @options = options if options[:monitoring] != false Global.subscribers.each do |topic, subscribers| subscribers.each do |subscriber| subscribe(topic, subscriber) end end subscribe(COMMAND, CommandLogSubscriber.new(options)) subscribe(SERVER_OPENING, ServerOpeningLogSubscriber.new(options)) subscribe(SERVER_CLOSED, ServerClosedLogSubscriber.new(options)) subscribe(SERVER_DESCRIPTION_CHANGED, ServerDescriptionChangedLogSubscriber.new(options)) subscribe(TOPOLOGY_OPENING, TopologyOpeningLogSubscriber.new(options)) subscribe(TOPOLOGY_CHANGED, TopologyChangedLogSubscriber.new(options)) subscribe(TOPOLOGY_CLOSED, TopologyClosedLogSubscriber.new(options)) end end
Used for generating unique operation ids to link events together.
@example Get the next operation id.
Monitoring.next_operation_id
@return [ Integer ] The next operation id.
@since 2.1.0
# File lib/mongo/monitoring.rb, line 71 def self.next_operation_id self.next_id end
Public Instance Methods
Publish a failed event.
@example Publish a failed event.
monitoring.failed(COMMAND, event)
@param [ String ] topic The event topic. @param [ Event
] event The event to publish.
@since 2.1.0
# File lib/mongo/monitoring.rb, line 273 def failed(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.failed(event) } end
@api private
# File lib/mongo/monitoring.rb, line 234 def monitoring? options[:monitoring] != false end
Publish a started event.
@example Publish a started event.
monitoring.started(COMMAND, event)
@param [ String ] topic The event topic. @param [ Event
] event The event to publish.
@since 2.1.0
# File lib/mongo/monitoring.rb, line 247 def started(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.started(event) } end
Publish a succeeded event.
@example Publish a succeeded event.
monitoring.succeeded(COMMAND, event)
@param [ String ] topic The event topic. @param [ Event
] event The event to publish.
@since 2.1.0
# File lib/mongo/monitoring.rb, line 260 def succeeded(topic, event) subscribers_for(topic).each{ |subscriber| subscriber.succeeded(event) } end
Private Instance Methods
# File lib/mongo/monitoring.rb, line 279 def initialize_copy(original) @subscribers = {} original.subscribers.each do |k, v| @subscribers[k] = v.dup end end