efigence-influxdb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +41 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +362 -0
  8. data/Rakefile +22 -0
  9. data/efigence-influxdb.gemspec +28 -0
  10. data/lib/influxdb.rb +21 -0
  11. data/lib/influxdb/client.rb +77 -0
  12. data/lib/influxdb/client/http.rb +98 -0
  13. data/lib/influxdb/config.rb +60 -0
  14. data/lib/influxdb/errors.rb +40 -0
  15. data/lib/influxdb/logging.rb +22 -0
  16. data/lib/influxdb/max_queue.rb +18 -0
  17. data/lib/influxdb/point_value.rb +31 -0
  18. data/lib/influxdb/query/cluster.rb +17 -0
  19. data/lib/influxdb/query/continuous_query.rb +36 -0
  20. data/lib/influxdb/query/core.rb +109 -0
  21. data/lib/influxdb/query/database.rb +21 -0
  22. data/lib/influxdb/query/series.rb +13 -0
  23. data/lib/influxdb/query/shard.rb +14 -0
  24. data/lib/influxdb/query/shard_space.rb +60 -0
  25. data/lib/influxdb/query/user.rb +38 -0
  26. data/lib/influxdb/version.rb +3 -0
  27. data/lib/influxdb/writer/async.rb +115 -0
  28. data/lib/influxdb/writer/udp.rb +21 -0
  29. data/spec/influxdb/cases/async_client_spec.rb +33 -0
  30. data/spec/influxdb/cases/query_cluster_spec.rb +65 -0
  31. data/spec/influxdb/cases/query_database_spec.rb +58 -0
  32. data/spec/influxdb/cases/query_series_spec.rb +50 -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 +159 -0
  36. data/spec/influxdb/cases/retry_requests_spec.rb +97 -0
  37. data/spec/influxdb/cases/udp_client_spec.rb +21 -0
  38. data/spec/influxdb/cases/write_points_spec.rb +141 -0
  39. data/spec/influxdb/client_spec.rb +58 -0
  40. data/spec/influxdb/config_spec.rb +118 -0
  41. data/spec/influxdb/logging_spec.rb +48 -0
  42. data/spec/influxdb/max_queue_spec.rb +29 -0
  43. data/spec/influxdb/point_value_spec.rb +66 -0
  44. data/spec/influxdb/worker_spec.rb +23 -0
  45. data/spec/spec_helper.rb +8 -0
  46. metadata +192 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b529434d3ed5510a7f29735a457bf34c05b5b4bd
4
+ data.tar.gz: 4858891f7501ee7fd7cf41f5d85ab4ac6a6b2296
5
+ SHA512:
6
+ metadata.gz: 85eda83459f2a4f221994bd48d9b4f8d24edb24c5421322195765f48190ee6de07c75e9047576e1628782a4a1bc50681cce74b4c6498c7a9d94eb36ba7d75ed4
7
+ data.tar.gz: ec9a6468caf2e85825137da33311288c0b319c6a86b80c23aac5e03c49934165473d3462a4257c4b000edcb3c43eaa2819a82600b24e22d925f87fe6e2c9c71f
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ Gemfile.lock
15
+ .rvmrc
16
+ .ruby-version
17
+
18
+ # YARD artifacts
19
+ .yardoc
20
+ _yardoc
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'
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - 2.2.0
8
+ - ruby-head
9
+ - jruby-20mode
10
+ - jruby-21mode
11
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
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
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Todd Persen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,362 @@
1
+ influxdb-ruby
2
+ =============
3
+
4
+ [![Build Status](https://travis-ci.org/influxdb/influxdb-ruby.png?branch=master)](https://travis-ci.org/influxdb/influxdb-ruby)
5
+
6
+ The official ruby client library for [InfluxDB](https://influxdb.com/).
7
+
8
+ Install
9
+ -------
10
+
11
+ ```
12
+ $ [sudo] gem install influxdb
13
+ ```
14
+
15
+ Or add it to your `Gemfile`, etc.
16
+
17
+ Usage
18
+ -----
19
+
20
+ Connecting to a single host:
21
+
22
+ ``` ruby
23
+ require 'influxdb'
24
+
25
+ influxdb = InfluxDB::Client.new host: "influxdb.domain.com"
26
+ # or
27
+ influxdb = InfluxDB::Client.new # no host given defaults connecting to localhost
28
+ ```
29
+
30
+ Connecting to multiple hosts (with built-in load balancing and failover):
31
+
32
+ ``` ruby
33
+ require 'influxdb'
34
+
35
+ influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domain.com"]
36
+ ```
37
+
38
+ Create a database:
39
+
40
+ ``` ruby
41
+ database = 'site_development'
42
+
43
+ influxdb.create_database(database)
44
+ ```
45
+
46
+ Delete a database:
47
+
48
+ ``` ruby
49
+ database = 'site_development'
50
+
51
+ influxdb.delete_database(database)
52
+ ```
53
+
54
+ List databases:
55
+
56
+ ``` ruby
57
+ influxdb.list_databases
58
+ ```
59
+
60
+ Create a user for a database:
61
+
62
+ ``` ruby
63
+ database = 'site_development'
64
+ new_username = 'foo'
65
+ new_password = 'bar'
66
+ permission = :write
67
+
68
+ # with all permissions
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)
73
+ ```
74
+
75
+ Update a user password:
76
+
77
+ ``` ruby
78
+ username = 'foo'
79
+ new_password = 'bar'
80
+
81
+ influxdb.update_user_password(username, new_password)
82
+ ```
83
+
84
+ Grant user privileges on database:
85
+
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)
92
+ ```
93
+
94
+ Revoke user privileges from database:
95
+
96
+ ``` ruby
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.continuous_queries(database)
146
+ ```
147
+
148
+ Write some data:
149
+
150
+ ``` ruby
151
+ username = 'foo'
152
+ password = 'bar'
153
+ database = 'site_development'
154
+ name = 'foobar'
155
+
156
+ influxdb = InfluxDB::Client.new database,
157
+ username: username,
158
+ password: password
159
+
160
+ # Enumerator that emits a sine wave
161
+ Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each
162
+
163
+ loop do
164
+ data = {
165
+ values: { value: Value.next },
166
+ tags: { wave: 'sine' } # tags are optional
167
+ }
168
+
169
+ influxdb.write_point(name, data)
170
+
171
+ sleep 1
172
+ end
173
+ ```
174
+
175
+ Write data with time precision (precision can be set in 2 ways):
176
+
177
+ ``` ruby
178
+ require 'influxdb'
179
+
180
+ username = 'foo'
181
+ password = 'bar'
182
+ database = 'site_development'
183
+ name = 'foobar'
184
+ time_precision = 's'
185
+
186
+ # either in the client initialization:
187
+ influxdb = InfluxDB::Client.new database, username: username,
188
+ password: password,
189
+ time_precision: time_precision
190
+
191
+ data = {
192
+ values: { value: 0 },
193
+ timestamp: Time.now.to_i # timestamp is optional, if not provided point will be saved with current time
194
+ }
195
+
196
+ influxdb.write_point(name, data)
197
+
198
+ # or in a method call:
199
+ influxdb.write_point(name, data, time_precision)
200
+
201
+ ```
202
+
203
+ Write multiple points in a batch (performance boost):
204
+
205
+ ``` ruby
206
+
207
+ data = [
208
+ {
209
+ series: 'cpu',
210
+ tags: { host: 'server_1', regios: 'us' },
211
+ values: {internal: 5, external: 0.453345}
212
+ },
213
+ {
214
+ series: 'gpu',
215
+ values: {value: 0.9999},
216
+ }
217
+ ]
218
+
219
+ influxdb.write_points(data)
220
+
221
+ # you can also specify precision in method call
222
+
223
+ precision = 'm'
224
+ influxdb.write_points(data, precision)
225
+
226
+ ```
227
+
228
+ Write asynchronously:
229
+
230
+ ``` ruby
231
+ require 'influxdb'
232
+
233
+ username = 'foo'
234
+ password = 'bar'
235
+ database = 'site_development'
236
+ name = 'foobar'
237
+ time_precision = 's'
238
+
239
+ influxdb = InfluxDB::Client.new database,
240
+ username: username,
241
+ password: password,
242
+ async: true
243
+
244
+ data = {
245
+ values: { value: 0 },
246
+ tags: { foo: 'bar', bar: 'baz' }
247
+ timestamp: Time.now.to_i
248
+ }
249
+
250
+ influxdb.write_point(name, data)
251
+ ```
252
+
253
+ Write data via UDP:
254
+
255
+ ``` ruby
256
+ require 'influxdb'
257
+ host = '127.0.0.1'
258
+ port = 4444
259
+
260
+ influxdb = InfluxDB::Client.new udp: { host: host, port: port }
261
+
262
+ name = 'hitchhiker'
263
+
264
+ data = {
265
+ values: { value: 666 },
266
+ tags: { foo: 'bar', bar: 'baz' }
267
+ }
268
+
269
+ influxdb.write_point(name, data)
270
+ ```
271
+
272
+ Querying:
273
+
274
+ ``` ruby
275
+ username = 'foo'
276
+ password = 'bar'
277
+ database = 'site_development'
278
+
279
+ influxdb = InfluxDB::Client.new database,
280
+ username: username,
281
+ password: password
282
+
283
+ # without a block:
284
+ influxdb.query 'select * from time_series_1' # results are grouped by name, but also their tags
285
+
286
+ # result:
287
+ [{"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}]},
288
+ {"name"=>"time_series_1", "tags"=>{"region"=>"us"}, "values"=>[{"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}]}]
289
+
290
+ # with a block:
291
+ influxdb.query 'select * from time_series_1' do |name, tags, points|
292
+ puts "#{name} [ #{tags} ] => #{points}"
293
+ end
294
+
295
+ # result:
296
+ # 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}]
297
+ # time_series_1 [ {"region"=>"us"} ] => [{"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}]
298
+ ```
299
+
300
+ 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:
301
+
302
+ ``` ruby
303
+ influxdb.query 'select * from time_series_1', denormalize: false
304
+
305
+ # result
306
+ [{"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]]},
307
+ {"name"=>"time_series_1", "tags"=>{"region"=>"us"}, "columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}]
308
+
309
+
310
+ influxdb.query 'select * from time_series_1', denormalize: false do |name, tags, points|
311
+ puts "#{name} [ #{tags} ] => #{points}"
312
+ end
313
+
314
+ # result:
315
+ # 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]]}
316
+ # time_series_1 [ {"region"=>"us"} ] => {"columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}
317
+ ```
318
+
319
+ 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
320
+ (or disable retries altogether), you should pass the `:retry`
321
+ value. `:retry` can be either `true`, `false` or an `Integer` to retry
322
+ infinite times, disable retries or retry a finite number of times,
323
+ respectively. `0` is equivalent to `false`
324
+
325
+ ```
326
+ > require 'influxdb'
327
+ => true
328
+
329
+ > influxdb = InfluxDB::Client.new 'database', :retry => 4
330
+ => #<InfluxDB::Client:0x00000002bb5ce0 @database="database", @hosts=["localhost"],
331
+ @port=8086, @username="root", @password="root", @use_ssl=false,
332
+ @time_precision="s", @initial_delay=0.01, @max_delay=30,
333
+ @open_timeout=5, @read_timeout=300, @async=false, @retry=4>
334
+
335
+ > influxdb.query 'select * from serie limit 1'
336
+ E, [2014-06-02T11:04:13.416209 #22825] ERROR -- : [InfluxDB] Failed to
337
+ contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
338
+ retrying in 0.01s.
339
+ E, [2014-06-02T11:04:13.433646 #22825] ERROR -- : [InfluxDB] Failed to
340
+ contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
341
+ retrying in 0.02s.
342
+ E, [2014-06-02T11:04:13.462566 #22825] ERROR -- : [InfluxDB] Failed to
343
+ contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
344
+ retrying in 0.04s.
345
+ E, [2014-06-02T11:04:13.510853 #22825] ERROR -- : [InfluxDB] Failed to
346
+ contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
347
+ retrying in 0.08s.
348
+ SocketError: Tried 4 times to reconnect but failed.
349
+
350
+ ```
351
+ If you pass `:retry => -1` it will keep trying forever
352
+ until it gets the connection.
353
+
354
+ Testing
355
+ -------
356
+
357
+ ```
358
+ git clone git@github.com:influxdb/influxdb-ruby.git
359
+ cd influxdb-ruby
360
+ bundle
361
+ bundle exec rake
362
+ ```