Skip to content

Instantly share code, notes, and snippets.

@dmke
Created April 28, 2016 19:42
Show Gist options
  • Save dmke/6695e227b2b7e6fb55b2ff6091c9354e to your computer and use it in GitHub Desktop.
Save dmke/6695e227b2b7e6fb55b2ff6091c9354e to your computer and use it in GitHub Desktop.
influxdb-ruby GH-141
influxdb-ruby: 0.3.0
influx server: 0.10.2
purging existing data...
generating data:
UNIT_000 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_001 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_002 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_003 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_004 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
writing data...
reading data:
UNIT_000 : {"time"=>1461794400, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_001 : {"time"=>1461798000, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_002 : {"time"=>1461801600, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_003 : {"time"=>1461805200, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_004 : {"time"=>1461808800, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
influxdb-ruby: 0.3.0
influx server: 0.11.1
purging existing data...
generating data:
UNIT_000 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_001 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_002 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_003 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_004 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
writing data...
reading data:
UNIT_000 : {"time"=>1461794400, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_001 : {"time"=>1461798000, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_002 : {"time"=>1461801600, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_003 : {"time"=>1461805200, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_004 : {"time"=>1461808800, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
influxdb-ruby: 0.3.0
influx server: 0.12.2
purging existing data...
generating data:
UNIT_000 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_001 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_002 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_003 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
UNIT_004 : {:consumed_energy=>5.0, :frequency=>5.0, :power_factor=>5.0, :reactive_watts=>5.0, :rms_voltage=>5.0, :temperature=>5.0}
writing data...
reading data:
UNIT_000 : {"time"=>1461794400, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_001 : {"time"=>1461798000, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_002 : {"time"=>1461801600, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_003 : {"time"=>1461805200, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
UNIT_004 : {"time"=>1461808800, "consumed_energy"=>5, "frequency"=>5, "power_factor"=>5, "reactive_watts"=>5, "rms_voltage"=>5, "temperature"=>5}
#!/usr/bin/env ruby
require "influxdb"
@dbname = "connector_test"
@series = "units_all"
def gen_data_point(i)
{
series: @series,
tags: {
device_unit_id: ("UNIT_%03d" % i)
},
values: {
consumed_energy: 5.0,
frequency: 5.0,
power_factor: 5.0,
reactive_watts: 5.0,
rms_voltage: 5.0,
temperature: 5.0,
},
timestamp: Time.new(2016, 4, 28, i%24, i/24).to_i
}
end
cli = InfluxDB::Client.new \
database: @dbname,
username: "root",
password: "root",
time_precision: "s",
epoch: "s"
puts "influxdb-ruby: #{InfluxDB::VERSION}"
puts "influx server: #{cli.version}", ""
puts "purging existing data..."
cli.delete_database(@dbname) if cli.list_databases.flat_map(&:values).include?(@dbname)
cli.create_database(@dbname)
puts "generating data:"
data = (0..4).map{|i| gen_data_point(i) }.each do |point|
tags, values = point[:tags], point[:values]
puts " #{tags[:device_unit_id]} : #{values.inspect}"
end
puts "writing data... "
cli.write_points data
puts "reading data:"
cli.query("select * from #{@series} group by device_unit_id") do |name, tags, values|
values.each do |val|
puts " #{tags['device_unit_id']} : #{val.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment