influxdb 0.3.12 → 0.3.13
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/CHANGELOG.md +7 -0
- data/README.md +38 -6
- data/lib/influxdb/query/core.rb +14 -8
- data/lib/influxdb/version.rb +1 -1
- data/lib/influxdb/writer/async.rb +1 -1
- data/lib/influxdb/writer/udp.rb +1 -1
- data/spec/influxdb/cases/querying_spec.rb +19 -0
- data/spec/influxdb/cases/write_points_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01adedbe7674717e14ed72845cfff4e156f2689a
|
4
|
+
data.tar.gz: ceefc5493edfa1144ec139d2dc07dc0ae5fe1db4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b86ea8d1c86d8f90e5d11bca3654d7e4462071a126ecbc2bf737514538235da8e0e91836fc12b290c5d8a5c968a5b14a7d1f5308743157762c0796d505b8c52a
|
7
|
+
data.tar.gz: 7564b0e19b8e80eb82734054481371459900608324a3d5d844f16680867f3cddf581c4d35e23ed98a1451acd2757465e26884807f28c0e3f63fa21e478b3ebb8
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/
|
|
6
6
|
|
7
7
|
- None.
|
8
8
|
|
9
|
+
## v0.3.13, released 2016-11-23
|
10
|
+
|
11
|
+
- You can now `InfluxDB::Client#query`, `#write_points`, `#write_point` and
|
12
|
+
`#write` now accept an additional parameter to override the database on
|
13
|
+
invokation time (#173, #176, @jfragoulis).
|
14
|
+
|
15
|
+
|
9
16
|
## v0.3.12, released 2016-11-15
|
10
17
|
|
11
18
|
- Bugfix for broken Unicode support (regression introduced in #169).
|
data/README.md
CHANGED
@@ -334,6 +334,32 @@ data = {
|
|
334
334
|
influxdb.write_point(name, data, precision, retention)
|
335
335
|
```
|
336
336
|
|
337
|
+
Write data while choosing the database:
|
338
|
+
|
339
|
+
``` ruby
|
340
|
+
require 'influxdb'
|
341
|
+
|
342
|
+
username = 'foo'
|
343
|
+
password = 'bar'
|
344
|
+
database = 'site_development'
|
345
|
+
name = 'foobar'
|
346
|
+
precision = 's'
|
347
|
+
retention = '1h.cpu'
|
348
|
+
|
349
|
+
influxdb = InfluxDB::Client.new {
|
350
|
+
username: username,
|
351
|
+
password: password
|
352
|
+
}
|
353
|
+
|
354
|
+
data = {
|
355
|
+
values: { value: 0 },
|
356
|
+
tags: { foo: 'bar', bar: 'baz' }
|
357
|
+
timestamp: Time.now.to_i
|
358
|
+
}
|
359
|
+
|
360
|
+
influxdb.write_point(name, data, precision, retention, database)
|
361
|
+
```
|
362
|
+
|
337
363
|
Write multiple points in a batch (performance boost):
|
338
364
|
|
339
365
|
``` ruby
|
@@ -458,7 +484,7 @@ influxdb = InfluxDB::Client.new database,
|
|
458
484
|
password: password
|
459
485
|
|
460
486
|
# without a block:
|
461
|
-
influxdb.query 'select * from time_series_1'
|
487
|
+
influxdb.query 'select * from time_series_1 group by region'
|
462
488
|
|
463
489
|
# results are grouped by name, but also their tags:
|
464
490
|
#
|
@@ -481,7 +507,7 @@ influxdb.query 'select * from time_series_1'
|
|
481
507
|
# ]
|
482
508
|
|
483
509
|
# with a block:
|
484
|
-
influxdb.query 'select * from time_series_1' do |name, tags, points|
|
510
|
+
influxdb.query 'select * from time_series_1 group by region' do |name, tags, points|
|
485
511
|
puts "#{name} [ #{tags.inspect} ]"
|
486
512
|
points.each do |pt|
|
487
513
|
puts " -> #{pt.inspect}"
|
@@ -503,7 +529,7 @@ If you would rather receive points with integer timestamp, it's possible to set
|
|
503
529
|
# globally, on client initialization:
|
504
530
|
influxdb = InfluxDB::Client.new database, epoch: 's'
|
505
531
|
|
506
|
-
influxdb.query 'select * from time_series'
|
532
|
+
influxdb.query 'select * from time_series group by region'
|
507
533
|
# [
|
508
534
|
# {
|
509
535
|
# "name"=>"time_series",
|
@@ -515,7 +541,7 @@ influxdb.query 'select * from time_series'
|
|
515
541
|
# ]
|
516
542
|
|
517
543
|
# or for a specific query call:
|
518
|
-
influxdb.query 'select * from time_series', epoch: 'ms'
|
544
|
+
influxdb.query 'select * from time_series group by region', epoch: 'ms'
|
519
545
|
# [
|
520
546
|
# {
|
521
547
|
# "name"=>"time_series",
|
@@ -551,7 +577,7 @@ columns and rows). If you want to get *raw* data add `denormalize: false` to
|
|
551
577
|
the initialization options or to query itself:
|
552
578
|
|
553
579
|
``` ruby
|
554
|
-
influxdb.query 'select * from time_series_1', denormalize: false
|
580
|
+
influxdb.query 'select * from time_series_1 group by region', denormalize: false
|
555
581
|
|
556
582
|
# [
|
557
583
|
# {
|
@@ -574,7 +600,7 @@ influxdb.query 'select * from time_series_1', denormalize: false
|
|
574
600
|
# ]
|
575
601
|
|
576
602
|
|
577
|
-
influxdb.query 'select * from time_series_1', denormalize: false do |name, tags, points|
|
603
|
+
influxdb.query 'select * from time_series_1 group by region', denormalize: false do |name, tags, points|
|
578
604
|
puts "#{name} [ #{tags.inspect} ]"
|
579
605
|
points.each do |key, values|
|
580
606
|
puts " #{key.inspect} -> #{values.inspect}"
|
@@ -590,6 +616,12 @@ end
|
|
590
616
|
# values -> [["2015-07-09T09:02:54Z", 55, 0.4343]]}
|
591
617
|
```
|
592
618
|
|
619
|
+
You can also pick the database to query from:
|
620
|
+
|
621
|
+
```
|
622
|
+
influxdb.query 'select * from time_series_1', database: 'database'
|
623
|
+
```
|
624
|
+
|
593
625
|
#### Streaming response
|
594
626
|
|
595
627
|
If you expect large quantities of data in a response, you may want to enable
|
data/lib/influxdb/query/core.rb
CHANGED
@@ -51,21 +51,24 @@ module InfluxDB
|
|
51
51
|
# values: {value: 0.9999},
|
52
52
|
# }
|
53
53
|
# ])
|
54
|
-
def write_points(data, precision = nil, retention_policy = nil)
|
54
|
+
def write_points(data, precision = nil, retention_policy = nil, database = nil)
|
55
55
|
data = data.is_a?(Array) ? data : [data]
|
56
56
|
payload = generate_payload(data)
|
57
|
-
writer.write(payload, precision, retention_policy)
|
57
|
+
writer.write(payload, precision, retention_policy, database)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Example:
|
61
61
|
# write_point('cpu', tags: {region: 'us'}, values: {internal: 60})
|
62
|
-
def write_point(series, data, precision = nil, retention_policy = nil)
|
63
|
-
write_points(data.merge(series: series), precision, retention_policy)
|
62
|
+
def write_point(series, data, precision = nil, retention_policy = nil, database = nil)
|
63
|
+
write_points(data.merge(series: series), precision, retention_policy, database)
|
64
64
|
end
|
65
65
|
|
66
|
-
def write(data, precision, retention_policy = nil)
|
67
|
-
|
68
|
-
|
66
|
+
def write(data, precision, retention_policy = nil, database = nil)
|
67
|
+
params = {
|
68
|
+
db: database || config.database,
|
69
|
+
precision: precision || config.time_precision
|
70
|
+
}
|
71
|
+
|
69
72
|
params[:rp] = retention_policy if retention_policy
|
70
73
|
url = full_url("/write", params)
|
71
74
|
post(url, data)
|
@@ -73,12 +76,14 @@ module InfluxDB
|
|
73
76
|
|
74
77
|
private
|
75
78
|
|
79
|
+
# rubocop:disable Metrics/MethodLength
|
76
80
|
def query_params(query, opts)
|
77
81
|
precision = opts.fetch(:precision, config.time_precision)
|
78
82
|
epoch = opts.fetch(:epoch, config.epoch)
|
79
83
|
chunk_size = opts.fetch(:chunk_size, config.chunk_size)
|
84
|
+
database = opts.fetch(:database, config.database)
|
80
85
|
|
81
|
-
params = { q: query, db:
|
86
|
+
params = { q: query, db: database, precision: precision }
|
82
87
|
params[:epoch] = epoch if epoch
|
83
88
|
|
84
89
|
if chunk_size
|
@@ -88,6 +93,7 @@ module InfluxDB
|
|
88
93
|
|
89
94
|
params
|
90
95
|
end
|
96
|
+
# rubocop:enable Metrics/MethodLength
|
91
97
|
|
92
98
|
def denormalized_series_list(series)
|
93
99
|
series.map do |s|
|
data/lib/influxdb/version.rb
CHANGED
@@ -12,7 +12,7 @@ module InfluxDB
|
|
12
12
|
@config = config
|
13
13
|
end
|
14
14
|
|
15
|
-
def write(data, _precision = nil, _retention_policy = nil)
|
15
|
+
def write(data, _precision = nil, _retention_policy = nil, _database = nil)
|
16
16
|
data = data.is_a?(Array) ? data : [data]
|
17
17
|
data.map { |p| worker.push(p) }
|
18
18
|
end
|
data/lib/influxdb/writer/udp.rb
CHANGED
@@ -159,6 +159,25 @@ describe InfluxDB::Client do
|
|
159
159
|
expect(subject.query(query)).to eq(expected_result)
|
160
160
|
end
|
161
161
|
end
|
162
|
+
|
163
|
+
context "with database" do
|
164
|
+
let(:extra_params) { { db: 'overriden_db' } }
|
165
|
+
let(:response) do
|
166
|
+
{ "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" },
|
167
|
+
"columns" => %w(time temp value),
|
168
|
+
"values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
|
169
|
+
end
|
170
|
+
let(:expected_result) do
|
171
|
+
[{ "name" => "cpu", "tags" => { "region" => "us" },
|
172
|
+
"values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 },
|
173
|
+
{ "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] }]
|
174
|
+
end
|
175
|
+
let(:query) { 'SELECT * FROM cpu' }
|
176
|
+
|
177
|
+
it "should return array with single hash containing multiple values" do
|
178
|
+
expect(subject.query(query, database: 'overriden_db')).to eq(expected_result)
|
179
|
+
end
|
180
|
+
end
|
162
181
|
end
|
163
182
|
|
164
183
|
describe "multiple select queries" do
|
@@ -154,5 +154,31 @@ describe InfluxDB::Client do
|
|
154
154
|
expect(subject.write_points(data, nil, 'rp_1_hour')).to be_a(Net::HTTPNoContent)
|
155
155
|
end
|
156
156
|
end
|
157
|
+
|
158
|
+
context "with database" do
|
159
|
+
let(:data) do
|
160
|
+
[{ series: 'cpu',
|
161
|
+
values: { temp: 88, value: 54 } },
|
162
|
+
{ series: 'gpu',
|
163
|
+
values: { value: 0.5435345 } }]
|
164
|
+
end
|
165
|
+
|
166
|
+
let(:body) do
|
167
|
+
data.map do |point|
|
168
|
+
InfluxDB::PointValue.new(point).dump
|
169
|
+
end.join("\n")
|
170
|
+
end
|
171
|
+
|
172
|
+
before do
|
173
|
+
stub_request(:post, "http://influxdb.test:9999/write").with(
|
174
|
+
query: { u: "username", p: "password", precision: 's', db: 'overriden_db' },
|
175
|
+
headers: { "Content-Type" => "application/octet-stream" },
|
176
|
+
body: body
|
177
|
+
).to_return(status: 204)
|
178
|
+
end
|
179
|
+
it "should POST multiple points" do
|
180
|
+
expect(subject.write_points(data, nil, nil, 'overriden_db')).to be_a(Net::HTTPNoContent)
|
181
|
+
end
|
182
|
+
end
|
157
183
|
end
|
158
184
|
end
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|