Module: Legion::Extensions::Influxdb::Runners::Writer

Includes:
Helpers::Lex
Defined in:
lib/legion/extensions/influxdb/runners/writer.rb

Class Method Summary collapse

Class Method Details

.write(series:, tags:, values:, host: 'localhost', port: 8086, database:, **_opts) ⇒ Object



4
5
6
7
# File 'lib/legion/extensions/influxdb/runners/writer.rb', line 4

def self.write(series:, tags:, values:, host: 'localhost', port: 8086, database:, **_opts)
  client = InfluxDB::Client.new(database, host: host, port: port)
  {}
end

.write_points(metrics:, host: 'localhost', port: 8086, database: 'telegraf', time_precision: 'ms', **_opts) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/legion/extensions/influxdb/runners/writer.rb', line 9

def self.write_points(metrics:, host: 'localhost', port: 8086, database: 'telegraf', time_precision: 'ms', **_opts)
  settings[:client] ||= InfluxDB::Client.new(database, host: host, port: port, async: false)
  metrics = Legion::JSON.load(metrics) if metrics.is_a? String
  if metrics[:timestamp].nil?
    metrics[:timestamp] = Time.now.to_i
    time_precision = 's'
  end

  settings[:client].write_point('sensors', metrics, time_precision)
  {}
end