Class: Ganymed::Client::Sampler

Inherits:
UDPSocket
  • Object
show all
Defined in:
lib/ganymed/client/sampler.rb

Overview

An EventMachine Protocol that can send samples to a Ganymed sampler.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#originObject

Returns the value of attribute origin.



10
11
12
# File 'lib/ganymed/client/sampler.rb', line 10

def origin
  @origin
end

Class Method Details

.connect(host, port, origin = nil) ⇒ Object

Connect to a Ganymed sampler.

Parameters:

  • host (String)

    Host to connect to.

  • port (Fixnum)

    Port to connect to.

  • origin (String) (defaults to: nil)

    Origin of events. Defaults to the fully-qualified hostname.



28
29
30
31
32
33
# File 'lib/ganymed/client/sampler.rb', line 28

def self.connect(host, port, origin=nil)
  new.tap do |socket|
    socket.connect(host, port)
    socket.origin = origin || ::Socket.gethostbyname(::Socket.gethostname).first
  end
end

Instance Method Details

#emit(ds, ns, value) ⇒ Object

Emit a new sample.

Parameters:

  • ds (String, Symbol)

    Sample data source.

  • ns (String)

    Event namespace.

  • value (Fixnum, Float)

    Sample value.



17
18
19
20
# File 'lib/ganymed/client/sampler.rb', line 17

def emit(ds, ns, value)
  data = [ds.to_s, ns, origin, value.to_f]
  send(data.pack("Z*Z*Z*G"), 0)
end