Class: InfluxDB::Writer::UDP

Inherits:
Object
  • Object
show all
Defined in:
lib/influxdb/writer/udp.rb

Overview

Writes data to InfluxDB through UDP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, config) ⇒ UDP

Returns a new instance of UDP.



7
8
9
10
11
12
13
14
# File 'lib/influxdb/writer/udp.rb', line 7

def initialize(client, config)
  @client = client
  config = config.is_a?(Hash) ? config : {}
  @host = config.fetch(:host, "localhost".freeze)
  @port = config.fetch(:port, 4444)
  self.socket = UDPSocket.new
  socket.connect(host, port)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/influxdb/writer/udp.rb', line 6

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/influxdb/writer/udp.rb', line 6

def port
  @port
end

#socketObject

Returns the value of attribute socket.



5
6
7
# File 'lib/influxdb/writer/udp.rb', line 5

def socket
  @socket
end

Instance Method Details

#write(payload, _precision = nil, _retention_policy = nil) ⇒ Object



16
17
18
# File 'lib/influxdb/writer/udp.rb', line 16

def write(payload, _precision = nil, _retention_policy = nil)
  socket.send(payload, 0)
end