Class: Mongo::Monitoring

Inherits:
Object
  • Object
show all
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/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/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.

Since:

  • 2.1.0

Defined Under Namespace

Modules: Event, Global, Publishable, Subscribable Classes: CmapLogSubscriber, CommandLogSubscriber, SDAMLogSubscriber, ServerClosedLogSubscriber, ServerDescriptionChangedLogSubscriber, ServerOpeningLogSubscriber, TopologyChangedLogSubscriber, TopologyClosedLogSubscriber, TopologyOpeningLogSubscriber

Constant Summary collapse

COMMAND =

The command topic.

Since:

  • 2.1.0

'Command'.freeze
CONNECTION_POOL =

The connection pool topic.

Since:

  • 2.9.0

'ConnectionPool'.freeze
SERVER_CLOSED =

Server closed topic.

Since:

  • 2.4.0

'ServerClosed'.freeze
SERVER_DESCRIPTION_CHANGED =

Server description changed topic.

Since:

  • 2.4.0

'ServerDescriptionChanged'.freeze
SERVER_OPENING =

Server opening topic.

Since:

  • 2.4.0

'ServerOpening'.freeze
TOPOLOGY_CHANGED =

Topology changed topic.

Since:

  • 2.4.0

'TopologyChanged'.freeze
TOPOLOGY_CLOSED =

Topology closed topic.

Since:

  • 2.4.0

'TopologyClosed'.freeze
TOPOLOGY_OPENING =

Topology opening topic.

Since:

  • 2.4.0

'TopologyOpening'.freeze
SERVER_HEARTBEAT =

Server heartbeat started topic.

Since:

  • 2.7.0

'ServerHeartbeat'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Subscribable

#subscribe, #subscribers, #subscribers?, #unsubscribe

Methods included from Id

included

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.

Examples:

Create the new monitoring.

Monitoring.new(:monitoring => true)

Parameters:

  • options (Hash) (defaults to: {})

    Options. Client constructor forwards its options to Monitoring constructor, although Monitoring recognizes only a subset of the options recognized by Client.

Options Hash (options):

  • :monitoring (true, false)

    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



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/mongo/monitoring.rb', line 217

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))
    # 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(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

Instance Attribute Details

#optionsObject (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.

Since:

  • 2.1.0



239
240
241
# File 'lib/mongo/monitoring.rb', line 239

def options
  @options
end

Class Method Details

.next_operation_idInteger

Used for generating unique operation ids to link events together.

Examples:

Get the next operation id.

Monitoring.next_operation_id

Returns:

  • (Integer)

    The next operation id.

Since:

  • 2.1.0



76
77
78
# File 'lib/mongo/monitoring.rb', line 76

def self.next_operation_id
  self.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.

Examples:

Publish a failed event.

monitoring.failed(COMMAND, event)

Parameters:

  • topic (String)

    The event topic.

  • event (Event)

    The event to publish.

Since:

  • 2.1.0



303
304
305
# File 'lib/mongo/monitoring.rb', line 303

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.

Returns:

  • (Boolean)

Since:

  • 2.1.0



242
243
244
# File 'lib/mongo/monitoring.rb', line 242

def monitoring?
  options[:monitoring] != false
end

#published(topic, event) ⇒ Object

Publish an event.

This method is used for event types which only have a single event in them.

Parameters:

  • topic (String)

    The event topic.

  • event (Event)

    The event to publish.

Since:

  • 2.9.0



255
256
257
# File 'lib/mongo/monitoring.rb', line 255

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.

Examples:

Publish a started event.

monitoring.started(COMMAND, event)

Parameters:

  • topic (String)

    The event topic.

  • event (Event)

    The event to publish.

Since:

  • 2.1.0



271
272
273
# File 'lib/mongo/monitoring.rb', line 271

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.

Examples:

Publish a succeeded event.

monitoring.succeeded(COMMAND, event)

Parameters:

  • topic (String)

    The event topic.

  • event (Event)

    The event to publish.

Since:

  • 2.1.0



287
288
289
# File 'lib/mongo/monitoring.rb', line 287

def succeeded(topic, event)
  subscribers_for(topic).each{ |subscriber| subscriber.succeeded(event) }
end