influxdb 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/influxdb.gemspec +1 -0
- data/lib/influxdb/client.rb +35 -5
- data/lib/influxdb/version.rb +1 -1
- data/spec/influxdb/client_spec.rb +63 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4c1d9fba941cead2557e6067144733298d81599
|
4
|
+
data.tar.gz: 4859b9674377a0c4cd613f79b4db5488179523ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65633c47e35680828609e2ed6b84dc74f72c506b3c58271db3aa69b18debccd2a5b3e0bace93eefbaa7fe1a0965a28f2142abb4eb5af072fa5833e2b3f15cf5e
|
7
|
+
data.tar.gz: 41492fac4c940702fbe15d2c17bf3c3c6afd54b70d3777b09eeab563b8ba9bde13a2ee1885fe1569a13fd91952877520544addf5b5ed1184f569cbef4de2a393
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
influxdb-ruby
|
2
2
|
=============
|
3
3
|
|
4
|
-
![
|
4
|
+
[![Build Status](https://travis-ci.org/influxdb/influxdb-ruby.png?branch=master)](https://travis-ci.org/influxdb/influxdb-ruby)
|
5
5
|
|
6
6
|
Ruby client library for [InfluxDB](http://influxdb.org/).
|
7
7
|
|
data/influxdb.gemspec
CHANGED
data/lib/influxdb/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
|
+
require 'addressable/uri'
|
3
4
|
|
4
5
|
module InfluxDB
|
5
6
|
class Client
|
@@ -69,15 +70,44 @@ module InfluxDB
|
|
69
70
|
url = "/db/#{@database}/series?u=#{@username}&p=#{@password}"
|
70
71
|
payload = {:name => name, :points => [], :columns => []}
|
71
72
|
|
72
|
-
|
73
|
-
data.
|
74
|
-
|
75
|
-
|
73
|
+
data = data.is_a?(Array) ? data : [data]
|
74
|
+
columns = data.reduce(:merge).keys
|
75
|
+
payload[:columns] = columns
|
76
|
+
|
77
|
+
data.each do |p|
|
78
|
+
point = []
|
79
|
+
columns.each { |c| point << p[c] }
|
80
|
+
payload[:points].push point
|
76
81
|
end
|
77
82
|
|
78
|
-
payload[:points].push point
|
79
83
|
data = JSON.generate([payload])
|
80
84
|
response = http.request(Net::HTTP::Post.new(url), data)
|
81
85
|
end
|
86
|
+
|
87
|
+
def query query
|
88
|
+
http = Net::HTTP.new(@host, @port)
|
89
|
+
url = "/db/#{@database}/query?u=#{@username}&p=#{@password}&q=#{query}"
|
90
|
+
url = Addressable::URI.encode url
|
91
|
+
response = http.request(Net::HTTP::Get.new(url))
|
92
|
+
series = JSON.parse(response.body)
|
93
|
+
|
94
|
+
if block_given?
|
95
|
+
series.each { |s| yield s['name'], denormalize_series(s) }
|
96
|
+
else
|
97
|
+
series.reduce({}) do |col, s|
|
98
|
+
name = s['name']
|
99
|
+
denormalized_series = denormalize_series s
|
100
|
+
col[name] = denormalized_series
|
101
|
+
col
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def denormalize_series series
|
109
|
+
columns = series['columns']
|
110
|
+
series['values'].map { |point| Hash[columns.zip(point)]}
|
111
|
+
end
|
82
112
|
end
|
83
113
|
end
|
data/lib/influxdb/version.rb
CHANGED
@@ -91,5 +91,68 @@ describe InfluxDB::Client do
|
|
91
91
|
|
92
92
|
@influxdb.write_point("seriez", data).should be_a(Net::HTTPOK)
|
93
93
|
end
|
94
|
+
|
95
|
+
it "should POST multiple points" do
|
96
|
+
body = [{
|
97
|
+
:name => "seriez",
|
98
|
+
:points => [["juan", 87], ["shahid", 99]],
|
99
|
+
:columns => ["name", "age"]
|
100
|
+
}]
|
101
|
+
|
102
|
+
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
103
|
+
:query => {:u => "username", :p => "password"},
|
104
|
+
:body => JSON.generate(body)
|
105
|
+
)
|
106
|
+
|
107
|
+
data = [{:name => "juan", :age => 87}, { :name => "shahid", :age => 99}]
|
108
|
+
|
109
|
+
@influxdb.write_point("seriez", data).should be_a(Net::HTTPOK)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should POST multiple points with missing columns" do
|
113
|
+
body = [{
|
114
|
+
:name => "seriez",
|
115
|
+
:points => [["juan", 87], ["shahid", nil]],
|
116
|
+
:columns => ["name", "age"]
|
117
|
+
}]
|
118
|
+
|
119
|
+
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
120
|
+
:query => {:u => "username", :p => "password"},
|
121
|
+
:body => JSON.generate(body)
|
122
|
+
)
|
123
|
+
|
124
|
+
data = [{:name => "juan", :age => 87}, { :name => "shahid"}]
|
125
|
+
|
126
|
+
@influxdb.write_point("seriez", data).should be_a(Net::HTTPOK)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#execute_queries" do
|
131
|
+
before(:each) do
|
132
|
+
data = [{ :name => "foo", :columns => ["name", "age"], :values => [["shahid", 99],["dix", 50]]}]
|
133
|
+
|
134
|
+
stub_request(:get, "http://influxdb.test:9999/db/database/query").with(
|
135
|
+
:query => { :q => "select * from foo", :u => "username", :p => "password"}
|
136
|
+
).to_return(
|
137
|
+
:body => JSON.generate(data)
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
expected_series = { 'foo' => [{"name" => "shahid", "age" => 99}, {"name" => "dix", "age" => 50}]}
|
142
|
+
|
143
|
+
it 'can execute a query with a block' do
|
144
|
+
series = { }
|
145
|
+
|
146
|
+
@influxdb.query "select * from foo" do |name, points|
|
147
|
+
series[name] = points
|
148
|
+
end
|
149
|
+
|
150
|
+
series.should ==(expected_series)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'can execute a query without a block' do
|
154
|
+
series = @influxdb.query 'select * from foo'
|
155
|
+
series.should ==(expected_series)
|
156
|
+
end
|
94
157
|
end
|
95
158
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|