influxdb 0.0.12 → 0.0.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 +8 -8
- data/lib/influxdb.rb +1 -0
- data/lib/influxdb/client.rb +54 -47
- data/lib/influxdb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDEzYzNkNTY1OWIxYzcxMDI0ODVjNDMwMDZmZDgwMjI3OWZkODg2Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTYxODNmYWVhYzUwMzY2ZGMxM2YyN2M1OGZkOGU1MGNhOGFiY2YwZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTNmNjMwZGFkYjEyMTA5MWEzZDc0YTQzZWJiZTNiYTlkY2UyNWZhODU1ODYw
|
10
|
+
Mzg4ZjMwZDQwZDk1Yzc4OGI1NjQyNzVmNzNjNDU4OWFkNjYxN2Q0MDM4NWRl
|
11
|
+
NGE5ZGNhN2Y4N2JlMWE0ZTRjY2ViMTIwNWY0N2Q5OTFlMjQ5Y2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2RjNThlNjNlOTlkYTA1YTA4MmM4ODQ2ZDQ5ZmQ2YzRmOTI3NTg0NjgyZmZk
|
14
|
+
YzdhNjg5MTk0Yjk1NjUzNjk1ZTNiMGJiN2Y3MjZlMTRjNjFkMzU0Y2M4ZWZi
|
15
|
+
ZmE1ZDlmMTEwMjYwMDk1OGQwMGNjY2ExYzU4MWJiODAwMzM0MWU=
|
data/lib/influxdb.rb
CHANGED
data/lib/influxdb/client.rb
CHANGED
@@ -10,19 +10,19 @@ module InfluxDB
|
|
10
10
|
|
11
11
|
include InfluxDB::Logger
|
12
12
|
|
13
|
-
# Initializes a new
|
13
|
+
# Initializes a new InfluxDB client
|
14
14
|
#
|
15
15
|
# === Examples:
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# InfluxDB::Client.new # connect to localhost using root/root
|
18
|
+
# # as the credentials and doesn't connect to a db
|
19
19
|
#
|
20
|
-
#
|
21
|
-
#
|
20
|
+
# InfluxDB::Client.new 'db' # connect to localhost using root/root
|
21
|
+
# # as the credentials and 'db' as the db name
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# InfluxDB::Client.new :username => 'username' # override username, other defaults remain unchanged
|
24
24
|
#
|
25
|
-
# Influxdb.new 'db', :username => 'username' # override username, use 'db' as the db name
|
25
|
+
# Influxdb::Client.new 'db', :username => 'username' # override username, use 'db' as the db name
|
26
26
|
#
|
27
27
|
# === Valid options in hash
|
28
28
|
#
|
@@ -45,80 +45,55 @@ module InfluxDB
|
|
45
45
|
def create_database(name)
|
46
46
|
url = full_url("db")
|
47
47
|
data = JSON.generate({:name => name})
|
48
|
-
|
49
|
-
headers = {"Content-Type" => "application/json"}
|
50
|
-
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
48
|
+
post(url, data)
|
51
49
|
end
|
52
50
|
|
53
51
|
def delete_database(name)
|
54
|
-
|
55
|
-
|
56
|
-
response = @http.request(Net::HTTP::Delete.new(url))
|
52
|
+
delete full_url("db/#{name}")
|
57
53
|
end
|
58
54
|
|
59
55
|
def get_database_list
|
60
|
-
|
61
|
-
|
62
|
-
response = @http.request(Net::HTTP::Get.new(url))
|
63
|
-
JSON.parse(response.body)
|
56
|
+
get full_url("db")
|
64
57
|
end
|
65
58
|
|
66
59
|
def create_cluster_admin(username, password)
|
67
60
|
url = full_url("cluster_admins")
|
68
61
|
data = JSON.generate({:name => username, :password => password})
|
69
|
-
|
70
|
-
headers = {"Content-Type" => "application/json"}
|
71
|
-
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
62
|
+
post(url, data)
|
72
63
|
end
|
73
64
|
|
74
65
|
def update_cluster_admin(username, password)
|
75
66
|
url = full_url("cluster_admins/#{username}")
|
76
67
|
data = JSON.generate({:password => password})
|
77
|
-
|
78
|
-
headers = {"Content-Type" => "application/json"}
|
79
|
-
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
68
|
+
post(url, data)
|
80
69
|
end
|
81
70
|
|
82
71
|
def delete_cluster_admin(username)
|
83
|
-
|
84
|
-
|
85
|
-
response = @http.request(Net::HTTP::Delete.new(url))
|
72
|
+
delete full_url("cluster_admins/#{username}")
|
86
73
|
end
|
87
74
|
|
88
75
|
def get_cluster_admin_list
|
89
|
-
|
90
|
-
|
91
|
-
response = @http.request(Net::HTTP::Get.new(url))
|
92
|
-
JSON.parse(response.body)
|
76
|
+
get full_url("cluster_admins")
|
93
77
|
end
|
94
78
|
|
95
79
|
def create_database_user(database, username, password)
|
96
80
|
url = full_url("db/#{database}/users")
|
97
81
|
data = JSON.generate({:name => username, :password => password})
|
98
|
-
|
99
|
-
headers = {"Content-Type" => "application/json"}
|
100
|
-
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
82
|
+
post(url, data)
|
101
83
|
end
|
102
84
|
|
103
85
|
def update_database_user(database, username, options = {})
|
104
86
|
url = full_url("db/#{database}/users/#{username}")
|
105
87
|
data = JSON.generate(options)
|
106
|
-
|
107
|
-
headers = {"Content-Type" => "application/json"}
|
108
|
-
@http.request(Net::HTTP::Post.new(url, headers), data)
|
88
|
+
post(url, data)
|
109
89
|
end
|
110
90
|
|
111
91
|
def delete_database_user(database, username)
|
112
|
-
|
113
|
-
|
114
|
-
@http.request(Net::HTTP::Delete.new(url))
|
92
|
+
delete full_url("db/#{database}/users/#{username}")
|
115
93
|
end
|
116
94
|
|
117
95
|
def get_database_user_list(database)
|
118
|
-
|
119
|
-
|
120
|
-
response = @http.request(Net::HTTP::Get.new(url))
|
121
|
-
JSON.parse(response.body)
|
96
|
+
get full_url("db/#{database}/users")
|
122
97
|
end
|
123
98
|
|
124
99
|
def alter_database_privilege(database, username, admin=true)
|
@@ -155,10 +130,8 @@ module InfluxDB
|
|
155
130
|
end
|
156
131
|
|
157
132
|
def query(query)
|
158
|
-
url = full_url("db/#{@database}/series", "q=#{query}")
|
159
|
-
|
160
|
-
response = @http.request(Net::HTTP::Get.new(url))
|
161
|
-
series = JSON.parse(response.body)
|
133
|
+
url = URI.encode full_url("db/#{@database}/series", "q=#{query}")
|
134
|
+
series = get(url)
|
162
135
|
|
163
136
|
if block_given?
|
164
137
|
series.each { |s| yield s['name'], denormalize_series(s) }
|
@@ -180,6 +153,40 @@ module InfluxDB
|
|
180
153
|
end
|
181
154
|
end
|
182
155
|
|
156
|
+
def get(url)
|
157
|
+
response = @http.request(Net::HTTP::Get.new(url))
|
158
|
+
if response.kind_of? Net::HTTPSuccess
|
159
|
+
return JSON.parse(response.body)
|
160
|
+
elsif response.kind_of? Net::HTTPUnauthorized
|
161
|
+
raise InfluxDB::AuthenticationError.new response.body
|
162
|
+
else
|
163
|
+
raise InfluxDB::Error.new response.body
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def post(url, data)
|
168
|
+
headers = {"Content-Type" => "application/json"}
|
169
|
+
response = @http.request(Net::HTTP::Post.new(url, headers), data)
|
170
|
+
if response.kind_of? Net::HTTPSuccess
|
171
|
+
return response
|
172
|
+
elsif response.kind_of? Net::HTTPUnauthorized
|
173
|
+
raise InfluxDB::AuthenticationError.new response.body
|
174
|
+
else
|
175
|
+
raise InfluxDB::Error.new response.body
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def delete(url)
|
180
|
+
response = @http.request(Net::HTTP::Delete.new(url))
|
181
|
+
if response.kind_of? Net::HTTPSuccess
|
182
|
+
return response
|
183
|
+
elsif response.kind_of? Net::HTTPUnauthorized
|
184
|
+
raise InfluxDB::AuthenticationError.new response.body
|
185
|
+
else
|
186
|
+
raise InfluxDB::Error.new response.body
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
183
190
|
def denormalize_series series
|
184
191
|
columns = series['columns']
|
185
192
|
series['points'].map { |point| Hash[columns.zip(point)]}
|
data/lib/influxdb/version.rb
CHANGED