Class: Infludp::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/infludp/client.rb', line 3

def host
  @host
end

#portObject

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

#socketObject



10
11
12
# File 'lib/infludp/client.rb', line 10

def socket
  Thread.current[:infludp_socket] ||= UDPSocket.new
end