@@ -14,7 +14,7 @@ Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://githu
1414- [ Usage] ( #usage )
1515 - [ Creating a client] ( #creating-a-client )
1616 - [ Writing data] ( #writing-data )
17- - [ A Note About Time Precision] ( #a-note-about-time-precision )
17+ - [ A Note About Time Precision] ( #a-note-about-time-precision )
1818 - [ Querying] ( #querying )
1919- [ Advanced Topics] ( #advanced-topics )
2020 - [ Administrative tasks] ( #administrative-tasks )
@@ -145,34 +145,8 @@ influxdb.write_point(name, data)
145145influxdb.write_point(name, data, time_precision)
146146```
147147
148- ### A Note About Time Precision
149-
150- The default precision in this gem is ` "s" ` (second), as Ruby's ` Time#to_i `
151- operates on this resolution.
152-
153- If you write data points with sub-second resolution, you _ have_ to configure
154- your client instance with a more granular ` time_precision ` option ** and** you
155- need to provide timestamp values which reflect this precision. ** If you don't do
156- this, your points will be squashed!**
157-
158- > A point is uniquely identified by the measurement name, tag set, and
159- > timestamp. If you submit a new point with the same measurement, tag set, and
160- > timestamp as an existing point, the field set becomes the union of the old
161- > field set and the new field set, where any ties go to the new field set. This
162- > is the intended behavior.
163-
164- See [ How does InfluxDB handle duplicate points?] [ docs-faq ] for details.
165-
166- For example, this is how to specify millisecond precision (which moves the
167- pitfall from the second- to the millisecond barrier):
168-
169- ``` ruby
170- influxdb = InfluxDB ::Client .new (time_precision: " ms" )
171- time = (Time .now.to_r * 1000 ).to_i
172- # A faster, albeit less readable alternative:
173- # time = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
174- influxdb.write_point(" foobar" , { values: { n: 42 }, timestamp: time })
175- ```
148+ > ** Attention:** Please also read the
149+ > [ note about time precision] ( #a-note-about-time-precision ) below.
176150
177151Allowed values for ` time_precision ` are:
178152
@@ -337,6 +311,56 @@ influxdb = InfluxDB::Client.new(
337311influxdb.write_point(' hitchhiker' , { values: { value: 666 } })
338312```
339313
314+ ### A Note About Time Precision
315+
316+ The default precision in this gem is ` "s" ` (second), as Ruby's ` Time#to_i `
317+ operates on this resolution.
318+
319+ If you write data points with sub-second resolution, you _ have_ to configure
320+ your client instance with a more granular ` time_precision ` option ** and** you
321+ need to provide timestamp values which reflect this precision. ** If you don't do
322+ this, your points will be squashed!**
323+
324+ > A point is uniquely identified by the measurement name, tag set, and
325+ > timestamp. If you submit a new point with the same measurement, tag set, and
326+ > timestamp as an existing point, the field set becomes the union of the old
327+ > field set and the new field set, where any ties go to the new field set. This
328+ > is the intended behavior.
329+
330+ See [ How does InfluxDB handle duplicate points?] [ docs-faq ] for details.
331+
332+ For example, this is how to specify millisecond precision (which moves the
333+ pitfall from the second- to the millisecond barrier):
334+
335+ ``` ruby
336+ client = InfluxDB ::Client .new (time_precision: " ms" )
337+ time = (Time .now.to_r * 1000 ).to_i
338+ client.write_point(" foobar" , { values: { n: 42 }, timestamp: time })
339+ ```
340+
341+ For convenience, InfluxDB provides a few helper methods:
342+
343+ ``` ruby
344+ # to get a timestamp with the precision configured in the client:
345+ client.now
346+
347+ # to get a timestamp with the given precision:
348+ InfluxDB .now(time_precision)
349+
350+ # to convert a Time into a timestamp with the given precision:
351+ InfluxDB .convert_timestamp(Time .now, time_precision)
352+ ```
353+
354+ As with ` client.write_point ` , allowed values for ` time_precision ` are:
355+
356+ - ` "ns" ` or ` nil ` for nanosecond
357+ - ` "u" ` for microsecond
358+ - ` "ms" ` for millisecond
359+ - ` "s" ` for second
360+ - ` "m" ` for minute
361+ - ` "h" ` for hour
362+
363+ [ docs-faq ] : http://docs.influxdata.com/influxdb/v1.7/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
340364
341365### Querying
342366
0 commit comments