class Mongo::Monitoring

The class defines behaviour 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_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

Public Class Methods

new(options = {}) click to toggle source

Initialize the monitoring.

@api private

@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.

@since 2.1.0

# File lib/mongo/monitoring.rb, line 202
def initialize(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))
  end
end
next_operation_id() click to toggle source

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 68
def self.next_operation_id
  @@operation_id_lock.synchronize do
    @@operation_id += 1
  end
end

Public Instance Methods

failed(topic, event) click to toggle source

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 253
def failed(topic, event)
  subscribers_for(topic).each{ |subscriber| subscriber.failed(event) }
end
started(topic, event) click to toggle source

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 227
def started(topic, event)
  subscribers_for(topic).each{ |subscriber| subscriber.started(event) }
end
succeeded(topic, event) click to toggle source

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 240
def succeeded(topic, event)
  subscribers_for(topic).each{ |subscriber| subscriber.succeeded(event) }
end

Private Instance Methods

initialize_copy(original) click to toggle source
# File lib/mongo/monitoring.rb, line 259
def initialize_copy(original)
  @subscribers = original.subscribers.dup
end