Class: Goliath::Plugin::Latency

Inherits:
Object
  • Object
show all
Defined in:
lib/goliath/plugins/latency.rb

Overview

Report latency information about the EventMachine reactor to the log file.

Examples:

plugin Goliath::Plugin::Latency

Constant Summary

@@recent_latency =
0

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Goliath::Plugin::Latency) initialize(port, config, status, logger)

Called by the framework to initialize the plugin

Parameters:

  • (Integer) port

    Unused

  • (Hash) config

    The server configuration data

  • (Hash) status

    A status hash

  • (Log4R::Logger) logger

    The logger



16
17
18
19
20
21
22
# File 'lib/goliath/plugins/latency.rb', line 16

def initialize(port, config, status, logger)
  @status = status
  @config = config
  @logger = logger

  @last = Time.now.to_f
end

Class Method Details

+ (Object) recent_latency



25
26
27
# File 'lib/goliath/plugins/latency.rb', line 25

def self.recent_latency
  @@recent_latency
end

Instance Method Details

- (Object) run

Called automatically to start the plugin



30
31
32
33
34
35
36
# File 'lib/goliath/plugins/latency.rb', line 30

def run
  EM.add_periodic_timer(1) do
    @@recent_latency = (Time.now.to_f - @last)
    @logger.info "LATENCY: #{@@recent_latency}"
    @last = Time.now.to_f
  end
end