influxdb 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/README.md +20 -0
- data/lib/influxdb/client.rb +12 -7
- data/lib/influxdb/version.rb +1 -1
- data/lib/influxdb/worker.rb +5 -1
- data/spec/influxdb/client_spec.rb +82 -17
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWViNjMyNTE1YzkxZTI1ODAyZjQ3YzdlNmRlYTcwNTY3OWRiNjUwMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjFiODMzNzA1MDU5YzQzNTk3Nzc3MDU5YzY3MmE3ZDVlYmI0OWE4ZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTU4MmI5N2E0MTViYzc3MmIyYjM3MDc0YTE5NGExMWFkZWU4MjZiMTgyZTAz
|
10
|
+
YTJkNDIxM2MwNDJmYjcwMTRkYWU3YTRhMjQ3MTY5Y2UyNTk1ZWEzNjhmMThk
|
11
|
+
NWY0MjM4Y2VkMDgzN2MzMDAzNGI2ZmU5OWRmMDA0ZDMwN2NlZWE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTQxYzc2ZjFmNmYxNDI3MzI0MTZmNGVmNjZkZmEyYTk0Y2JhNmEyMTBhOWVl
|
14
|
+
NDc5NTQ5ZjhiYTIxMmMyOWRjMjc4MmUwYmM5NDZmOWJiM2Y3OWUyNmJjMTA2
|
15
|
+
MWEwMTRkMWZkNTAwZDgzN2JjZmM2MTUwYjY4MmM0ZjY2NGM0NTI=
|
data/README.md
CHANGED
@@ -40,6 +40,16 @@ new_password = 'bar'
|
|
40
40
|
influxdb.create_database_user(database, new_username, new_password)
|
41
41
|
```
|
42
42
|
|
43
|
+
Update a database user:
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
require 'influxdb'
|
47
|
+
|
48
|
+
influxdb = InfluxDB::Client.new
|
49
|
+
|
50
|
+
influxdb.update_database_user(database, username, :password => "new_password")
|
51
|
+
```
|
52
|
+
|
43
53
|
Write some data:
|
44
54
|
|
45
55
|
``` ruby
|
@@ -66,6 +76,16 @@ loop do
|
|
66
76
|
end
|
67
77
|
```
|
68
78
|
|
79
|
+
List cluster admins:
|
80
|
+
|
81
|
+
``` ruby
|
82
|
+
require 'influxdb'
|
83
|
+
|
84
|
+
influxdb = InfluxDB::Client.new
|
85
|
+
|
86
|
+
influxdb.get_cluster_admin_list
|
87
|
+
```
|
88
|
+
|
69
89
|
List databases:
|
70
90
|
|
71
91
|
``` ruby
|
data/lib/influxdb/client.rb
CHANGED
@@ -31,12 +31,12 @@ module InfluxDB
|
|
31
31
|
# +:username+:: the username to use when executing commands
|
32
32
|
# +:password+:: the password associated with the username
|
33
33
|
def initialize *args
|
34
|
+
@database = args.first if args.first.is_a? String
|
34
35
|
opts = args.last.is_a?(Hash) ? args.last : {}
|
35
36
|
@host = opts[:host] || "localhost"
|
36
37
|
@port = opts[:port] || 8086
|
37
38
|
@username = opts[:username] || "root"
|
38
39
|
@password = opts[:password] || "root"
|
39
|
-
@database = args.first
|
40
40
|
@http = Net::HTTP.new(@host, @port)
|
41
41
|
@queue = InfluxDB::MaxQueue.new
|
42
42
|
spawn_threads!
|
@@ -57,7 +57,7 @@ module InfluxDB
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def get_database_list
|
60
|
-
url = full_url("
|
60
|
+
url = full_url("db")
|
61
61
|
|
62
62
|
response = @http.request(Net::HTTP::Get.new(url))
|
63
63
|
JSON.parse(response.body)
|
@@ -85,6 +85,13 @@ module InfluxDB
|
|
85
85
|
response = @http.request(Net::HTTP::Delete.new(url))
|
86
86
|
end
|
87
87
|
|
88
|
+
def get_cluster_admin_list
|
89
|
+
url = full_url("cluster_admins")
|
90
|
+
|
91
|
+
response = @http.request(Net::HTTP::Get.new(url))
|
92
|
+
JSON.parse(response.body)
|
93
|
+
end
|
94
|
+
|
88
95
|
def create_database_user(database, username, password)
|
89
96
|
url = full_url("db/#{database}/users")
|
90
97
|
data = JSON.generate({:name => username, :password => password})
|
@@ -115,11 +122,7 @@ module InfluxDB
|
|
115
122
|
end
|
116
123
|
|
117
124
|
def alter_database_privilege(database, username, admin=true)
|
118
|
-
|
119
|
-
data = JSON.generate({:admin => admin})
|
120
|
-
|
121
|
-
headers = {"Content-Type" => "application/json"}
|
122
|
-
@http.request(Net::HTTP::Post.new(url, headers), data)
|
125
|
+
update_database_user(database, username, :admin => admin)
|
123
126
|
end
|
124
127
|
|
125
128
|
def write_point(name, data, async=false)
|
@@ -142,6 +145,8 @@ module InfluxDB
|
|
142
145
|
|
143
146
|
headers = {"Content-Type" => "application/json"}
|
144
147
|
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
148
|
+
raise "Write failed with '#{response.message}'" unless (200...300).include?(response.code.to_i)
|
149
|
+
response
|
145
150
|
end
|
146
151
|
|
147
152
|
def query(query)
|
data/lib/influxdb/version.rb
CHANGED
data/lib/influxdb/worker.rb
CHANGED
@@ -8,25 +8,62 @@ describe InfluxDB::Client do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#new" do
|
11
|
-
|
12
|
-
|
11
|
+
describe "with no parameters specified" do
|
12
|
+
it "should be initialzed with a nil database and the default options" do
|
13
|
+
@influxdb = InfluxDB::Client.new
|
14
|
+
|
15
|
+
@influxdb.should be_a InfluxDB::Client
|
16
|
+
@influxdb.database.should be_nil
|
17
|
+
@influxdb.host.should == "localhost"
|
18
|
+
@influxdb.port.should == 8086
|
19
|
+
@influxdb.username.should == "root"
|
20
|
+
@influxdb.password.should == "root"
|
21
|
+
end
|
22
|
+
end
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
24
|
+
describe "with no database specified" do
|
25
|
+
it "should be initialized with a nil database and the specified options" do
|
26
|
+
@influxdb = InfluxDB::Client.new :hostname => "host",
|
27
|
+
:port => "port",
|
28
|
+
:username => "username",
|
29
|
+
:password => "password"
|
30
|
+
|
31
|
+
@influxdb.should be_a InfluxDB::Client
|
32
|
+
@influxdb.database.should be_nil
|
33
|
+
@influxdb.host.should == "localhost"
|
34
|
+
@influxdb.port.should == "port"
|
35
|
+
@influxdb.username.should == "username"
|
36
|
+
@influxdb.password.should == "password"
|
37
|
+
end
|
19
38
|
end
|
20
39
|
|
21
|
-
|
22
|
-
|
23
|
-
|
40
|
+
describe "with only a database specified" do
|
41
|
+
it "should be initialized with the specified database and the default options" do
|
42
|
+
@influxdb = InfluxDB::Client.new "database"
|
24
43
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
@influxdb.should be_a(InfluxDB::Client)
|
45
|
+
@influxdb.database.should == "database"
|
46
|
+
@influxdb.host.should == "localhost"
|
47
|
+
@influxdb.port.should == 8086
|
48
|
+
@influxdb.username.should == "root"
|
49
|
+
@influxdb.password.should == "root"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "with both a database and options specified" do
|
54
|
+
it "should be initialized with the specified database and options" do
|
55
|
+
@influxdb = InfluxDB::Client.new "database", :hostname => "host",
|
56
|
+
:port => "port",
|
57
|
+
:username => "username",
|
58
|
+
:password => "password"
|
59
|
+
|
60
|
+
@influxdb.should be_a(InfluxDB::Client)
|
61
|
+
@influxdb.database.should == "database"
|
62
|
+
@influxdb.host.should == "localhost"
|
63
|
+
@influxdb.port.should == "port"
|
64
|
+
@influxdb.username.should == "username"
|
65
|
+
@influxdb.password.should == "password"
|
66
|
+
end
|
30
67
|
end
|
31
68
|
end
|
32
69
|
|
@@ -54,7 +91,7 @@ describe InfluxDB::Client do
|
|
54
91
|
describe "#get_database_list" do
|
55
92
|
it "should GET a list of databases" do
|
56
93
|
database_list = [{"name" => "foobar"}]
|
57
|
-
stub_request(:get, "http://influxdb.test:9999/
|
94
|
+
stub_request(:get, "http://influxdb.test:9999/db").with(
|
58
95
|
:query => {:u => "username", :p => "password"}
|
59
96
|
).to_return(:body => JSON.generate(database_list), :status => 200)
|
60
97
|
|
@@ -94,6 +131,17 @@ describe InfluxDB::Client do
|
|
94
131
|
end
|
95
132
|
end
|
96
133
|
|
134
|
+
describe "#get_cluster_admin_list" do
|
135
|
+
it "should GET a list of cluster admins" do
|
136
|
+
admin_list = [{"username"=>"root"}, {"username"=>"admin"}]
|
137
|
+
stub_request(:get, "http://influxdb.test:9999/cluster_admins").with(
|
138
|
+
:query => {:u => "username", :p => "password"}
|
139
|
+
).to_return(:body => JSON.generate(admin_list), :status => 200)
|
140
|
+
|
141
|
+
@influxdb.get_cluster_admin_list.should == admin_list
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
97
145
|
describe "#create_database_user" do
|
98
146
|
it "should POST to create a new database user" do
|
99
147
|
stub_request(:post, "http://influxdb.test:9999/db/foo/users").with(
|
@@ -166,6 +214,23 @@ describe InfluxDB::Client do
|
|
166
214
|
@influxdb.write_point("seriez", data).should be_a(Net::HTTPOK)
|
167
215
|
end
|
168
216
|
|
217
|
+
it "raise an exception if the server didn't return 200" do
|
218
|
+
body = [{
|
219
|
+
"name" => "seriez",
|
220
|
+
"points" => [[87, "juan"]],
|
221
|
+
"columns" => ["age", "name"]
|
222
|
+
}]
|
223
|
+
|
224
|
+
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
225
|
+
:query => {:u => "username", :p => "password"},
|
226
|
+
:body => body
|
227
|
+
).to_return(:status => 401)
|
228
|
+
|
229
|
+
data = {:name => "juan", :age => 87}
|
230
|
+
|
231
|
+
expect { @influxdb.write_point("seriez", data) }.to raise_error
|
232
|
+
end
|
233
|
+
|
169
234
|
it "should POST multiple points" do
|
170
235
|
body = [{
|
171
236
|
"name" => "seriez",
|
@@ -176,7 +241,7 @@ describe InfluxDB::Client do
|
|
176
241
|
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
177
242
|
:query => {:u => "username", :p => "password"},
|
178
243
|
:body => body
|
179
|
-
)
|
244
|
+
).to_return(:status => 200)
|
180
245
|
|
181
246
|
data = [{:name => "juan", :age => 87}, { :name => "shahid", :age => 99}]
|
182
247
|
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -42,42 +42,42 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: This is the official Ruby library for InfluxDB.
|
@@ -115,17 +115,17 @@ require_paths:
|
|
115
115
|
- lib
|
116
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- - '>='
|
118
|
+
- - ! '>='
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - '>='
|
123
|
+
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.0.
|
128
|
+
rubygems_version: 2.0.7
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Ruby library for InfluxDB.
|