Class: Collectd::Server

Inherits:
Values
  • Object
show all
Defined in:
lib/collectd/server.rb

Instance Attribute Summary

Attributes inherited from Values

#interval

Instance Method Summary collapse

Methods inherited from Values

#inc_counter, #make_pkt, #set_counter, #set_gauge

Constructor Details

#initialize(interval, host, port) ⇒ Server

Returns a new instance of Server.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/collectd/server.rb', line 7

def initialize(interval, host, port)
  super(interval)
  @sock = UDPSocket.new(host.index(':') ? Socket::AF_INET6 : Socket::AF_INET)
  @sock.connect(host, port)

  Thread.new do
    loop do
      sleep interval

      Collectd.run_pollables_for self
      Thread.critical = true
      pkt = make_pkt
      Thread.critical = false
      begin
        @sock.send(pkt, 0)
      rescue SystemCallError
      end
    end
  end.abort_on_exception = true
end