Class: EventMachine::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/em-monitor.rb

Overview

The monitor object itself deals with maintaining lspace and timers.

Constant Summary collapse

DEFAULT_INTERVAL =

How long (by default) between calls to monitors

60
DEFAULT_BUCKETS =

Which buckets to include in the histogram by default

[0.001, 0.01, 0.1, 1, 10]

Instance Method Summary collapse

Constructor Details

#initialize(&block) {|self| ... } ⇒ Monitor

Create a new monitor.

The block will be called in the monitor’s LSpace, all further EM work should happen within the block to ensure that we measure everything.

Parameters:

  • block (Proc)

    The block during which to monitor events

Yield Parameters:



145
146
147
148
149
# File 'lib/em-monitor.rb', line 145

def initialize(&block)
  create_lspace.enter do
    block.call self
  end
end

Instance Method Details

#monitor_spans(interval, &block) {|spans, from, to| ... } ⇒ Object

Attach a listener to this monitor.

Only one listener can be active at a time, and the interval set here will take affect after the next tick of the previous interval.

Parameters:

  • interval (Number)

    The (lower bound of) time in seconds between calls to block

  • block (Proc)

    The block to call

Yield Parameters:

  • spans (Array<Float>)

    Each number of seconds the event loop spent processing.

  • from (Time)

    The time at which the block was previously called

  • to (Time)

    The current time

See Also:

  • EM.monitor_spans


162
163
164
165
166
# File 'lib/em-monitor.rb', line 162

def monitor_spans(interval, &block)
  @periodic_timer ||= create_timer(interval)
  @periodic_timer.interval = interval
  @monitor = block
end