Class: Influx
- Inherits:
-
Object
- Object
- Influx
- Defined in:
- lib/influx.rb
Instance Method Summary collapse
-
#clean(measurement) ⇒ Object
Clean measurement.
-
#initialize(host, dbname, port = 8086, user = nil, pass = nil) ⇒ Influx
constructor
Initialize InfluxDB connection class and create the database if not exists.
-
#write(dataname, data) ⇒ Object
Write single datapoint to InfluxDB.
Constructor Details
#initialize(host, dbname, port = 8086, user = nil, pass = nil) ⇒ Influx
Initialize InfluxDB connection class and create the database if not exists
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#clean(measurement) ⇒ Object
Clean measurement
26 27 28 29 |
# File 'lib/influx.rb', line 26 def clean(measurement) query = 'DELETE FROM ' + measurement @connection.query query end |
#write(dataname, data) ⇒ Object
Write single datapoint to InfluxDB
21 22 23 |
# File 'lib/influx.rb', line 21 def write(dataname, data) @connection.write_point(dataname, data) end |