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