influxdb 0.1.9 → 0.2.0
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/.gitignore +1 -0
- data/.rubocop.yml +41 -0
- data/.travis.yml +3 -2
- data/Gemfile +7 -1
- data/README.md +218 -102
- data/Rakefile +2 -6
- data/lib/influxdb.rb +15 -5
- data/lib/influxdb/client.rb +38 -433
- data/lib/influxdb/client/http.rb +123 -0
- data/lib/influxdb/config.rb +66 -0
- data/lib/influxdb/errors.rb +8 -2
- data/lib/influxdb/{logger.rb → logging.rb} +6 -5
- data/lib/influxdb/max_queue.rb +2 -1
- data/lib/influxdb/point_value.rb +27 -25
- data/lib/influxdb/query/cluster.rb +17 -0
- data/lib/influxdb/query/continuous_query.rb +22 -0
- data/lib/influxdb/query/core.rb +110 -0
- data/lib/influxdb/query/database.rb +21 -0
- data/lib/influxdb/query/retention_policy.rb +26 -0
- data/lib/influxdb/query/user.rb +41 -0
- data/lib/influxdb/version.rb +2 -2
- data/lib/influxdb/writer/async.rb +115 -0
- data/lib/influxdb/writer/udp.rb +21 -0
- data/spec/influxdb/cases/async_client_spec.rb +33 -0
- data/spec/influxdb/cases/query_cluster_spec.rb +65 -0
- data/spec/influxdb/cases/query_continuous_query_spec.rb +82 -0
- data/spec/influxdb/cases/query_core.rb +34 -0
- data/spec/influxdb/cases/query_database_spec.rb +58 -0
- data/spec/influxdb/cases/query_retention_policy_spec.rb +84 -0
- data/spec/influxdb/cases/query_series_spec.rb +50 -0
- data/spec/influxdb/cases/query_shard_space_spec.rb +105 -0
- data/spec/influxdb/cases/query_shard_spec.rb +43 -0
- data/spec/influxdb/cases/query_user_spec.rb +127 -0
- data/spec/influxdb/cases/querying_spec.rb +149 -0
- data/spec/influxdb/cases/retry_requests_spec.rb +102 -0
- data/spec/influxdb/cases/udp_client_spec.rb +21 -0
- data/spec/influxdb/cases/write_points_spec.rb +140 -0
- data/spec/influxdb/client_spec.rb +37 -810
- data/spec/influxdb/config_spec.rb +118 -0
- data/spec/influxdb/{logger_spec.rb → logging_spec.rb} +4 -8
- data/spec/influxdb/max_queue_spec.rb +29 -0
- data/spec/influxdb/point_value_spec.rb +81 -14
- data/spec/influxdb/worker_spec.rb +8 -11
- data/spec/spec_helper.rb +7 -10
- metadata +65 -30
- data/lib/influxdb/udp_client.rb +0 -16
- data/lib/influxdb/worker.rb +0 -80
- data/spec/influxdb/udp_client_spec.rb +0 -33
- data/spec/influxdb_spec.rb +0 -4
- data/spec/max_queue_spec.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5122c2a56a46565d1ee7481c6d20e1647035e94d
|
4
|
+
data.tar.gz: e4c1e752d0d49a5d3749e92f6c1afd1fbc269549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4053245ecd16e82ee75055a407099a4ab44740722abc225d2a27fa1c3c562f6b703c07dae3322f523ec4cb3181ec69c991c17d2b8842af58970df10a343f717
|
7
|
+
data.tar.gz: adcf58659107dfc6ef3c99a4628c33662cbabc2782e06eb47cdfa90e345c2946d2e56af2e5849641221b5971cfad8ebc83d2cae4149a6a5bd778fe21270f6211
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
AllCops:
|
2
|
+
# Include gemspec and Rakefile
|
3
|
+
Include:
|
4
|
+
- 'lib/**/*.rb'
|
5
|
+
- 'lib/**/*.rake'
|
6
|
+
- 'spec/**/*.rb'
|
7
|
+
Exclude:
|
8
|
+
- 'bin/**/*'
|
9
|
+
RunRailsCops: false
|
10
|
+
DisplayCopNames: true
|
11
|
+
StyleGuideCopsOnly: false
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Exclude:
|
15
|
+
- 'spec/**/*.rb'
|
16
|
+
|
17
|
+
Style/StringLiterals:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/BlockDelimiters:
|
21
|
+
Exclude:
|
22
|
+
- 'spec/**/*.rb'
|
23
|
+
|
24
|
+
Style/RescueModifier:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Lint/HandleExceptions:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Lint/Void:
|
31
|
+
Exclude:
|
32
|
+
- 'spec/**/*.rb'
|
33
|
+
|
34
|
+
Metrics/LineLength:
|
35
|
+
Max: 100
|
36
|
+
Exclude:
|
37
|
+
- 'spec/**/*.rb'
|
38
|
+
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Exclude:
|
41
|
+
- 'spec/**/*.rb'
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,4 +2,10 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem "webmock", :
|
5
|
+
gem "webmock", git: "https://github.com/influxdb/webmock.git"
|
6
|
+
|
7
|
+
local_gemfile = 'Gemfile.local'
|
8
|
+
|
9
|
+
if File.exist?(local_gemfile)
|
10
|
+
eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
|
11
|
+
end
|
data/README.md
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
influxdb-ruby
|
2
2
|
=============
|
3
3
|
|
4
|
-
# This library is not updated for InfluxDB 0.9.0. There are breaking changes to the API, use at your own risk.
|
5
|
-
|
6
|
-
We encourage you to submit a pull request if you have a contribution.
|
7
|
-
|
8
|
-
----------
|
9
|
-
|
10
|
-
|
11
|
-
|
12
4
|
[](https://travis-ci.org/influxdb/influxdb-ruby)
|
13
5
|
|
14
|
-
|
6
|
+
The official ruby client library for [InfluxDB](https://influxdb.com/).
|
15
7
|
|
16
8
|
Install
|
17
9
|
-------
|
@@ -46,56 +38,179 @@ influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domai
|
|
46
38
|
Create a database:
|
47
39
|
|
48
40
|
``` ruby
|
49
|
-
|
41
|
+
database = 'site_development'
|
42
|
+
|
43
|
+
influxdb.create_database(database)
|
44
|
+
```
|
50
45
|
|
51
|
-
|
46
|
+
Delete a database:
|
52
47
|
|
48
|
+
``` ruby
|
53
49
|
database = 'site_development'
|
54
50
|
|
55
|
-
influxdb.
|
51
|
+
influxdb.delete_database(database)
|
56
52
|
```
|
57
53
|
|
58
|
-
|
54
|
+
List databases:
|
59
55
|
|
60
56
|
``` ruby
|
61
|
-
|
57
|
+
influxdb.list_databases
|
58
|
+
```
|
62
59
|
|
63
|
-
|
60
|
+
Create a user for a database:
|
64
61
|
|
62
|
+
``` ruby
|
65
63
|
database = 'site_development'
|
66
64
|
new_username = 'foo'
|
67
65
|
new_password = 'bar'
|
66
|
+
permission = :write
|
67
|
+
|
68
|
+
# with all permissions
|
68
69
|
influxdb.create_database_user(database, new_username, new_password)
|
70
|
+
|
71
|
+
# with specified permission - options are: :read, :write, :all
|
72
|
+
influxdb.create_database_user(database, new_username, new_password, permissions: permission)
|
69
73
|
```
|
70
74
|
|
71
|
-
Update a
|
75
|
+
Update a user password:
|
72
76
|
|
73
77
|
``` ruby
|
74
|
-
|
78
|
+
username = 'foo'
|
79
|
+
new_password = 'bar'
|
75
80
|
|
76
|
-
influxdb
|
81
|
+
influxdb.update_user_password(username, new_password)
|
82
|
+
```
|
83
|
+
|
84
|
+
Grant user privileges on database:
|
77
85
|
|
78
|
-
|
86
|
+
``` ruby
|
87
|
+
username = 'foobar'
|
88
|
+
database = 'foo'
|
89
|
+
permission = :read # options are :read, :write, :all
|
90
|
+
|
91
|
+
influxdb.grant_user_privileges(username, database, permission)
|
79
92
|
```
|
80
93
|
|
81
|
-
|
94
|
+
Revoke user privileges from database:
|
82
95
|
|
83
96
|
``` ruby
|
84
|
-
|
97
|
+
username = 'foobar'
|
98
|
+
database = 'foo'
|
99
|
+
permission = :write # options are :read, :write, :all
|
100
|
+
|
101
|
+
influxdb.revoke_user_privileges(username, database, permission)
|
102
|
+
```
|
103
|
+
Delete a user:
|
104
|
+
|
105
|
+
``` ruby
|
106
|
+
username = 'foobar'
|
107
|
+
|
108
|
+
influxdb.delete_user(username)
|
109
|
+
```
|
110
|
+
|
111
|
+
List users:
|
112
|
+
|
113
|
+
``` ruby
|
114
|
+
influxdb.list_users
|
115
|
+
```
|
116
|
+
|
117
|
+
Create cluster admin:
|
118
|
+
|
119
|
+
``` ruby
|
120
|
+
username = 'foobar'
|
121
|
+
password = 'pwd'
|
122
|
+
|
123
|
+
influxdb.create_cluster_admin(username, password)
|
124
|
+
```
|
125
|
+
|
126
|
+
List cluster admins:
|
127
|
+
|
128
|
+
``` ruby
|
129
|
+
influxdb.list_cluster_admins
|
130
|
+
```
|
131
|
+
|
132
|
+
Revoke cluster admin privileges from user:
|
133
|
+
|
134
|
+
``` ruby
|
135
|
+
username = 'foobar'
|
136
|
+
|
137
|
+
influxdb.revoke_cluster_admin_privileges(username)
|
138
|
+
```
|
139
|
+
|
140
|
+
List continuous queries of a database:
|
141
|
+
|
142
|
+
``` ruby
|
143
|
+
database = 'foo'
|
144
|
+
|
145
|
+
influxdb.list_continuous_queries(database)
|
146
|
+
```
|
147
|
+
|
148
|
+
Create a continuous query for a database:
|
149
|
+
|
150
|
+
``` ruby
|
151
|
+
database = 'foo'
|
152
|
+
name = 'clicks_count'
|
153
|
+
query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)'
|
154
|
+
|
155
|
+
influxdb.create_continuous_query(name, database, query)
|
156
|
+
```
|
157
|
+
|
158
|
+
Delete a continuous query from a database:
|
159
|
+
|
160
|
+
``` ruby
|
161
|
+
database = 'foo'
|
162
|
+
name = 'clicks_count'
|
163
|
+
|
164
|
+
influxdb.delete_continuous_query(name, database)
|
165
|
+
```
|
166
|
+
|
167
|
+
List retention policies of a database:
|
168
|
+
|
169
|
+
``` ruby
|
170
|
+
database = 'foo'
|
171
|
+
|
172
|
+
influxdb.list_retention_policies(database)
|
173
|
+
```
|
174
|
+
|
175
|
+
Create a retention policy for a database:
|
85
176
|
|
177
|
+
``` ruby
|
178
|
+
database = 'foo'
|
179
|
+
name = '1h.cpu'
|
180
|
+
duration = '10m'
|
181
|
+
replication = 2
|
182
|
+
|
183
|
+
influxdb.create_retention_policy(name, database, duration, replication)
|
184
|
+
```
|
185
|
+
|
186
|
+
Delete a retention policy from a database:
|
187
|
+
|
188
|
+
``` ruby
|
189
|
+
database = 'foo'
|
190
|
+
name = '1h.cpu'
|
191
|
+
|
192
|
+
influxdb.delete_retention_policy(name, database)
|
193
|
+
```
|
194
|
+
|
195
|
+
Write some data:
|
196
|
+
|
197
|
+
``` ruby
|
86
198
|
username = 'foo'
|
87
199
|
password = 'bar'
|
88
200
|
database = 'site_development'
|
89
201
|
name = 'foobar'
|
90
202
|
|
91
|
-
influxdb = InfluxDB::Client.new database,
|
203
|
+
influxdb = InfluxDB::Client.new database,
|
204
|
+
username: username,
|
205
|
+
password: password
|
92
206
|
|
93
207
|
# Enumerator that emits a sine wave
|
94
208
|
Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each
|
95
209
|
|
96
210
|
loop do
|
97
211
|
data = {
|
98
|
-
:value
|
212
|
+
values: { value: Value.next },
|
213
|
+
tags: { wave: 'sine' } # tags are optional
|
99
214
|
}
|
100
215
|
|
101
216
|
influxdb.write_point(name, data)
|
@@ -104,9 +219,7 @@ loop do
|
|
104
219
|
end
|
105
220
|
```
|
106
221
|
|
107
|
-
Write data with time precision:
|
108
|
-
|
109
|
-
Time precision can be set in 2 ways, either in the client initialization
|
222
|
+
Write data with time precision (precision can be set in 2 ways):
|
110
223
|
|
111
224
|
``` ruby
|
112
225
|
require 'influxdb'
|
@@ -117,18 +230,49 @@ database = 'site_development'
|
|
117
230
|
name = 'foobar'
|
118
231
|
time_precision = 's'
|
119
232
|
|
120
|
-
|
121
|
-
|
122
|
-
:
|
233
|
+
# either in the client initialization:
|
234
|
+
influxdb = InfluxDB::Client.new database, username: username,
|
235
|
+
password: password,
|
236
|
+
time_precision: time_precision
|
123
237
|
|
124
238
|
data = {
|
125
|
-
:value
|
126
|
-
:
|
239
|
+
values: { value: 0 },
|
240
|
+
timestamp: Time.now.to_i # timestamp is optional, if not provided point will be saved with current time
|
127
241
|
}
|
128
242
|
|
129
243
|
influxdb.write_point(name, data)
|
244
|
+
|
245
|
+
# or in a method call:
|
246
|
+
influxdb.write_point(name, data, time_precision)
|
247
|
+
|
130
248
|
```
|
131
|
-
|
249
|
+
|
250
|
+
Write multiple points in a batch (performance boost):
|
251
|
+
|
252
|
+
``` ruby
|
253
|
+
|
254
|
+
data = [
|
255
|
+
{
|
256
|
+
series: 'cpu',
|
257
|
+
tags: { host: 'server_1', regios: 'us' },
|
258
|
+
values: {internal: 5, external: 0.453345}
|
259
|
+
},
|
260
|
+
{
|
261
|
+
series: 'gpu',
|
262
|
+
values: {value: 0.9999},
|
263
|
+
}
|
264
|
+
]
|
265
|
+
|
266
|
+
influxdb.write_points(data)
|
267
|
+
|
268
|
+
# you can also specify precision in method call
|
269
|
+
|
270
|
+
precision = 'm'
|
271
|
+
influxdb.write_points(data, precision)
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
Write asynchronously:
|
132
276
|
|
133
277
|
``` ruby
|
134
278
|
require 'influxdb'
|
@@ -139,14 +283,18 @@ database = 'site_development'
|
|
139
283
|
name = 'foobar'
|
140
284
|
time_precision = 's'
|
141
285
|
|
142
|
-
influxdb = InfluxDB::Client.new database,
|
286
|
+
influxdb = InfluxDB::Client.new database,
|
287
|
+
username: username,
|
288
|
+
password: password,
|
289
|
+
async: true
|
143
290
|
|
144
291
|
data = {
|
145
|
-
:value
|
146
|
-
:
|
292
|
+
values: { value: 0 },
|
293
|
+
tags: { foo: 'bar', bar: 'baz' }
|
294
|
+
timestamp: Time.now.to_i
|
147
295
|
}
|
148
296
|
|
149
|
-
influxdb.write_point(name, data
|
297
|
+
influxdb.write_point(name, data)
|
150
298
|
```
|
151
299
|
|
152
300
|
Write data via UDP:
|
@@ -156,98 +304,66 @@ require 'influxdb'
|
|
156
304
|
host = '127.0.0.1'
|
157
305
|
port = 4444
|
158
306
|
|
159
|
-
influxdb = InfluxDB::Client.new :
|
307
|
+
influxdb = InfluxDB::Client.new udp: { host: host, port: port }
|
160
308
|
|
161
309
|
name = 'hitchhiker'
|
162
310
|
|
163
311
|
data = {
|
164
|
-
:
|
165
|
-
:
|
312
|
+
values: { value: 666 },
|
313
|
+
tags: { foo: 'bar', bar: 'baz' }
|
166
314
|
}
|
167
315
|
|
168
316
|
influxdb.write_point(name, data)
|
169
317
|
```
|
170
318
|
|
171
|
-
|
172
|
-
List cluster admins:
|
173
|
-
|
174
|
-
``` ruby
|
175
|
-
require 'influxdb'
|
176
|
-
|
177
|
-
influxdb = InfluxDB::Client.new
|
178
|
-
|
179
|
-
influxdb.get_cluster_admin_list
|
180
|
-
```
|
181
|
-
|
182
|
-
List databases:
|
183
|
-
|
184
|
-
``` ruby
|
185
|
-
require 'influxdb'
|
186
|
-
|
187
|
-
influxdb = InfluxDB::Client.new
|
188
|
-
|
189
|
-
influxdb.get_database_list
|
190
|
-
```
|
191
|
-
|
192
|
-
List database users:
|
193
|
-
|
194
|
-
``` ruby
|
195
|
-
require 'influxdb'
|
196
|
-
|
197
|
-
influxdb = InfluxDB::Client.new
|
198
|
-
|
199
|
-
influxdb.get_database_user_list(database)
|
200
|
-
```
|
201
|
-
|
202
|
-
List a database user:
|
203
|
-
|
204
|
-
``` ruby
|
205
|
-
require 'influxdb'
|
206
|
-
|
207
|
-
influxdb = InfluxDB::Client.new
|
208
|
-
|
209
|
-
influxdb.get_database_user_info(database, username)
|
210
|
-
```
|
211
|
-
|
212
|
-
Delete a database:
|
319
|
+
Querying:
|
213
320
|
|
214
321
|
``` ruby
|
215
|
-
|
216
|
-
|
217
|
-
influxdb = InfluxDB::Client.new
|
218
|
-
|
322
|
+
username = 'foo'
|
323
|
+
password = 'bar'
|
219
324
|
database = 'site_development'
|
220
|
-
influxdb.delete_database(database)
|
221
|
-
```
|
222
325
|
|
223
|
-
|
326
|
+
influxdb = InfluxDB::Client.new database,
|
327
|
+
username: username,
|
328
|
+
password: password
|
224
329
|
|
225
|
-
|
226
|
-
|
330
|
+
# without a block:
|
331
|
+
influxdb.query 'select * from time_series_1' # results are grouped by name, but also their tags
|
332
|
+
|
333
|
+
# result:
|
334
|
+
[{"name"=>"time_series_1", "tags"=>{"region"=>"uk"}, "values"=>[{"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}, {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}]},
|
335
|
+
{"name"=>"time_series_1", "tags"=>{"region"=>"us"}, "values"=>[{"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}]}]
|
227
336
|
|
228
|
-
|
337
|
+
# with a block:
|
338
|
+
influxdb.query 'select * from time_series_1' do |name, tags, points|
|
339
|
+
puts "#{name} [ #{tags} ] => #{points}"
|
340
|
+
end
|
229
341
|
|
230
|
-
|
342
|
+
# result:
|
343
|
+
# time_series_1 [ {"region"=>"uk"} ] => [{"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}, {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}]
|
344
|
+
# time_series_1 [ {"region"=>"us"} ] => [{"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}]
|
231
345
|
```
|
232
346
|
|
233
|
-
|
347
|
+
By default, InfluxDB::Client will denormalize points (received from InfluxDB as columns and rows), if you want to get _raw_ data add `denormalize: false` to initialization options or to query itself:
|
234
348
|
|
235
349
|
``` ruby
|
236
|
-
|
350
|
+
influxdb.query 'select * from time_series_1', denormalize: false
|
237
351
|
|
238
|
-
|
239
|
-
|
240
|
-
|
352
|
+
# result
|
353
|
+
[{"name"=>"time_series_1", "tags"=>{"region"=>"uk"}, "columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]},
|
354
|
+
{"name"=>"time_series_1", "tags"=>{"region"=>"us"}, "columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}]
|
241
355
|
|
242
|
-
influxdb = InfluxDB::Client.new database, :username => username, :password => password
|
243
356
|
|
244
|
-
influxdb.query 'select * from time_series_1' do |name, points|
|
245
|
-
puts "#{name} => #{points}"
|
357
|
+
influxdb.query 'select * from time_series_1', denormalize: false do |name, tags, points|
|
358
|
+
puts "#{name} [ #{tags} ] => #{points}"
|
246
359
|
end
|
360
|
+
|
361
|
+
# result:
|
362
|
+
# time_series_1 [ {"region"=>"uk"} ] => {"columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]}
|
363
|
+
# time_series_1 [ {"region"=>"us"} ] => {"columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}
|
247
364
|
```
|
248
365
|
|
249
|
-
By default,
|
250
|
-
it gets connection denied, if you want to retry a finite number of times
|
366
|
+
By default, InfluxDB::Client will keep trying to connect to the database when it gets connection denied, if you want to retry a finite number of times
|
251
367
|
(or disable retries altogether), you should pass the `:retry`
|
252
368
|
value. `:retry` can be either `true`, `false` or an `Integer` to retry
|
253
369
|
infinite times, disable retries or retry a finite number of times,
|