Class: Graphite_sender

Inherits:
Object
  • Object
show all
Defined in:
lib/graphite_sender.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 2003, type = 'tcp') ⇒ Graphite_sender

Returns a new instance of Graphite_sender.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/graphite_sender.rb', line 4

def initialize(host, port = 2003, type = 'tcp')
 
  @type = type

  if @type == 'tcp'
    @socket = TCPSocket.new(host, port)
  else
    @socket = UDPSocket.new
    @socket.connect(host, port)
  end
end

Instance Method Details

#send_measure(stat, value, timestamp = nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/graphite_sender.rb', line 16

def send_measure(stat, value, timestamp = nil)
  if timestamp == nil
    timestamp = Time.now.to_i
  end
  send_to_socket("#{stat} #{value} #{timestamp}")
end