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
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #put(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
#put(options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/opentsdb/client.rb', line 20 def put( = {}) = [:timestamp].to_i metric_name = [:metric] value = [:value].to_f = [:tags].map{|k,v| "#{k}=#{v}"}.join(" ") @connection.puts("put #{metric_name} #{} #{value} #{}") end |