influxdb 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/lib/influxdb/client.rb +14 -6
- data/lib/influxdb/version.rb +1 -1
- data/spec/influxdb/client_spec.rb +19 -8
- data/spec/influxdb/logger_spec.rb +29 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d70a9878bd1e5c317027674416232aa8a04ae7d
|
4
|
+
data.tar.gz: 04aa90bf5904206307fe68d2ea09dec094792e9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be3a486311a2a5506dad439e1aba5d6dfd1c11d54bfd665be5f80d89a958ae40ae641eb40718c4ffe422a1b4d1a02dac4a7ec7dbdb530c7dff1dee91dc4caa62
|
7
|
+
data.tar.gz: 59e4d64307c3b4662cf652511ec9f2a1b4c0df7cb293792d5eccfa0d4c804f65ecce0b970ee22c3cd607f39d8d778142f86917df467c1127191ea3e54c47709e
|
data/README.md
CHANGED
@@ -94,7 +94,7 @@ influxdb = InfluxDB::Client.new database, :username => username,
|
|
94
94
|
:time_precision => time_precision
|
95
95
|
|
96
96
|
data = {
|
97
|
-
:value => 0
|
97
|
+
:value => 0,
|
98
98
|
:time => Time.now.to_i
|
99
99
|
}
|
100
100
|
|
@@ -114,7 +114,7 @@ time_precision = 's'
|
|
114
114
|
influxdb = InfluxDB::Client.new database, :username => username, :password => password
|
115
115
|
|
116
116
|
data = {
|
117
|
-
:value => 0
|
117
|
+
:value => 0,
|
118
118
|
:time => Time.now.to_i
|
119
119
|
}
|
120
120
|
|
@@ -152,6 +152,16 @@ influxdb = InfluxDB::Client.new
|
|
152
152
|
influxdb.get_database_user_list(database)
|
153
153
|
```
|
154
154
|
|
155
|
+
List a database user:
|
156
|
+
|
157
|
+
``` ruby
|
158
|
+
require 'influxdb'
|
159
|
+
|
160
|
+
influxdb = InfluxDB::Client.new
|
161
|
+
|
162
|
+
influxdb.get_database_user_info(database, username)
|
163
|
+
```
|
164
|
+
|
155
165
|
Delete a database:
|
156
166
|
|
157
167
|
``` ruby
|
@@ -197,5 +207,5 @@ Testing
|
|
197
207
|
git clone git@github.com:influxdb/influxdb-ruby.git
|
198
208
|
cd influxdb-ruby
|
199
209
|
bundle
|
200
|
-
|
210
|
+
bundle exec rspec
|
201
211
|
```
|
data/lib/influxdb/client.rb
CHANGED
@@ -40,7 +40,7 @@ module InfluxDB
|
|
40
40
|
@password = opts[:password] || "root"
|
41
41
|
@http = Net::HTTP.new(@host, @port)
|
42
42
|
@http.use_ssl = opts[:use_ssl]
|
43
|
-
@time_precision = opts[:time_precision] || "
|
43
|
+
@time_precision = opts[:time_precision] || "s"
|
44
44
|
end
|
45
45
|
|
46
46
|
## allow options, e.g. influxdb.create_database('foo', replicationFactor: 3)
|
@@ -99,10 +99,18 @@ module InfluxDB
|
|
99
99
|
get full_url("db/#{database}/users")
|
100
100
|
end
|
101
101
|
|
102
|
+
def get_database_user_info(database, username)
|
103
|
+
get full_url("db/#{database}/users/#{username}")
|
104
|
+
end
|
105
|
+
|
102
106
|
def alter_database_privilege(database, username, admin=true)
|
103
107
|
update_database_user(database, username, :admin => admin)
|
104
108
|
end
|
105
109
|
|
110
|
+
def continuous_queries
|
111
|
+
get full_url("continuous_queries")
|
112
|
+
end
|
113
|
+
|
106
114
|
def write_point(name, data, async=false, time_precision=@time_precision)
|
107
115
|
data = data.is_a?(Array) ? data : [data]
|
108
116
|
columns = data.reduce(:merge).keys.sort {|a,b| a.to_s <=> b.to_s}
|
@@ -125,11 +133,7 @@ module InfluxDB
|
|
125
133
|
def _write(payload, time_precision=nil)
|
126
134
|
url = full_url("db/#{@database}/series", "time_precision=#{time_precision}")
|
127
135
|
data = JSON.generate(payload)
|
128
|
-
|
129
|
-
headers = {"Content-Type" => "application/json"}
|
130
|
-
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
131
|
-
raise "Write failed with '#{response.message}'" unless (200...300).include?(response.code.to_i)
|
132
|
-
response
|
136
|
+
post(url, data)
|
133
137
|
end
|
134
138
|
|
135
139
|
def query(query)
|
@@ -192,6 +196,10 @@ module InfluxDB
|
|
192
196
|
|
193
197
|
def denormalize_series series
|
194
198
|
columns = series['columns']
|
199
|
+
|
200
|
+
h = Hash.new(-1)
|
201
|
+
columns = columns.map {|v| h[v] += 1; h[v] > 0 ? "#{v}~#{h[v]}" : v }
|
202
|
+
|
195
203
|
series['points'].map do |point|
|
196
204
|
decoded_point = point.map do |value|
|
197
205
|
InfluxDB::PointValue.new(value).load
|
data/lib/influxdb/version.rb
CHANGED
@@ -19,7 +19,7 @@ describe InfluxDB::Client do
|
|
19
19
|
@influxdb.username.should == "root"
|
20
20
|
@influxdb.password.should == "root"
|
21
21
|
@influxdb.instance_variable_get(:@http).use_ssl?.should == false
|
22
|
-
@influxdb.time_precision.should == "
|
22
|
+
@influxdb.time_precision.should == "s"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -29,7 +29,7 @@ describe InfluxDB::Client do
|
|
29
29
|
:port => "port",
|
30
30
|
:username => "username",
|
31
31
|
:password => "password",
|
32
|
-
:time_precision => "
|
32
|
+
:time_precision => "m"
|
33
33
|
|
34
34
|
@influxdb.should be_a InfluxDB::Client
|
35
35
|
@influxdb.database.should be_nil
|
@@ -37,7 +37,7 @@ describe InfluxDB::Client do
|
|
37
37
|
@influxdb.port.should == "port"
|
38
38
|
@influxdb.username.should == "username"
|
39
39
|
@influxdb.password.should == "password"
|
40
|
-
@influxdb.time_precision.should == "
|
40
|
+
@influxdb.time_precision.should == "m"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -51,7 +51,7 @@ describe InfluxDB::Client do
|
|
51
51
|
@influxdb.port.should == 8086
|
52
52
|
@influxdb.username.should == "root"
|
53
53
|
@influxdb.password.should == "root"
|
54
|
-
@influxdb.time_precision.should == "
|
54
|
+
@influxdb.time_precision.should == "s"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -61,7 +61,7 @@ describe InfluxDB::Client do
|
|
61
61
|
:port => "port",
|
62
62
|
:username => "username",
|
63
63
|
:password => "password",
|
64
|
-
:time_precision => "
|
64
|
+
:time_precision => "m"
|
65
65
|
|
66
66
|
@influxdb.should be_a(InfluxDB::Client)
|
67
67
|
@influxdb.database.should == "database"
|
@@ -69,7 +69,7 @@ describe InfluxDB::Client do
|
|
69
69
|
@influxdb.port.should == "port"
|
70
70
|
@influxdb.username.should == "username"
|
71
71
|
@influxdb.password.should == "password"
|
72
|
-
@influxdb.time_precision.should == "
|
72
|
+
@influxdb.time_precision.should == "m"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -217,6 +217,17 @@ describe InfluxDB::Client do
|
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
220
|
+
describe "#get_database_user_info" do
|
221
|
+
it "should GET information about a database user" do
|
222
|
+
user_info = {"name" => "bar", "isAdmin" => true}
|
223
|
+
stub_request(:get, "http://influxdb.test:9999/db/foo/users/bar").with(
|
224
|
+
:query => {:u => "username", :p => "password"}
|
225
|
+
).to_return(:body => JSON.generate(user_info, :status => 200))
|
226
|
+
|
227
|
+
@influxdb.get_database_user_info("foo", "bar").should == user_info
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
220
231
|
describe "#write_point" do
|
221
232
|
it "should POST to add points" do
|
222
233
|
body = [{
|
@@ -361,7 +372,7 @@ describe InfluxDB::Client do
|
|
361
372
|
|
362
373
|
describe "#execute_queries" do
|
363
374
|
before(:each) do
|
364
|
-
data = [{ :name => "foo", :columns => ["name", "age"], :points => [["shahid", 99],["dix", 50]]}]
|
375
|
+
data = [{ :name => "foo", :columns => ["name", "age", "count", "count"], :points => [["shahid", 99, 1, 2],["dix", 50, 3, 4]]}]
|
365
376
|
|
366
377
|
stub_request(:get, "http://influxdb.test:9999/db/database/series").with(
|
367
378
|
:query => { :q => "select * from foo", :u => "username", :p => "password"}
|
@@ -370,7 +381,7 @@ describe InfluxDB::Client do
|
|
370
381
|
)
|
371
382
|
end
|
372
383
|
|
373
|
-
expected_series = { 'foo' => [{"name" => "shahid", "age" => 99}, {"name" => "dix", "age" => 50}]}
|
384
|
+
expected_series = { 'foo' => [{"name" => "shahid", "age" => 99, "count" => 1, "count~1" => 2}, {"name" => "dix", "age" => 50, "count" => 3, "count~1" => 4}]}
|
374
385
|
|
375
386
|
it 'can execute a query with a block' do
|
376
387
|
series = { }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe InfluxDB::Logger do
|
4
|
+
class LoggerTest
|
5
|
+
include InfluxDB::Logger
|
6
|
+
|
7
|
+
def write_to_log(level, message)
|
8
|
+
log(level, message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { LoggerTest.new }
|
13
|
+
|
14
|
+
context 'with DEBUG level' do
|
15
|
+
it 'should not write a log message to STDERR' do
|
16
|
+
expect(STDERR).to_not receive(:puts)
|
17
|
+
|
18
|
+
subject.write_to_log(:debug, 'debug')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with non-DEBUG level' do
|
23
|
+
it 'should write a log message to STDERR' do
|
24
|
+
expect(STDERR).to receive(:puts).with('[InfluxDB] (info) info')
|
25
|
+
|
26
|
+
subject.write_to_log(:info, 'info')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/influxdb/version.rb
|
105
105
|
- lib/influxdb/worker.rb
|
106
106
|
- spec/influxdb/client_spec.rb
|
107
|
+
- spec/influxdb/logger_spec.rb
|
107
108
|
- spec/influxdb/point_value_spec.rb
|
108
109
|
- spec/influxdb_spec.rb
|
109
110
|
- spec/max_queue_spec.rb
|
@@ -134,6 +135,7 @@ specification_version: 4
|
|
134
135
|
summary: Ruby library for InfluxDB.
|
135
136
|
test_files:
|
136
137
|
- spec/influxdb/client_spec.rb
|
138
|
+
- spec/influxdb/logger_spec.rb
|
137
139
|
- spec/influxdb/point_value_spec.rb
|
138
140
|
- spec/influxdb_spec.rb
|
139
141
|
- spec/max_queue_spec.rb
|