influxdb 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +53 -29
- data/lib/influxdb/client.rb +5 -1
- data/lib/influxdb/timestamp_conversion.rb +52 -12
- data/lib/influxdb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9d8162fab3d514cea64b236b6646e3f5ac82fbd73b2212d27e62a0941477a2
|
4
|
+
data.tar.gz: 8d2ad9db604f1792f384628c9b29a233abea16c7f21bd6db97bb472ee51e12af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cba9385d8d07bf5299ef050a26df71e2cc70341d02bffe7e6e64d9fe91885cec6d6aba40a154c0a5aa871f653b80f0c40316f9ccf59eb37557ec93b82c6c4581
|
7
|
+
data.tar.gz: 26f8ee0318e7b3be065b768b3b134b8e4dadd741be340a97e0f4381994bc4bcf29f7e49bdce0a76dad20c02ed7b2c25ad759a6dcfca7e10299ba3d976a11b687
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/commits/master).
|
4
4
|
|
5
|
+
## v0.6.3, released 2018-11-30
|
6
|
+
|
7
|
+
- Added `InfluxDB.now(precision)` and `InfluxDB::Client#now` as companions
|
8
|
+
to `InfluxDB.convert_timestamp`.
|
9
|
+
|
5
10
|
## v0.6.2, released 2018-11-30
|
6
11
|
|
7
12
|
- Added `InfluxDB.convert_timestamp` utility to convert a `Time` to a
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://githu
|
|
14
14
|
- [Usage](#usage)
|
15
15
|
- [Creating a client](#creating-a-client)
|
16
16
|
- [Writing data](#writing-data)
|
17
|
-
|
17
|
+
- [A Note About Time Precision](#a-note-about-time-precision)
|
18
18
|
- [Querying](#querying)
|
19
19
|
- [Advanced Topics](#advanced-topics)
|
20
20
|
- [Administrative tasks](#administrative-tasks)
|
@@ -145,34 +145,8 @@ influxdb.write_point(name, data)
|
|
145
145
|
influxdb.write_point(name, data, time_precision)
|
146
146
|
```
|
147
147
|
|
148
|
-
|
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.
|
176
150
|
|
177
151
|
Allowed values for `time_precision` are:
|
178
152
|
|
@@ -337,6 +311,56 @@ influxdb = InfluxDB::Client.new(
|
|
337
311
|
influxdb.write_point('hitchhiker', { values: { value: 666 } })
|
338
312
|
```
|
339
313
|
|
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
|
340
364
|
|
341
365
|
### Querying
|
342
366
|
|
data/lib/influxdb/client.rb
CHANGED
@@ -48,7 +48,7 @@ module InfluxDB
|
|
48
48
|
# +:verify_ssl+:: verify ssl server certificate?
|
49
49
|
# +:ssl_ca_cert+:: ssl CA certificate, chainfile or CA path.
|
50
50
|
# The system CA path is automatically included
|
51
|
-
# +:retry
|
51
|
+
# +:retry+:: number of times a failed request should be retried. Defaults to infinite.
|
52
52
|
def initialize(database = nil, **opts)
|
53
53
|
opts[:database] = database if database.is_a? String
|
54
54
|
@config = InfluxDB::Config.new(opts)
|
@@ -72,6 +72,10 @@ module InfluxDB
|
|
72
72
|
@stopped
|
73
73
|
end
|
74
74
|
|
75
|
+
def now
|
76
|
+
InfluxDB.now(config.time_precision)
|
77
|
+
end
|
78
|
+
|
75
79
|
private
|
76
80
|
|
77
81
|
def find_writer
|
@@ -1,5 +1,45 @@
|
|
1
1
|
module InfluxDB #:nodoc:
|
2
|
-
|
2
|
+
# Converts a Time to a timestamp with the given precision.
|
3
|
+
#
|
4
|
+
# === Example
|
5
|
+
#
|
6
|
+
# InfluxDB.convert_timestamp(Time.now, "ms")
|
7
|
+
# #=> 1543533308243
|
8
|
+
def self.convert_timestamp(time, precision = "s")
|
9
|
+
factor = TIME_PRECISION_FACTORS.fetch(precision) do
|
10
|
+
raise ArgumentError, "invalid time precision: #{precision}"
|
11
|
+
end
|
12
|
+
|
13
|
+
(time.to_r * factor).to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the current timestamp with the given precision.
|
17
|
+
#
|
18
|
+
# Implementation detail: This does not create an intermediate Time
|
19
|
+
# object with `Time.now`, but directly requests the CLOCK_REALTIME,
|
20
|
+
# which in general is a bit faster.
|
21
|
+
#
|
22
|
+
# This is useful, if you want or need to shave off a few microseconds
|
23
|
+
# from your measurement.
|
24
|
+
#
|
25
|
+
# === Examples
|
26
|
+
#
|
27
|
+
# InfluxDB.now("ns") #=> 1543612126401392625
|
28
|
+
# InfluxDB.now("u") #=> 1543612126401392
|
29
|
+
# InfluxDB.now("ms") #=> 1543612126401
|
30
|
+
# InfluxDB.now("s") #=> 1543612126
|
31
|
+
# InfluxDB.now("m") #=> 25726868
|
32
|
+
# InfluxDB.now("h") #=> 428781
|
33
|
+
def self.now(precision = "s")
|
34
|
+
name, divisor = TIME_PRECISION_FACTORS.fetch(precision) do
|
35
|
+
raise ArgumentError, "invalid time precision: #{precision}"
|
36
|
+
end
|
37
|
+
|
38
|
+
time = Process.clock_gettime Process::CLOCK_REALTIME, name
|
39
|
+
(time / divisor).to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
TIME_PRECISION_FACTORS = {
|
3
43
|
"ns" => 1e9.to_r,
|
4
44
|
nil => 1e9.to_r,
|
5
45
|
"u" => 1e6.to_r,
|
@@ -8,16 +48,16 @@ module InfluxDB #:nodoc:
|
|
8
48
|
"m" => 1.to_r / 60,
|
9
49
|
"h" => 1.to_r / 60 / 60,
|
10
50
|
}.freeze
|
11
|
-
private_constant :
|
51
|
+
private_constant :TIME_PRECISION_FACTORS
|
12
52
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
53
|
+
CLOCK_NAMES = {
|
54
|
+
"ns" => [:nanosecond, 1],
|
55
|
+
nil => [:nanosecond, 1],
|
56
|
+
"u" => [:microsecond, 1],
|
57
|
+
"ms" => [:millisecond, 1],
|
58
|
+
"s" => [:second, 1],
|
59
|
+
"m" => [:second, 1.to_r / 60],
|
60
|
+
"h" => [:second, 1.to_r / 60 / 60],
|
61
|
+
}.freeze
|
62
|
+
private_constant :CLOCK_NAMES
|
23
63
|
end
|
data/lib/influxdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: influxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|