Class: OpenTSDB::Client

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/opentsdb/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
# File 'lib/opentsdb/client.rb', line 10

def initialize(options = {})
  begin
    hostname = options[:hostname] || 'localhost'
    port = options[:port] || 4242
    @connection = TCPSocket.new(hostname, port)
  rescue
    raise "Unable to connect or invalid connection data"
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/opentsdb/client.rb', line 8

def connection
  @connection
end

Instance Method Details

#put(options = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/opentsdb/client.rb', line 20

def put(options = {})
  timestamp = options[:timestamp].to_i
  metric_name = options[:metric]
  value = options[:value].to_f
  tags = options[:tags].map{|k,v| "#{k}=#{v}"}.join(" ")
  @connection.puts("put #{metric_name} #{timestamp} #{value} #{tags}")
end