Class: OpenTSDB::Client
- Inherits:
-
Object
- Object
- OpenTSDB::Client
- Includes:
- Logging
- Defined in:
- lib/opentsdb/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #build_command(input) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #put(options = {}) ⇒ Object
- #to_command(options) ⇒ Object
Methods included from Logging
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( = {}) begin hostname = [:hostname] || 'localhost' port = [:port] || 4242 @connection = TCPSocket.new(hostname, port) rescue raise "Unable to connect or invalid connection data" end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/opentsdb/client.rb', line 8 def connection @connection end |
Instance Method Details
#build_command(input) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/opentsdb/client.rb', line 28 def build_command(input) if input.kind_of?(Array) input.collect { |unit| to_command(unit) }.join("\n") else to_command(input) end.chomp end |
#put(options = {}) ⇒ Object
36 37 38 |
# File 'lib/opentsdb/client.rb', line 36 def put( = {}) @connection.puts(build_command()) end |
#to_command(options) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/opentsdb/client.rb', line 20 def to_command( ) = [:timestamp].to_i metric_name = [:metric] value = [:value].to_f = [:tags].map{|k,v| "#{k}=#{v}"}.join(" ") "put #{metric_name} #{timestamp} #{value} #{tags}" end |