influxdb 0.3.14 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -7
- data/.travis.yml +1 -1
- data/CHANGELOG.md +10 -2
- data/README.md +233 -233
- data/influxdb.gemspec +1 -1
- data/lib/influxdb/client.rb +1 -1
- data/lib/influxdb/config.rb +0 -1
- data/lib/influxdb/errors.rb +2 -2
- data/lib/influxdb/point_value.rb +1 -2
- data/lib/influxdb/query/core.rb +9 -8
- data/lib/influxdb/query/database.rb +13 -2
- data/lib/influxdb/query/series.rb +1 -0
- data/lib/influxdb/version.rb +1 -1
- data/spec/influxdb/cases/query_series_spec.rb +17 -0
- data/spec/influxdb/cases/show_field_keys_spec.rb +60 -0
- data/spec/influxdb/point_value_spec.rb +18 -14
- data/spec/spec_helper.rb +1 -0
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60063db18e559aa688b4c54f7b7b4a9b10112249
|
4
|
+
data.tar.gz: e2babb896952b556975099b7fc181401687211c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922a93ef68a4b71a1dc33ad5d2b811af017db80b28899f0ac355bafe9551a3ce69d3ff9e064ff949f7a5fe39442d031ad58404ccddfb877318626d5370d2268f
|
7
|
+
data.tar.gz: add867058a65debfe4a31d0f8f11e2f94c46aa17d16bfa8b20da2d4608ab655ed80712bb1330a2897356d030181a86d7e7eac720d147bc14894182bdaedf39f5
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
AllCops:
|
2
2
|
Include:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
- 'Rakefile'
|
4
|
+
- '*.gemspec'
|
5
|
+
- 'lib/**/*.rb'
|
6
|
+
- 'spec/**/*.rb'
|
7
7
|
Exclude:
|
8
|
-
|
9
|
-
|
8
|
+
- 'bin/**/*'
|
9
|
+
- 'smoke/**/*'
|
10
10
|
DisplayCopNames: true
|
11
11
|
StyleGuideCopsOnly: false
|
12
12
|
TargetRubyVersion: 1.9
|
@@ -29,8 +29,16 @@ Style/RescueModifier:
|
|
29
29
|
Metrics/LineLength:
|
30
30
|
Max: 100
|
31
31
|
Exclude:
|
32
|
-
|
32
|
+
- 'spec/**/*.rb'
|
33
33
|
|
34
34
|
Metrics/ModuleLength:
|
35
35
|
CountComments: false # count full line comments?
|
36
36
|
Max: 120
|
37
|
+
|
38
|
+
Style/TrailingCommaInLiteral:
|
39
|
+
EnforcedStyleForMultiline: comma
|
40
|
+
Exclude:
|
41
|
+
- "spec/**/*.rb"
|
42
|
+
|
43
|
+
Metrics/AbcSize:
|
44
|
+
Max: 20
|
data/.travis.yml
CHANGED
@@ -35,7 +35,7 @@ matrix:
|
|
35
35
|
- rvm: 2.4.0
|
36
36
|
env: TEST_TASK=smoke influx_version=1.1.0 pkghash=682904c350ecfc2a60ec9c6c08453ef2
|
37
37
|
- rvm: 2.4.0
|
38
|
-
env: TEST_TASK=smoke influx_version=1.2.
|
38
|
+
env: TEST_TASK=smoke influx_version=1.2.4 pkghash=0545d67217393282188e5d5cdedfdc85
|
39
39
|
- rvm: 2.4.0
|
40
40
|
env: TEST_TASK=smoke influx_version=nightly channel=nightlies
|
41
41
|
fail_fast: true
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,16 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/
|
|
4
4
|
|
5
5
|
## Unreleased changes
|
6
6
|
|
7
|
-
-
|
7
|
+
- nothing yet
|
8
|
+
|
9
|
+
## v0.3.15, released 2017-07-17
|
10
|
+
|
11
|
+
- Bugfix for `InfluxDB::Client#list_series` when no series available
|
12
|
+
(#195, @skladd).
|
13
|
+
- Clarified/expanded docs (also #190, @paneq).
|
14
|
+
- Added preliminary `show_field_keys` method to `InfluxDB::Client` (note:
|
15
|
+
the API for this is not stable yet).
|
16
|
+
- Degraded dependency on "cause" from runtime to development.
|
8
17
|
|
9
18
|
## v0.3.14, released 2017-02-06
|
10
19
|
|
@@ -19,7 +28,6 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/
|
|
19
28
|
`#write` now accept an additional parameter to override the database on
|
20
29
|
invokation time (#173, #176, @jfragoulis).
|
21
30
|
|
22
|
-
|
23
31
|
## v0.3.12, released 2016-11-15
|
24
32
|
|
25
33
|
- Bugfix for broken Unicode support (regression introduced in #169).
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# influxdb-ruby
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/influxdb)
|
3
4
|
[](https://travis-ci.org/influxdata/influxdb-ruby)
|
4
5
|
|
5
6
|
The official Ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/).
|
@@ -12,17 +13,19 @@ Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://githu
|
|
12
13
|
- [Installation](#installation)
|
13
14
|
- [Usage](#usage)
|
14
15
|
- [Creating a client](#creating-a-client)
|
16
|
+
- [Writing data](#writing-data)
|
17
|
+
- [A Note About Time Precision](#a-note-about-time-precision)
|
18
|
+
- [Querying](#querying)
|
19
|
+
- [Advanced Topics](#advanced-topics)
|
15
20
|
- [Administrative tasks](#administrative-tasks)
|
16
21
|
- [Continuous queries](#continuous-queries)
|
17
22
|
- [Retention policies](#retention-policies)
|
18
|
-
- [Writing data](#writing-data)
|
19
23
|
- [Reading data](#reading-data)
|
20
|
-
- [Querying](#querying)
|
21
24
|
- [De-normalization](#de--normalization)
|
22
25
|
- [Streaming response](#streaming-response)
|
23
26
|
- [Retry](#retry)
|
24
|
-
|
25
|
-
|
27
|
+
- [Testing](#testing)
|
28
|
+
- [Contributing](#contributing)
|
26
29
|
|
27
30
|
## Platform support
|
28
31
|
|
@@ -72,187 +75,6 @@ require 'influxdb'
|
|
72
75
|
influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domain.com"]
|
73
76
|
```
|
74
77
|
|
75
|
-
### Administrative tasks
|
76
|
-
|
77
|
-
Create a database:
|
78
|
-
|
79
|
-
``` ruby
|
80
|
-
database = 'site_development'
|
81
|
-
|
82
|
-
influxdb.create_database(database)
|
83
|
-
```
|
84
|
-
|
85
|
-
Delete a database:
|
86
|
-
|
87
|
-
``` ruby
|
88
|
-
database = 'site_development'
|
89
|
-
|
90
|
-
influxdb.delete_database(database)
|
91
|
-
```
|
92
|
-
|
93
|
-
List databases:
|
94
|
-
|
95
|
-
``` ruby
|
96
|
-
influxdb.list_databases
|
97
|
-
```
|
98
|
-
|
99
|
-
Create a user for a database:
|
100
|
-
|
101
|
-
``` ruby
|
102
|
-
database = 'site_development'
|
103
|
-
new_username = 'foo'
|
104
|
-
new_password = 'bar'
|
105
|
-
permission = :write
|
106
|
-
|
107
|
-
# with all permissions
|
108
|
-
influxdb.create_database_user(database, new_username, new_password)
|
109
|
-
|
110
|
-
# with specified permission - options are: :read, :write, :all
|
111
|
-
influxdb.create_database_user(database, new_username, new_password, permissions: permission)
|
112
|
-
```
|
113
|
-
|
114
|
-
Update a user password:
|
115
|
-
|
116
|
-
``` ruby
|
117
|
-
username = 'foo'
|
118
|
-
new_password = 'bar'
|
119
|
-
|
120
|
-
influxdb.update_user_password(username, new_password)
|
121
|
-
```
|
122
|
-
|
123
|
-
Grant user privileges on database:
|
124
|
-
|
125
|
-
``` ruby
|
126
|
-
username = 'foobar'
|
127
|
-
database = 'foo'
|
128
|
-
permission = :read # options are :read, :write, :all
|
129
|
-
|
130
|
-
influxdb.grant_user_privileges(username, database, permission)
|
131
|
-
```
|
132
|
-
|
133
|
-
Revoke user privileges from database:
|
134
|
-
|
135
|
-
``` ruby
|
136
|
-
username = 'foobar'
|
137
|
-
database = 'foo'
|
138
|
-
permission = :write # options are :read, :write, :all
|
139
|
-
|
140
|
-
influxdb.revoke_user_privileges(username, database, permission)
|
141
|
-
```
|
142
|
-
Delete a user:
|
143
|
-
|
144
|
-
``` ruby
|
145
|
-
username = 'foobar'
|
146
|
-
|
147
|
-
influxdb.delete_user(username)
|
148
|
-
```
|
149
|
-
|
150
|
-
List users:
|
151
|
-
|
152
|
-
``` ruby
|
153
|
-
influxdb.list_users
|
154
|
-
```
|
155
|
-
|
156
|
-
Create cluster admin:
|
157
|
-
|
158
|
-
``` ruby
|
159
|
-
username = 'foobar'
|
160
|
-
password = 'pwd'
|
161
|
-
|
162
|
-
influxdb.create_cluster_admin(username, password)
|
163
|
-
```
|
164
|
-
|
165
|
-
List cluster admins:
|
166
|
-
|
167
|
-
``` ruby
|
168
|
-
influxdb.list_cluster_admins
|
169
|
-
```
|
170
|
-
|
171
|
-
Revoke cluster admin privileges from user:
|
172
|
-
|
173
|
-
``` ruby
|
174
|
-
username = 'foobar'
|
175
|
-
|
176
|
-
influxdb.revoke_cluster_admin_privileges(username)
|
177
|
-
```
|
178
|
-
|
179
|
-
### Continuous Queries
|
180
|
-
|
181
|
-
List continuous queries of a database:
|
182
|
-
|
183
|
-
``` ruby
|
184
|
-
database = 'foo'
|
185
|
-
|
186
|
-
influxdb.list_continuous_queries(database)
|
187
|
-
```
|
188
|
-
|
189
|
-
Create a continuous query for a database:
|
190
|
-
|
191
|
-
``` ruby
|
192
|
-
database = 'foo'
|
193
|
-
name = 'clicks_count'
|
194
|
-
query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)'
|
195
|
-
|
196
|
-
influxdb.create_continuous_query(name, database, query)
|
197
|
-
```
|
198
|
-
|
199
|
-
Additionally, you can specify the resample interval and the time range over
|
200
|
-
which the CQ runs:
|
201
|
-
|
202
|
-
``` ruby
|
203
|
-
influxdb.create_continuous_query(name, database, query, resample_every: "10m", resample_for: "65m")
|
204
|
-
```
|
205
|
-
|
206
|
-
Delete a continuous query from a database:
|
207
|
-
|
208
|
-
``` ruby
|
209
|
-
database = 'foo'
|
210
|
-
name = 'clicks_count'
|
211
|
-
|
212
|
-
influxdb.delete_continuous_query(name, database)
|
213
|
-
```
|
214
|
-
|
215
|
-
### Retention Policies
|
216
|
-
|
217
|
-
List retention policies of a database:
|
218
|
-
|
219
|
-
``` ruby
|
220
|
-
database = 'foo'
|
221
|
-
|
222
|
-
influxdb.list_retention_policies(database)
|
223
|
-
```
|
224
|
-
|
225
|
-
Create a retention policy for a database:
|
226
|
-
|
227
|
-
``` ruby
|
228
|
-
database = 'foo'
|
229
|
-
name = '1h.cpu'
|
230
|
-
duration = '10m'
|
231
|
-
replication = 2
|
232
|
-
|
233
|
-
influxdb.create_retention_policy(name, database, duration, replication)
|
234
|
-
```
|
235
|
-
|
236
|
-
Delete a retention policy from a database:
|
237
|
-
|
238
|
-
``` ruby
|
239
|
-
database = 'foo'
|
240
|
-
name = '1h.cpu'
|
241
|
-
|
242
|
-
influxdb.delete_retention_policy(name, database)
|
243
|
-
```
|
244
|
-
|
245
|
-
Alter a retention policy for a database:
|
246
|
-
|
247
|
-
``` ruby
|
248
|
-
database = 'foo'
|
249
|
-
name = '1h.cpu'
|
250
|
-
duration = '10m'
|
251
|
-
replication = 2
|
252
|
-
|
253
|
-
influxdb.alter_retention_policy(name, database, duration, replication)
|
254
|
-
```
|
255
|
-
|
256
78
|
### Writing data
|
257
79
|
|
258
80
|
Write some data:
|
@@ -306,24 +128,44 @@ influxdb.write_point(name, data)
|
|
306
128
|
|
307
129
|
# or in a method call:
|
308
130
|
influxdb.write_point(name, data, time_precision)
|
309
|
-
|
310
131
|
```
|
311
132
|
|
133
|
+
> ### A Note About Time Precision
|
134
|
+
>
|
135
|
+
> The default precision (in this Rubygem) is `"s"` (second), as Ruby's
|
136
|
+
> `Time#to_i` operates on this resolution.
|
137
|
+
>
|
138
|
+
> If you write data points with sub-second resolution (for example
|
139
|
+
> via `Time#to_r`), you need to configure your client instance with an
|
140
|
+
> appropiate `time_precision` option **and** you'll need to provide a
|
141
|
+
> timestamp value which reflects this precision:
|
142
|
+
>
|
143
|
+
> ```ruby
|
144
|
+
> influxdb = InfluxDB::Client.new time_precision: "ms"
|
145
|
+
> time = (Time.now.to_r * 10**6).to_i
|
146
|
+
> influxdb.write_point("foobar", { values: { n: 42 }, timestamp: time })
|
147
|
+
> ```
|
148
|
+
|
149
|
+
Allowed values for `time_precision` are:
|
150
|
+
|
151
|
+
- `"ns"` or `nil` for nanosecond
|
152
|
+
- `"u"` for microsecond
|
153
|
+
- `"ms"` for millisecond
|
154
|
+
- `"s"` for second
|
155
|
+
- `"m"` for minute
|
156
|
+
- `"h"` for hour
|
157
|
+
|
312
158
|
Write data with a specific retention policy:
|
313
159
|
|
314
160
|
``` ruby
|
315
|
-
require 'influxdb'
|
316
|
-
|
317
|
-
username = 'foo'
|
318
|
-
password = 'bar'
|
319
161
|
database = 'site_development'
|
320
162
|
name = 'foobar'
|
321
163
|
precision = 's'
|
322
164
|
retention = '1h.cpu'
|
323
165
|
|
324
166
|
influxdb = InfluxDB::Client.new database,
|
325
|
-
username:
|
326
|
-
password:
|
167
|
+
username: "foo",
|
168
|
+
password: "bar"
|
327
169
|
|
328
170
|
data = {
|
329
171
|
values: { value: 0 },
|
@@ -337,18 +179,14 @@ influxdb.write_point(name, data, precision, retention)
|
|
337
179
|
Write data while choosing the database:
|
338
180
|
|
339
181
|
``` ruby
|
340
|
-
require 'influxdb'
|
341
|
-
|
342
|
-
username = 'foo'
|
343
|
-
password = 'bar'
|
344
182
|
database = 'site_development'
|
345
183
|
name = 'foobar'
|
346
184
|
precision = 's'
|
347
185
|
retention = '1h.cpu'
|
348
186
|
|
349
187
|
influxdb = InfluxDB::Client.new {
|
350
|
-
username:
|
351
|
-
password:
|
188
|
+
username: "foo",
|
189
|
+
password: "bar"
|
352
190
|
}
|
353
191
|
|
354
192
|
data = {
|
@@ -363,7 +201,6 @@ influxdb.write_point(name, data, precision, retention, database)
|
|
363
201
|
Write multiple points in a batch (performance boost):
|
364
202
|
|
365
203
|
``` ruby
|
366
|
-
|
367
204
|
data = [
|
368
205
|
{
|
369
206
|
series: 'cpu',
|
@@ -402,22 +239,17 @@ data = [
|
|
402
239
|
precision = 'm'
|
403
240
|
retention = '1h.cpu'
|
404
241
|
influxdb.write_points(data, precision, retention)
|
405
|
-
|
406
242
|
```
|
407
243
|
|
408
244
|
Write asynchronously (note that a retention policy cannot be specified for asynchronous writes):
|
409
245
|
|
410
246
|
``` ruby
|
411
|
-
require 'influxdb'
|
412
|
-
|
413
|
-
username = 'foo'
|
414
|
-
password = 'bar'
|
415
247
|
database = 'site_development'
|
416
248
|
name = 'foobar'
|
417
249
|
|
418
250
|
influxdb = InfluxDB::Client.new database,
|
419
|
-
username:
|
420
|
-
password:
|
251
|
+
username: "foo",
|
252
|
+
password: "bar",
|
421
253
|
async: true
|
422
254
|
|
423
255
|
data = {
|
@@ -444,21 +276,13 @@ async_options = {
|
|
444
276
|
sleep_interval: 5
|
445
277
|
}
|
446
278
|
|
447
|
-
influxdb = InfluxDB::Client.new database,
|
448
|
-
username: username,
|
449
|
-
password: password,
|
450
|
-
async: async_options
|
279
|
+
influxdb = InfluxDB::Client.new database, async: async_options
|
451
280
|
```
|
452
281
|
|
453
|
-
|
454
282
|
Write data via UDP (note that a retention policy cannot be specified for UDP writes):
|
455
283
|
|
456
284
|
``` ruby
|
457
|
-
|
458
|
-
host = '127.0.0.1'
|
459
|
-
port = 4444
|
460
|
-
|
461
|
-
influxdb = InfluxDB::Client.new udp: { host: host, port: port }
|
285
|
+
influxdb = InfluxDB::Client.new udp: { host: "127.0.0.1", port: 4444 }
|
462
286
|
|
463
287
|
name = 'hitchhiker'
|
464
288
|
|
@@ -473,30 +297,22 @@ influxdb.write_point(name, data)
|
|
473
297
|
Discard write errors:
|
474
298
|
|
475
299
|
``` ruby
|
476
|
-
require 'influxdb'
|
477
|
-
host = '127.0.0.1'
|
478
|
-
port = 4444
|
479
|
-
|
480
300
|
influxdb = InfluxDB::Client.new(
|
481
|
-
udp: { host:
|
301
|
+
udp: { host: "127.0.0.1", port: 4444 },
|
482
302
|
discard_write_errors: true
|
483
303
|
)
|
484
304
|
|
485
305
|
influxdb.write_point('hitchhiker', { values: { value: 666 } })
|
486
306
|
```
|
487
307
|
|
488
|
-
### Reading data
|
489
308
|
|
490
|
-
|
309
|
+
### Querying
|
491
310
|
|
492
311
|
``` ruby
|
493
|
-
username = 'foo'
|
494
|
-
password = 'bar'
|
495
312
|
database = 'site_development'
|
496
|
-
|
497
313
|
influxdb = InfluxDB::Client.new database,
|
498
|
-
username:
|
499
|
-
password:
|
314
|
+
username: "foo",
|
315
|
+
password: "bar"
|
500
316
|
|
501
317
|
# without a block:
|
502
318
|
influxdb.query 'select * from time_series_1 group by region'
|
@@ -523,9 +339,9 @@ influxdb.query 'select * from time_series_1 group by region'
|
|
523
339
|
|
524
340
|
# with a block:
|
525
341
|
influxdb.query 'select * from time_series_1 group by region' do |name, tags, points|
|
526
|
-
|
342
|
+
printf "%s [ %p ]\n", name, tags
|
527
343
|
points.each do |pt|
|
528
|
-
|
344
|
+
printf " -> %p\n", pt
|
529
345
|
end
|
530
346
|
end
|
531
347
|
|
@@ -584,6 +400,190 @@ influxdb.query positional_params_query, params: ["foobar", 42]
|
|
584
400
|
# select * from time_series_0 where f = 'foobar' and i < 42
|
585
401
|
```
|
586
402
|
|
403
|
+
## Advanced Topics
|
404
|
+
|
405
|
+
### Administrative tasks
|
406
|
+
|
407
|
+
Create a database:
|
408
|
+
|
409
|
+
``` ruby
|
410
|
+
database = 'site_development'
|
411
|
+
|
412
|
+
influxdb.create_database(database)
|
413
|
+
```
|
414
|
+
|
415
|
+
Delete a database:
|
416
|
+
|
417
|
+
``` ruby
|
418
|
+
database = 'site_development'
|
419
|
+
|
420
|
+
influxdb.delete_database(database)
|
421
|
+
```
|
422
|
+
|
423
|
+
List databases:
|
424
|
+
|
425
|
+
``` ruby
|
426
|
+
influxdb.list_databases
|
427
|
+
```
|
428
|
+
|
429
|
+
Create a user for a database:
|
430
|
+
|
431
|
+
``` ruby
|
432
|
+
database = 'site_development'
|
433
|
+
new_username = 'foo'
|
434
|
+
new_password = 'bar'
|
435
|
+
permission = :write
|
436
|
+
|
437
|
+
# with all permissions
|
438
|
+
influxdb.create_database_user(database, new_username, new_password)
|
439
|
+
|
440
|
+
# with specified permission - options are: :read, :write, :all
|
441
|
+
influxdb.create_database_user(database, new_username, new_password, permissions: permission)
|
442
|
+
```
|
443
|
+
|
444
|
+
Update a user password:
|
445
|
+
|
446
|
+
``` ruby
|
447
|
+
username = 'foo'
|
448
|
+
new_password = 'bar'
|
449
|
+
|
450
|
+
influxdb.update_user_password(username, new_password)
|
451
|
+
```
|
452
|
+
|
453
|
+
Grant user privileges on database:
|
454
|
+
|
455
|
+
``` ruby
|
456
|
+
username = 'foobar'
|
457
|
+
database = 'foo'
|
458
|
+
permission = :read # options are :read, :write, :all
|
459
|
+
|
460
|
+
influxdb.grant_user_privileges(username, database, permission)
|
461
|
+
```
|
462
|
+
|
463
|
+
Revoke user privileges from database:
|
464
|
+
|
465
|
+
``` ruby
|
466
|
+
username = 'foobar'
|
467
|
+
database = 'foo'
|
468
|
+
permission = :write # options are :read, :write, :all
|
469
|
+
|
470
|
+
influxdb.revoke_user_privileges(username, database, permission)
|
471
|
+
```
|
472
|
+
Delete a user:
|
473
|
+
|
474
|
+
``` ruby
|
475
|
+
username = 'foobar'
|
476
|
+
|
477
|
+
influxdb.delete_user(username)
|
478
|
+
```
|
479
|
+
|
480
|
+
List users:
|
481
|
+
|
482
|
+
``` ruby
|
483
|
+
influxdb.list_users
|
484
|
+
```
|
485
|
+
|
486
|
+
Create cluster admin:
|
487
|
+
|
488
|
+
``` ruby
|
489
|
+
username = 'foobar'
|
490
|
+
password = 'pwd'
|
491
|
+
|
492
|
+
influxdb.create_cluster_admin(username, password)
|
493
|
+
```
|
494
|
+
|
495
|
+
List cluster admins:
|
496
|
+
|
497
|
+
``` ruby
|
498
|
+
influxdb.list_cluster_admins
|
499
|
+
```
|
500
|
+
|
501
|
+
Revoke cluster admin privileges from user:
|
502
|
+
|
503
|
+
``` ruby
|
504
|
+
username = 'foobar'
|
505
|
+
|
506
|
+
influxdb.revoke_cluster_admin_privileges(username)
|
507
|
+
```
|
508
|
+
|
509
|
+
### Continuous Queries
|
510
|
+
|
511
|
+
List continuous queries of a database:
|
512
|
+
|
513
|
+
``` ruby
|
514
|
+
database = 'foo'
|
515
|
+
|
516
|
+
influxdb.list_continuous_queries(database)
|
517
|
+
```
|
518
|
+
|
519
|
+
Create a continuous query for a database:
|
520
|
+
|
521
|
+
``` ruby
|
522
|
+
database = 'foo'
|
523
|
+
name = 'clicks_count'
|
524
|
+
query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)'
|
525
|
+
|
526
|
+
influxdb.create_continuous_query(name, database, query)
|
527
|
+
```
|
528
|
+
|
529
|
+
Additionally, you can specify the resample interval and the time range over
|
530
|
+
which the CQ runs:
|
531
|
+
|
532
|
+
``` ruby
|
533
|
+
influxdb.create_continuous_query(name, database, query, resample_every: "10m", resample_for: "65m")
|
534
|
+
```
|
535
|
+
|
536
|
+
Delete a continuous query from a database:
|
537
|
+
|
538
|
+
``` ruby
|
539
|
+
database = 'foo'
|
540
|
+
name = 'clicks_count'
|
541
|
+
|
542
|
+
influxdb.delete_continuous_query(name, database)
|
543
|
+
```
|
544
|
+
|
545
|
+
### Retention Policies
|
546
|
+
|
547
|
+
List retention policies of a database:
|
548
|
+
|
549
|
+
``` ruby
|
550
|
+
database = 'foo'
|
551
|
+
|
552
|
+
influxdb.list_retention_policies(database)
|
553
|
+
```
|
554
|
+
|
555
|
+
Create a retention policy for a database:
|
556
|
+
|
557
|
+
``` ruby
|
558
|
+
database = 'foo'
|
559
|
+
name = '1h.cpu'
|
560
|
+
duration = '10m'
|
561
|
+
replication = 2
|
562
|
+
|
563
|
+
influxdb.create_retention_policy(name, database, duration, replication)
|
564
|
+
```
|
565
|
+
|
566
|
+
Delete a retention policy from a database:
|
567
|
+
|
568
|
+
``` ruby
|
569
|
+
database = 'foo'
|
570
|
+
name = '1h.cpu'
|
571
|
+
|
572
|
+
influxdb.delete_retention_policy(name, database)
|
573
|
+
```
|
574
|
+
|
575
|
+
Alter a retention policy for a database:
|
576
|
+
|
577
|
+
``` ruby
|
578
|
+
database = 'foo'
|
579
|
+
name = '1h.cpu'
|
580
|
+
duration = '10m'
|
581
|
+
replication = 2
|
582
|
+
|
583
|
+
influxdb.alter_retention_policy(name, database, duration, replication)
|
584
|
+
```
|
585
|
+
|
586
|
+
### Reading data
|
587
587
|
|
588
588
|
#### (De-) Normalization
|
589
589
|
|
@@ -616,13 +616,12 @@ influxdb.query 'select * from time_series_1 group by region', denormalize: false
|
|
616
616
|
|
617
617
|
|
618
618
|
influxdb.query 'select * from time_series_1 group by region', denormalize: false do |name, tags, points|
|
619
|
-
|
619
|
+
printf "%s [ %p ]\n", name, tags
|
620
620
|
points.each do |key, values|
|
621
|
-
|
621
|
+
printf " %p -> %p\n", key, values
|
622
622
|
end
|
623
623
|
end
|
624
624
|
|
625
|
-
|
626
625
|
# time_series_1 [ {"region"=>"uk"} ]
|
627
626
|
# columns -> ["time", "count", "value"]
|
628
627
|
# values -> [["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]}
|
@@ -681,6 +680,7 @@ E, [2016-08-31T23:55:19.562428 #23476] ERROR -- InfluxDB: Failed to contact host
|
|
681
680
|
InfluxDB::ConnectionError: Tried 8 times to reconnect but failed.
|
682
681
|
```
|
683
682
|
|
683
|
+
|
684
684
|
## Testing
|
685
685
|
|
686
686
|
```
|
data/influxdb.gemspec
CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "json"
|
23
|
-
spec.add_runtime_dependency "cause"
|
24
23
|
|
25
24
|
spec.add_development_dependency "rake"
|
26
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
27
26
|
spec.add_development_dependency "rspec", "~> 3.5.0"
|
28
27
|
spec.add_development_dependency "webmock", "~> 2.1.0"
|
29
28
|
spec.add_development_dependency "rubocop", "~> 0.41.2"
|
29
|
+
spec.add_development_dependency "cause"
|
30
30
|
end
|
data/lib/influxdb/client.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'cause' unless Exception.instance_methods.include?(:cause)
|
3
2
|
require 'thread'
|
4
3
|
|
5
4
|
module InfluxDB
|
@@ -49,6 +48,7 @@ module InfluxDB
|
|
49
48
|
# +:verify_ssl+:: verify ssl server certificate?
|
50
49
|
# +:ssl_ca_cert+:: ssl CA certificate, chainfile or CA path.
|
51
50
|
# The system CA path is automatically included
|
51
|
+
# +:retry:: number of times a failed request should be retried. Defaults to infinite.
|
52
52
|
def initialize(*args)
|
53
53
|
opts = args.last.is_a?(Hash) ? args.last : {}
|
54
54
|
opts[:database] = args.first if args.first.is_a? String
|
data/lib/influxdb/config.rb
CHANGED
data/lib/influxdb/errors.rb
CHANGED
@@ -36,7 +36,7 @@ module InfluxDB # :nodoc:
|
|
36
36
|
Net::HTTPHeaderSyntaxError,
|
37
37
|
Net::ProtocolError,
|
38
38
|
SocketError,
|
39
|
-
(OpenSSL::SSL::SSLError if defined?(OpenSSL))
|
39
|
+
(OpenSSL::SSL::SSLError if defined?(OpenSSL)),
|
40
40
|
].compact.freeze
|
41
41
|
|
42
42
|
# Exception classes which hint to a larger problem on the server side,
|
@@ -44,7 +44,7 @@ module InfluxDB # :nodoc:
|
|
44
44
|
# _don't_ retry a query but escalate it upwards.
|
45
45
|
NON_RECOVERABLE_EXCEPTIONS = [
|
46
46
|
EOFError,
|
47
|
-
Zlib::Error
|
47
|
+
Zlib::Error,
|
48
48
|
].freeze
|
49
49
|
|
50
50
|
NON_RECOVERABLE_MESSAGE = "The server has sent incomplete data" \
|
data/lib/influxdb/point_value.rb
CHANGED
@@ -7,7 +7,6 @@ module InfluxDB
|
|
7
7
|
@series = escape data[:series], :measurement
|
8
8
|
@values = escape_values data[:values]
|
9
9
|
@tags = escape_tags data[:tags]
|
10
|
-
|
11
10
|
@timestamp = data[:timestamp]
|
12
11
|
end
|
13
12
|
|
@@ -26,7 +25,7 @@ module InfluxDB
|
|
26
25
|
tag_key: ['='.freeze, ' '.freeze, ','.freeze],
|
27
26
|
tag_value: ['='.freeze, ' '.freeze, ','.freeze],
|
28
27
|
field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze],
|
29
|
-
field_value: ['"'.freeze]
|
28
|
+
field_value: ['"'.freeze],
|
30
29
|
}.freeze
|
31
30
|
|
32
31
|
def escape(s, type)
|
data/lib/influxdb/query/core.rb
CHANGED
@@ -69,8 +69,8 @@ module InfluxDB
|
|
69
69
|
|
70
70
|
def write(data, precision, retention_policy = nil, database = nil)
|
71
71
|
params = {
|
72
|
-
db:
|
73
|
-
precision:
|
72
|
+
db: database || config.database,
|
73
|
+
precision: precision || config.time_precision,
|
74
74
|
}
|
75
75
|
|
76
76
|
params[:rp] = retention_policy if retention_policy
|
@@ -87,11 +87,12 @@ module InfluxDB
|
|
87
87
|
chunk_size = opts.fetch(:chunk_size, config.chunk_size)
|
88
88
|
database = opts.fetch(:database, config.database)
|
89
89
|
|
90
|
-
params = { q: query, db: database
|
91
|
-
params[:
|
90
|
+
params = { q: query, db: database }
|
91
|
+
params[:precision] = precision if precision
|
92
|
+
params[:epoch] = epoch if epoch
|
92
93
|
|
93
94
|
if chunk_size
|
94
|
-
params[:chunked] = 'true'
|
95
|
+
params[:chunked] = 'true'.freeze
|
95
96
|
params[:chunk_size] = chunk_size
|
96
97
|
end
|
97
98
|
|
@@ -102,9 +103,9 @@ module InfluxDB
|
|
102
103
|
def denormalized_series_list(series)
|
103
104
|
series.map do |s|
|
104
105
|
{
|
105
|
-
"name" => s["name".freeze],
|
106
|
-
"tags" => s["tags".freeze],
|
107
|
-
"values" => denormalize_series(s)
|
106
|
+
"name".freeze => s["name".freeze],
|
107
|
+
"tags".freeze => s["tags".freeze],
|
108
|
+
"values".freeze => denormalize_series(s),
|
108
109
|
}
|
109
110
|
end
|
110
111
|
end
|
@@ -13,9 +13,20 @@ module InfluxDB
|
|
13
13
|
resp = execute("SHOW DATABASES".freeze, parse: true)
|
14
14
|
fetch_series(resp)
|
15
15
|
.fetch(0, {})
|
16
|
-
.fetch(
|
16
|
+
.fetch("values".freeze, [])
|
17
17
|
.flatten
|
18
|
-
.map { |v| {
|
18
|
+
.map { |v| { "name".freeze => v } }
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_field_keys
|
22
|
+
query("SHOW FIELD KEYS".freeze, precision: nil).each_with_object({}) do |collection, keys|
|
23
|
+
name = collection.fetch("name")
|
24
|
+
values = collection.fetch("values", [])
|
25
|
+
|
26
|
+
keys[name] = values.each_with_object({}) do |row, types|
|
27
|
+
types[row.fetch("fieldKey")] = [row.fetch("fieldType")]
|
28
|
+
end
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
data/lib/influxdb/version.rb
CHANGED
@@ -35,6 +35,23 @@ describe InfluxDB::Client do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
describe "GET empty #list_series" do
|
39
|
+
let(:response) { { "results" => [{ "series" => [] }] } }
|
40
|
+
let(:query) { "SHOW SERIES" }
|
41
|
+
|
42
|
+
before do
|
43
|
+
stub_request(:get, "http://influxdb.test:9999/query").with(
|
44
|
+
query: { u: "username", p: "password", q: query, db: "database" }
|
45
|
+
).to_return(
|
46
|
+
body: JSON.generate(response)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a empty list" do
|
51
|
+
expect(subject.list_series).to eq []
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
38
55
|
describe "#delete_series" do
|
39
56
|
let(:name) { "events" }
|
40
57
|
let(:query) { "DROP SERIES FROM #{name}" }
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
describe InfluxDB::Client do
|
5
|
+
let(:subject) do
|
6
|
+
described_class.new "database",
|
7
|
+
host: "influxdb.test",
|
8
|
+
port: 9999,
|
9
|
+
username: "username",
|
10
|
+
password: "password"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:query) { nil }
|
14
|
+
let(:response) { { "results" => [{ "statement_id" => 0 }] } }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, "http://influxdb.test:9999/query").with(
|
18
|
+
query: { u: "username", p: "password", q: query, db: "database" }
|
19
|
+
).to_return(body: JSON.generate(response))
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#show_field_keys" do
|
23
|
+
let(:query) { "SHOW FIELD KEYS" }
|
24
|
+
let(:response) do
|
25
|
+
{
|
26
|
+
"results" => [{
|
27
|
+
"series" => [{
|
28
|
+
"name" => "measurement_a",
|
29
|
+
"columns" => %w(fieldKey fieldType),
|
30
|
+
"values" => [%w(a_string_field string),
|
31
|
+
%w(a_boolean_field boolean),
|
32
|
+
%w(a_float_field float),
|
33
|
+
%w(an_integer_field integer)]
|
34
|
+
}, {
|
35
|
+
"name" => "measurement_b",
|
36
|
+
"columns" => %w(fieldKey fieldType),
|
37
|
+
"values" => [%w(another_string string)]
|
38
|
+
}]
|
39
|
+
}]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
let(:expected_result) do
|
43
|
+
{
|
44
|
+
"measurement_a" => {
|
45
|
+
"a_string_field" => ["string"],
|
46
|
+
"a_boolean_field" => ["boolean"],
|
47
|
+
"a_float_field" => ["float"],
|
48
|
+
"an_integer_field" => ["integer"],
|
49
|
+
},
|
50
|
+
"measurement_b" => {
|
51
|
+
"another_string" => ["string"],
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should GET a list of field/type pairs per measurement" do
|
57
|
+
expect(subject.show_field_keys).to eq(expected_result)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -39,35 +39,38 @@ describe InfluxDB::PointValue do
|
|
39
39
|
'responses,region=eu,status=200 value=5i,threshold=0.54 1436349652'
|
40
40
|
end
|
41
41
|
it 'should have proper form' do
|
42
|
-
point = InfluxDB::PointValue.new
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
point = InfluxDB::PointValue.new \
|
43
|
+
series: "responses",
|
44
|
+
values: { value: 5, threshold: 0.54 },
|
45
|
+
tags: { region: 'eu', status: 200 },
|
46
|
+
timestamp: 1_436_349_652
|
46
47
|
|
47
48
|
expect(point.dump).to eq(expected_value)
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
context "
|
52
|
+
context "without tags" do
|
52
53
|
let(:expected_value) do
|
53
54
|
"responses value=5i,threshold=0.54 1436349652"
|
54
55
|
end
|
55
56
|
it 'should have proper form' do
|
56
|
-
point = InfluxDB::PointValue.new
|
57
|
-
|
58
|
-
|
57
|
+
point = InfluxDB::PointValue.new \
|
58
|
+
series: "responses",
|
59
|
+
values: { value: 5, threshold: 0.54 },
|
60
|
+
timestamp: 1_436_349_652
|
59
61
|
|
60
62
|
expect(point.dump).to eq(expected_value)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
|
-
context "
|
66
|
+
context "without tags and timestamp" do
|
65
67
|
let(:expected_value) do
|
66
68
|
"responses value=5i,threshold=0.54"
|
67
69
|
end
|
68
70
|
it 'should have proper form' do
|
69
|
-
point = InfluxDB::PointValue.new
|
70
|
-
|
71
|
+
point = InfluxDB::PointValue.new \
|
72
|
+
series: "responses",
|
73
|
+
values: { value: 5, threshold: 0.54 }
|
71
74
|
|
72
75
|
expect(point.dump).to eq(expected_value)
|
73
76
|
end
|
@@ -79,9 +82,10 @@ describe InfluxDB::PointValue do
|
|
79
82
|
end
|
80
83
|
|
81
84
|
it "should be omitted" do
|
82
|
-
point = InfluxDB::PointValue.new
|
83
|
-
|
84
|
-
|
85
|
+
point = InfluxDB::PointValue.new \
|
86
|
+
series: "responses",
|
87
|
+
values: { value: 5 },
|
88
|
+
tags: { region: "eu", status: nil, other: "", nil => "ignored", "" => "ignored" }
|
85
89
|
expect(point.dump).to eq(expected_value)
|
86
90
|
end
|
87
91
|
end
|
data/spec/spec_helper.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.3.
|
4
|
+
version: 0.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: cause
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +94,20 @@ dependencies:
|
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: 0.41.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: cause
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
111
|
description: This is the official Ruby library for InfluxDB.
|
112
112
|
email:
|
113
113
|
- influxdb@googlegroups.com
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- spec/influxdb/cases/querying_issue_7000_spec.rb
|
161
161
|
- spec/influxdb/cases/querying_spec.rb
|
162
162
|
- spec/influxdb/cases/retry_requests_spec.rb
|
163
|
+
- spec/influxdb/cases/show_field_keys_spec.rb
|
163
164
|
- spec/influxdb/cases/udp_client_spec.rb
|
164
165
|
- spec/influxdb/cases/write_points_spec.rb
|
165
166
|
- spec/influxdb/client_spec.rb
|
@@ -212,6 +213,7 @@ test_files:
|
|
212
213
|
- spec/influxdb/cases/querying_issue_7000_spec.rb
|
213
214
|
- spec/influxdb/cases/querying_spec.rb
|
214
215
|
- spec/influxdb/cases/retry_requests_spec.rb
|
216
|
+
- spec/influxdb/cases/show_field_keys_spec.rb
|
215
217
|
- spec/influxdb/cases/udp_client_spec.rb
|
216
218
|
- spec/influxdb/cases/write_points_spec.rb
|
217
219
|
- spec/influxdb/client_spec.rb
|