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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +41 -0
  4. data/.travis.yml +3 -2
  5. data/Gemfile +7 -1
  6. data/README.md +218 -102
  7. data/Rakefile +2 -6
  8. data/lib/influxdb.rb +15 -5
  9. data/lib/influxdb/client.rb +38 -433
  10. data/lib/influxdb/client/http.rb +123 -0
  11. data/lib/influxdb/config.rb +66 -0
  12. data/lib/influxdb/errors.rb +8 -2
  13. data/lib/influxdb/{logger.rb → logging.rb} +6 -5
  14. data/lib/influxdb/max_queue.rb +2 -1
  15. data/lib/influxdb/point_value.rb +27 -25
  16. data/lib/influxdb/query/cluster.rb +17 -0
  17. data/lib/influxdb/query/continuous_query.rb +22 -0
  18. data/lib/influxdb/query/core.rb +110 -0
  19. data/lib/influxdb/query/database.rb +21 -0
  20. data/lib/influxdb/query/retention_policy.rb +26 -0
  21. data/lib/influxdb/query/user.rb +41 -0
  22. data/lib/influxdb/version.rb +2 -2
  23. data/lib/influxdb/writer/async.rb +115 -0
  24. data/lib/influxdb/writer/udp.rb +21 -0
  25. data/spec/influxdb/cases/async_client_spec.rb +33 -0
  26. data/spec/influxdb/cases/query_cluster_spec.rb +65 -0
  27. data/spec/influxdb/cases/query_continuous_query_spec.rb +82 -0
  28. data/spec/influxdb/cases/query_core.rb +34 -0
  29. data/spec/influxdb/cases/query_database_spec.rb +58 -0
  30. data/spec/influxdb/cases/query_retention_policy_spec.rb +84 -0
  31. data/spec/influxdb/cases/query_series_spec.rb +50 -0
  32. data/spec/influxdb/cases/query_shard_space_spec.rb +105 -0
  33. data/spec/influxdb/cases/query_shard_spec.rb +43 -0
  34. data/spec/influxdb/cases/query_user_spec.rb +127 -0
  35. data/spec/influxdb/cases/querying_spec.rb +149 -0
  36. data/spec/influxdb/cases/retry_requests_spec.rb +102 -0
  37. data/spec/influxdb/cases/udp_client_spec.rb +21 -0
  38. data/spec/influxdb/cases/write_points_spec.rb +140 -0
  39. data/spec/influxdb/client_spec.rb +37 -810
  40. data/spec/influxdb/config_spec.rb +118 -0
  41. data/spec/influxdb/{logger_spec.rb → logging_spec.rb} +4 -8
  42. data/spec/influxdb/max_queue_spec.rb +29 -0
  43. data/spec/influxdb/point_value_spec.rb +81 -14
  44. data/spec/influxdb/worker_spec.rb +8 -11
  45. data/spec/spec_helper.rb +7 -10
  46. metadata +65 -30
  47. data/lib/influxdb/udp_client.rb +0 -16
  48. data/lib/influxdb/worker.rb +0 -80
  49. data/spec/influxdb/udp_client_spec.rb +0 -33
  50. data/spec/influxdb_spec.rb +0 -4
  51. data/spec/max_queue_spec.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79714dbe624e4485dfefc69e334b3234daf4c5c6
4
- data.tar.gz: 8a36045de479f5406d65b332c191edb3cfe327bb
3
+ metadata.gz: 5122c2a56a46565d1ee7481c6d20e1647035e94d
4
+ data.tar.gz: e4c1e752d0d49a5d3749e92f6c1afd1fbc269549
5
5
  SHA512:
6
- metadata.gz: f29ae07c03cd04314bfc82af8510334c7a6e829a33ef1eaa1a7d8a5be802bf53883bab852075d64b3fd142b319e7ea9ecfb5a4f447671bd5629af0be4087dda3
7
- data.tar.gz: 478b0d0002b481bed502b6682f795bad4a61f69eaa4c459dacc9f8050023ba1ed78d15bd27187914d0c6b6d2ea0b6e6989945f5b399f97c0ffefb0596e2d9514
6
+ metadata.gz: d4053245ecd16e82ee75055a407099a4ab44740722abc225d2a27fa1c3c562f6b703c07dae3322f523ec4cb3181ec69c991c17d2b8842af58970df10a343f717
7
+ data.tar.gz: adcf58659107dfc6ef3c99a4628c33662cbabc2782e06eb47cdfa90e345c2946d2e56af2e5849641221b5971cfad8ebc83d2cae4149a6a5bd778fe21270f6211
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ Gemfile.lock
19
19
  .yardoc
20
20
  _yardoc
21
21
  doc/
22
+ *.local
@@ -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'
@@ -2,9 +2,10 @@ language: ruby
2
2
  before_install:
3
3
  - gem update bundler
4
4
  rvm:
5
- - 1.9.3
6
5
  - 2.0.0
7
6
  - 2.1.0
8
7
  - 2.2.0
9
8
  - ruby-head
10
- - jruby
9
+ - jruby-20mode
10
+ - jruby-21mode
11
+ - jruby-head
data/Gemfile CHANGED
@@ -2,4 +2,10 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "webmock", :git => "https://github.com/influxdb/webmock.git"
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
  [![Build Status](https://travis-ci.org/influxdb/influxdb-ruby.png?branch=master)](https://travis-ci.org/influxdb/influxdb-ruby)
13
5
 
14
- Ruby client library for [InfluxDB](http://influxdb.org/).
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
- require 'influxdb'
41
+ database = 'site_development'
42
+
43
+ influxdb.create_database(database)
44
+ ```
50
45
 
51
- influxdb = InfluxDB::Client.new
46
+ Delete a database:
52
47
 
48
+ ``` ruby
53
49
  database = 'site_development'
54
50
 
55
- influxdb.create_database(database)
51
+ influxdb.delete_database(database)
56
52
  ```
57
53
 
58
- Create a user for a database:
54
+ List databases:
59
55
 
60
56
  ``` ruby
61
- require 'influxdb'
57
+ influxdb.list_databases
58
+ ```
62
59
 
63
- influxdb = InfluxDB::Client.new
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 database user:
75
+ Update a user password:
72
76
 
73
77
  ``` ruby
74
- require 'influxdb'
78
+ username = 'foo'
79
+ new_password = 'bar'
75
80
 
76
- influxdb = InfluxDB::Client.new
81
+ influxdb.update_user_password(username, new_password)
82
+ ```
83
+
84
+ Grant user privileges on database:
77
85
 
78
- influxdb.update_database_user(database, username, :password => "new_password")
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
- Write some data:
94
+ Revoke user privileges from database:
82
95
 
83
96
  ``` ruby
84
- require 'influxdb'
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, :username => username, :password => password
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 => Value.next
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
- influxdb = InfluxDB::Client.new database, :username => username,
121
- :password => password,
122
- :time_precision => time_precision
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 => 0,
126
- :time => Time.now.to_i
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
- or in the write call
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, :username => username, :password => password
286
+ influxdb = InfluxDB::Client.new database,
287
+ username: username,
288
+ password: password,
289
+ async: true
143
290
 
144
291
  data = {
145
- :value => 0,
146
- :time => Time.now.to_i
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, false, time_precision)
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 :udp => { :host => host, :port => port }
307
+ influxdb = InfluxDB::Client.new udp: { host: host, port: port }
160
308
 
161
309
  name = 'hitchhiker'
162
310
 
163
311
  data = {
164
- :answer => 42,
165
- :question => "life the universe and everything?"
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
- require 'influxdb'
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
- Delete a database user:
326
+ influxdb = InfluxDB::Client.new database,
327
+ username: username,
328
+ password: password
224
329
 
225
- ``` ruby
226
- require 'influxdb'
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
- influxdb = InfluxDB::Client.new
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
- influxdb.delete_database_user(database, username)
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
- Querying:
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
- require 'influxdb'
350
+ influxdb.query 'select * from time_series_1', denormalize: false
237
351
 
238
- username = 'foo'
239
- password = 'bar'
240
- database = 'site_development'
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, an InfluxDB::Client will keep trying to connect to the database when
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,