influxdb 0.0.10 → 0.0.11

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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a15d18aa85145172f0abb3333ef7ffb9641b4ada
4
- data.tar.gz: 6146be97a07658dffb26b044d15ddca5adc8e8ac
5
- SHA512:
6
- metadata.gz: 191c102bd7ad4f5e136763b16ba0efce9b2f6f1002bcea5e317cad36ad20918484c714e277a329890598bd1172469bf117013ed93e2db5ed7742aebbfaa7c8bc
7
- data.tar.gz: 7cdbe3eefee7b679dae5c46d1a825cc36195d1bdb05326cf57dd005c1ce3663d57bd34414edaa289424281a726d9df6d25702fea527b4d8711bb6edac9d02151
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
@@ -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("dbs")
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
- url = full_url("db/#{database}/users/#{username}")
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)
@@ -1,3 +1,3 @@
1
1
  module InfluxDB
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -52,7 +52,11 @@ module InfluxDB
52
52
  data.push p
53
53
  end
54
54
 
55
- _write(data)
55
+ begin
56
+ _write(data)
57
+ rescue => e
58
+ puts "Cannot write data: #{e.inspect}"
59
+ end
56
60
  end while @queue.length > MAX_POST_POINTS
57
61
  end
58
62
  end
@@ -8,25 +8,62 @@ describe InfluxDB::Client do
8
8
  end
9
9
 
10
10
  describe "#new" do
11
- it "should instantiate a new InfluxDB client and default to localhost" do
12
- @influxdb = InfluxDB::Client.new
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
- @influxdb.should be_a(InfluxDB::Client)
15
- @influxdb.host.should ==("localhost")
16
- @influxdb.port.should ==(8086)
17
- @influxdb.username.should ==("root")
18
- @influxdb.password.should ==("root")
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
- it "should instantiate a new InfluxDB client" do
22
- @influxdb = InfluxDB::Client.new "database", :hostname => "host",
23
- :port => "port", :username => "username", :password => "password"
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
- @influxdb.should be_a(InfluxDB::Client)
26
- @influxdb.host.should ==("localhost")
27
- @influxdb.port.should ==("port")
28
- @influxdb.username.should ==("username")
29
- @influxdb.password.should ==("password")
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/dbs").with(
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.10
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-22 00:00:00.000000000 Z
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.3
128
+ rubygems_version: 2.0.7
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Ruby library for InfluxDB.