Class: Observium::Agent::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/observium/agent/poller.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, **args) ⇒ Poller

Returns a new instance of Poller.



4
5
6
7
8
# File 'lib/observium/agent/poller.rb', line 4

def initialize(host, **args)
  @host    = host
  @port    = args[:port]    || Observium::Agent.defaults[:port]
  @timeout = args[:timeout] || Observium::Agent.defaults[:timeout]
end

Instance Method Details

#pollObject

Connects to the given host on the agent port to get the agent output. Connection times out after 5 seconds.

Raises a PollingFailed error if no data was output, or the command failed

Returns the raw output returned by the agent as a multiline string



16
17
18
19
20
21
22
23
# File 'lib/observium/agent/poller.rb', line 16

def poll
  @output = %x(nc -w #{@timeout} #{@host} #{@port} 2>&1)
  
  $?.success? or raise Errors::PollingFailed, "Agent check failed: #{error_msg}"
  has_data?   or raise Errors::PollingFailed, "Agent didn't return any data"

  @output
end