class Influx

Public Class Methods

new(host, dbname, port = 8086, user = nil, pass = nil) click to toggle source

Initialize InfluxDB connection class and create the database if not exists

# File lib/influx.rb, line 4
def initialize(host, dbname, port = 8086, user = nil, pass = nil)
  @host = host
  @name = dbname
  @port = port
  @user = user
  @pass = pass
  @time = "s"
  @connection = InfluxDB::Client.new host: @host, port: @port, username: @user, password: @pass, time_precision: @time
  if  @connection.list_databases.map{|r| r['name']}.compact.uniq.include? @name
    @connection = InfluxDB::Client.new database: @name, host: @host, port: @port, username: @user, password: @pass, time_precision: @time
  else
    @connection.create_database(@name)
    @connection = InfluxDB::Client.new database: @name, host: @host, port: @port, username: @user, password: @pass, time_precision: @time
  end
end

Public Instance Methods

clean(measurement) click to toggle source

Clean measurement

# File lib/influx.rb, line 26
def clean(measurement)
  query = 'DELETE FROM ' + measurement
  @connection.query query
end
write(dataname, data) click to toggle source

Write single datapoint to InfluxDB

# File lib/influx.rb, line 21
def write(dataname, data)
  @connection.write_point(dataname, data)
end