Closed navaneeth closed 7 years ago
Yeah, this is a common pitfall when using the Ruby gem:
presicsion
parameterTime
operations are based onSo if you don't specify a precision, we'll fall back to second-precision. When you write five points with the same tags (within the same second), the first four points are overwritten by the last point (i.e. each subsequent point overwrites the last one).
You can find the corresponding note in the README in the Writing data section (scroll to the "Note:" under the second code sample):
The easiest soultion is to explicitly define a time_precision
(on the InfluxDB::Client
) and the timestamp
option (when writing points):
influxdb = InfluxDB::Client.new "tt", time_precision: "ns"
tags = { type: 'Draft', subtype: 'dummy', state: 'Live' }
def now_in_nanoseconds
(Time.now.to_r * 10**9).to_i
end
5.times do
item = {
values: { count: rand(10...42).to_f },
tags: tags,
timestamp: now_in_nanoseconds,
}
influxdb.write_point(name, item)
end
I've added a link to the readme: https://github.com/influxdata/influxdb-ruby#a-note-about-time-precision
FYI: If you're feeling adventurous, you could try the timestamps
branch, whilch might be included in the next release:
# Gemfile
gem "influxdb", github: "influxdata/influxdb-ruby", branch: "timestamps"
# your code
influxdb = InfluxDB::Client.new "tt", time_precision: "ns"
# item = { values: {...}, tags: {...} }
influxdb.write_point(name, item, Time.now)
As you can see, you still need to define the time_precision
option on the client and explicitly provide a timestamp
on the data point, but you'll save the second→whatever conversion.
I am using the following code:
Above code inserts 5 values into influx. If I remove the
sleep 1
, then only one point gets inserted into the DB. When I havesleep
in the loop, all 5 values gets inserted.Is this expected?
Influx version:
1.2.4
Influx ruby:0.3.14