Class: Infludp::Client
- Inherits:
-
Object
- Object
- Infludp::Client
- Defined in:
- lib/infludp/client.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #build_metric(name, data) ⇒ Object
-
#initialize(args) ⇒ Client
constructor
A new instance of Client.
- #send(name, data) ⇒ Object
- #socket ⇒ Object
Constructor Details
#initialize(args) ⇒ Client
5 6 7 8 |
# File 'lib/infludp/client.rb', line 5 def initialize(args) @host = args[:host] @port = args[:port] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/infludp/client.rb', line 3 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/infludp/client.rb', line 3 def port @port end |
Instance Method Details
#build_metric(name, data) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/infludp/client.rb', line 23 def build_metric(name, data) [{ name: name, columns: data.keys.map{|key| key.to_s}, points: data.values }].to_json end |
#send(name, data) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/infludp/client.rb', line 14 def send(name, data) socket.send( build_metric(name, data), 0, host, port ) end |
#socket ⇒ Object
10 11 12 |
# File 'lib/infludp/client.rb', line 10 def socket Thread.current[:infludp_socket] ||= UDPSocket.new end |