Class Mongo::Server::Monitor
In: lib/mongo/server/monitor.rb
lib/mongo/server/monitor/connection.rb
lib/mongo/server/monitor/app_metadata.rb
Parent: Object

This object is responsible for keeping server status up to date, running in a separate thread as to not disrupt other operations.

@since 2.0.0

Methods

heartbeat_frequency   new   restart!   run!   scan!   stop!  

Included Modules

Loggable Event::Publisher

Classes and Modules

Class Mongo::Server::Monitor::AppMetadata
Class Mongo::Server::Monitor::Connection

Constants

HEARTBEAT_FREQUENCY = 10.freeze   The default time for a server to refresh its status is 10 seconds.

@since 2.0.0

MIN_SCAN_FREQUENCY = 0.5.freeze   The minimum time between forced server scans. Is minHeartbeatFrequencyMS in the SDAM spec.

@since 2.0.0

RTT_WEIGHT_FACTOR = 0.2.freeze   The weighting factor (alpha) for calculating the average moving round trip time.

@since 2.0.0 @deprecated Will be removed in version 3.0.

Attributes

connection  [R]  @return [ Mongo::Server::Monitor::Connection ] connection The connection to use.
description  [R]  @return [ Server::Description ] description The server
  description the monitor refreshes.
last_scan  [R]  @return [ Time ] last_scan The time when the last server scan started.

@since 2.4.0

monitoring  [R]  @return [ Monitoring ] monitoring The monitoring.
options  [R]  @return [ Hash ] options The server options.
round_trip_time_averager  [R]  @api private
scan_semaphore  [R]  @api private

Public Class methods

Create the new server monitor.

@example Create the server monitor.

  Mongo::Server::Monitor.new(address, listeners, monitoring)

@note Monitor must never be directly instantiated outside of a Server.

@param [ Address ] address The address to monitor. @param [ Event::Listeners ] event_listeners The event listeners. @param [ Monitoring ] monitoring The monitoring.. @param [ Hash ] options The options. @option options [ Float ] :heartbeat_frequency The interval, in seconds,

  between server description refreshes via ismaster.

@since 2.0.0 @api private

Public Instance methods

Get the refresh interval for the server. This will be defined via an option or will default to 10.

@example Get the refresh interval.

  server.heartbeat_frequency

@return [ Integer ] The heartbeat frequency, in seconds.

@since 2.0.0

Restarts the server monitor unless the current thread is alive.

@example Restart the monitor.

  monitor.restart!

@return [ Thread ] The thread the monitor runs on.

@since 2.1.0

Runs the server monitor. Refreshing happens on a separate thread per server.

@example Run the monitor.

  monitor.run

@return [ Thread ] The thread the monitor runs on.

@since 2.0.0

Perform a check of the server with throttling, and update the server‘s description and average round trip time.

If the server was checked less than MIN_SCAN_FREQUENCY seconds ago, sleep until MIN_SCAN_FREQUENCY seconds have passed since the last check. Then perform the check which involves running isMaster on the server being monitored and updating the server description as a result.

@note If the system clock is set to a time in the past, this method

  can sleep for a very long time.

@example Run a scan.

  monitor.scan!

@return [ Description ] The updated description.

@since 2.0.0

Stops the server monitor. Kills the thread so it doesn‘t continue taking memory and sending commands to the connection.

@example Stop the monitor.

  monitor.stop!

@param [ Boolean ] wait Whether to wait for background threads to

  finish running.

@return [ Boolean ] Is the thread stopped?

@since 2.0.0

[Validate]