influxdb 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +118 -0
- data/lib/influxdb/client.rb +32 -8
- data/lib/influxdb/version.rb +1 -1
- data/spec/influxdb/client_spec.rb +20 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 015169efb594ef5763c19ae7775484d4d7bb5503
|
4
|
+
data.tar.gz: 5028373587c1b36ce5d8c5e723f9641d71fea996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0d6534aa38bf7673c310a864731f21f0e7154244eb37c9cf92bc78833dae03ff6548a31e381a535533de48528df10da4e09af453b782dfae1eb853374d5826
|
7
|
+
data.tar.gz: bbb42ada8b32eeda12ee2966814cfd6fa18d336499d4c7accea408cd23bb4cc5e9b8678f8e1f0db82768d6f66408990dc56933629ba4624d76d7e0f10ecf494d
|
data/README.md
CHANGED
@@ -2,3 +2,121 @@ influxdb-ruby
|
|
2
2
|
=============
|
3
3
|
|
4
4
|

|
5
|
+
|
6
|
+
Ruby client library for [InfluxDB](http://influxdb.org/).
|
7
|
+
|
8
|
+
Install
|
9
|
+
-------
|
10
|
+
|
11
|
+
```
|
12
|
+
$ [sudo] gem install influxdb
|
13
|
+
```
|
14
|
+
|
15
|
+
Or add it to your `Gemfile`, etc.
|
16
|
+
|
17
|
+
Usage
|
18
|
+
-----
|
19
|
+
|
20
|
+
Create a database:
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
require 'influxdb'
|
24
|
+
|
25
|
+
hostname = 'localhost'
|
26
|
+
port = 8086
|
27
|
+
username = 'root'
|
28
|
+
password = 'root'
|
29
|
+
database = 'site_development'
|
30
|
+
|
31
|
+
influxdb = InfluxDB::Client.new(hostname, port, username, password)
|
32
|
+
|
33
|
+
influxdb.create_database(database)
|
34
|
+
```
|
35
|
+
|
36
|
+
Create a user for a database:
|
37
|
+
|
38
|
+
``` ruby
|
39
|
+
require 'influxdb'
|
40
|
+
|
41
|
+
hostname = 'localhost'
|
42
|
+
port = 8086
|
43
|
+
username = 'root'
|
44
|
+
password = 'root'
|
45
|
+
database = 'site_development'
|
46
|
+
|
47
|
+
influxdb = InfluxDB::Client.new(hostname, port, username, password)
|
48
|
+
|
49
|
+
new_username = 'foo'
|
50
|
+
new_password = 'bar'
|
51
|
+
influxdb.create_database_user(database, new_username, new_password)
|
52
|
+
```
|
53
|
+
|
54
|
+
Write some data:
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
require 'influxdb'
|
58
|
+
|
59
|
+
hostname = 'localhost'
|
60
|
+
port = 8086
|
61
|
+
username = 'foo'
|
62
|
+
password = 'bar'
|
63
|
+
database = 'site_development'
|
64
|
+
name = 'foobar'
|
65
|
+
|
66
|
+
influxdb = InfluxDB::Client.new(hostname, port, username, password, database)
|
67
|
+
|
68
|
+
# Enumerator that emits a sine wave
|
69
|
+
Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each
|
70
|
+
|
71
|
+
loop do
|
72
|
+
data = {
|
73
|
+
:value => Value.next
|
74
|
+
}
|
75
|
+
|
76
|
+
influxdb.write_point(name, data)
|
77
|
+
|
78
|
+
sleep 1
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
List databases:
|
83
|
+
|
84
|
+
``` ruby
|
85
|
+
require 'influxdb'
|
86
|
+
|
87
|
+
hostname = 'localhost'
|
88
|
+
port = 8086
|
89
|
+
username = 'root'
|
90
|
+
password = 'root'
|
91
|
+
|
92
|
+
influxdb = InfluxDB::Client.new(hostname, 8086, username, password)
|
93
|
+
|
94
|
+
influxdb.get_database_list
|
95
|
+
```
|
96
|
+
|
97
|
+
Delete a database:
|
98
|
+
|
99
|
+
``` ruby
|
100
|
+
require 'influxdb'
|
101
|
+
|
102
|
+
hostname = 'localhost'
|
103
|
+
port = 8086
|
104
|
+
username = 'root'
|
105
|
+
password = 'root'
|
106
|
+
database = 'site_development'
|
107
|
+
|
108
|
+
influxdb = InfluxDB::Client.new(username, port, username, password)
|
109
|
+
|
110
|
+
influxdb.delete_database(database)
|
111
|
+
```
|
112
|
+
|
113
|
+
|
114
|
+
Testing
|
115
|
+
-------
|
116
|
+
|
117
|
+
```
|
118
|
+
git clone git@github.com:influxdb/influxdb-ruby.git
|
119
|
+
cd influxdb-ruby
|
120
|
+
bundle
|
121
|
+
rake
|
122
|
+
```
|
data/lib/influxdb/client.rb
CHANGED
@@ -1,13 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module InfluxDB
|
4
5
|
class Client
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
attr_accessor :host, :port, :username, :password, :database
|
7
|
+
|
8
|
+
# Initializes a new Influxdb client
|
9
|
+
#
|
10
|
+
# === Examples:
|
11
|
+
#
|
12
|
+
# Influxdb.new # connect to localhost using root/root
|
13
|
+
# # as the credentials and doesn't connect to a db
|
14
|
+
#
|
15
|
+
# Influxdb.new 'db' # connect to localhost using root/root
|
16
|
+
# # as the credentials and 'db' as the db name
|
17
|
+
#
|
18
|
+
# Influxdb.new :username => 'username' # override username, other defaults remain unchanged
|
19
|
+
#
|
20
|
+
# Influxdb.new 'db', :username => 'username' # override username, use 'db' as the db name
|
21
|
+
#
|
22
|
+
# === Valid options in hash
|
23
|
+
#
|
24
|
+
# +:hostname+:: the hostname to connect to
|
25
|
+
# +:port+:: the port to connect to
|
26
|
+
# +:username+:: the username to use when executing commands
|
27
|
+
# +:password+:: the password associated with the username
|
28
|
+
def initialize *args
|
29
|
+
opts = args.last.is_a?(Hash) ? args.last : {}
|
30
|
+
@host = opts[:host] || "localhost"
|
31
|
+
@port = opts[:port] || 8086
|
32
|
+
@username = opts[:username] || "root"
|
33
|
+
@password = opts[:password] || "root"
|
34
|
+
@database = args.first
|
11
35
|
end
|
12
36
|
|
13
37
|
def create_database(name)
|
@@ -48,7 +72,7 @@ module InfluxDB
|
|
48
72
|
end
|
49
73
|
|
50
74
|
payload[:points].push point
|
51
|
-
data = JSON.generate(payload)
|
75
|
+
data = JSON.generate([payload])
|
52
76
|
response = http.request(Net::HTTP::Post.new(url), data)
|
53
77
|
end
|
54
78
|
end
|
data/lib/influxdb/version.rb
CHANGED
@@ -3,14 +3,30 @@ require "json"
|
|
3
3
|
|
4
4
|
describe InfluxDB::Client do
|
5
5
|
before do
|
6
|
-
@influxdb = InfluxDB::Client.new
|
6
|
+
@influxdb = InfluxDB::Client.new "database", :host => "influxdb.test",
|
7
|
+
:port => 9999, :username => "username", :password => "password"
|
7
8
|
end
|
8
9
|
|
9
10
|
describe "#new" do
|
11
|
+
it "should instantiate a new InfluxDB client and default to localhost" do
|
12
|
+
@influxdb = InfluxDB::Client.new
|
13
|
+
|
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")
|
19
|
+
end
|
20
|
+
|
10
21
|
it "should instantiate a new InfluxDB client" do
|
11
|
-
@influxdb = InfluxDB::Client.new
|
22
|
+
@influxdb = InfluxDB::Client.new "database", :hostname => "host",
|
23
|
+
:port => "port", :username => "username", :password => "password"
|
12
24
|
|
13
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")
|
14
30
|
end
|
15
31
|
end
|
16
32
|
|
@@ -58,11 +74,11 @@ describe InfluxDB::Client do
|
|
58
74
|
|
59
75
|
describe "#write_point" do
|
60
76
|
it "should POST to add points" do
|
61
|
-
body = {
|
77
|
+
body = [{
|
62
78
|
:name => "seriez",
|
63
79
|
:points => [["juan", 87]],
|
64
80
|
:columns => ["name", "age"]
|
65
|
-
}
|
81
|
+
}]
|
66
82
|
|
67
83
|
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
68
84
|
:query => {:u => "username", :p => "password"},
|
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.4
|
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-
|
11
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|