influxdb 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +41 -0
- data/.travis.yml +3 -2
- data/Gemfile +7 -1
- data/README.md +218 -102
- data/Rakefile +2 -6
- data/lib/influxdb.rb +15 -5
- data/lib/influxdb/client.rb +38 -433
- data/lib/influxdb/client/http.rb +123 -0
- data/lib/influxdb/config.rb +66 -0
- data/lib/influxdb/errors.rb +8 -2
- data/lib/influxdb/{logger.rb → logging.rb} +6 -5
- data/lib/influxdb/max_queue.rb +2 -1
- data/lib/influxdb/point_value.rb +27 -25
- data/lib/influxdb/query/cluster.rb +17 -0
- data/lib/influxdb/query/continuous_query.rb +22 -0
- data/lib/influxdb/query/core.rb +110 -0
- data/lib/influxdb/query/database.rb +21 -0
- data/lib/influxdb/query/retention_policy.rb +26 -0
- data/lib/influxdb/query/user.rb +41 -0
- data/lib/influxdb/version.rb +2 -2
- data/lib/influxdb/writer/async.rb +115 -0
- data/lib/influxdb/writer/udp.rb +21 -0
- data/spec/influxdb/cases/async_client_spec.rb +33 -0
- data/spec/influxdb/cases/query_cluster_spec.rb +65 -0
- data/spec/influxdb/cases/query_continuous_query_spec.rb +82 -0
- data/spec/influxdb/cases/query_core.rb +34 -0
- data/spec/influxdb/cases/query_database_spec.rb +58 -0
- data/spec/influxdb/cases/query_retention_policy_spec.rb +84 -0
- data/spec/influxdb/cases/query_series_spec.rb +50 -0
- data/spec/influxdb/cases/query_shard_space_spec.rb +105 -0
- data/spec/influxdb/cases/query_shard_spec.rb +43 -0
- data/spec/influxdb/cases/query_user_spec.rb +127 -0
- data/spec/influxdb/cases/querying_spec.rb +149 -0
- data/spec/influxdb/cases/retry_requests_spec.rb +102 -0
- data/spec/influxdb/cases/udp_client_spec.rb +21 -0
- data/spec/influxdb/cases/write_points_spec.rb +140 -0
- data/spec/influxdb/client_spec.rb +37 -810
- data/spec/influxdb/config_spec.rb +118 -0
- data/spec/influxdb/{logger_spec.rb → logging_spec.rb} +4 -8
- data/spec/influxdb/max_queue_spec.rb +29 -0
- data/spec/influxdb/point_value_spec.rb +81 -14
- data/spec/influxdb/worker_spec.rb +8 -11
- data/spec/spec_helper.rb +7 -10
- metadata +65 -30
- data/lib/influxdb/udp_client.rb +0 -16
- data/lib/influxdb/worker.rb +0 -80
- data/spec/influxdb/udp_client_spec.rb +0 -33
- data/spec/influxdb_spec.rb +0 -4
- data/spec/max_queue_spec.rb +0 -32
data/lib/influxdb/udp_client.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require "json"
|
2
|
-
|
3
|
-
module InfluxDB
|
4
|
-
class UDPClient
|
5
|
-
attr_accessor :socket
|
6
|
-
def initialize(host, port)
|
7
|
-
self.socket = UDPSocket.new
|
8
|
-
self.socket.connect(host, port)
|
9
|
-
end
|
10
|
-
|
11
|
-
def send(payload)
|
12
|
-
socket.send(JSON.generate(payload), 0)
|
13
|
-
rescue
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/influxdb/worker.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
require "net/http"
|
3
|
-
require "uri"
|
4
|
-
|
5
|
-
module InfluxDB
|
6
|
-
class Worker
|
7
|
-
attr_reader :client
|
8
|
-
attr_accessor :queue
|
9
|
-
|
10
|
-
include InfluxDB::Logging
|
11
|
-
|
12
|
-
MAX_POST_POINTS = 1000
|
13
|
-
NUM_WORKER_THREADS = 3
|
14
|
-
SLEEP_INTERVAL = 5
|
15
|
-
|
16
|
-
def initialize(client)
|
17
|
-
@queue = InfluxDB::MaxQueue.new
|
18
|
-
@client = client
|
19
|
-
spawn_threads!
|
20
|
-
|
21
|
-
at_exit do
|
22
|
-
log :debug, "Thread exiting, flushing queue."
|
23
|
-
check_background_queue until @queue.empty?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def current_threads
|
28
|
-
Thread.list.select {|t| t[:influxdb] == self.object_id}
|
29
|
-
end
|
30
|
-
|
31
|
-
def current_thread_count
|
32
|
-
Thread.list.count {|t| t[:influxdb] == self.object_id}
|
33
|
-
end
|
34
|
-
|
35
|
-
def push(payload)
|
36
|
-
if payload.is_a? Array
|
37
|
-
payload.each {|p| queue.push(p) }
|
38
|
-
else
|
39
|
-
queue.push(payload)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def spawn_threads!
|
44
|
-
NUM_WORKER_THREADS.times do |thread_num|
|
45
|
-
log :debug, "Spawning background worker thread #{thread_num}."
|
46
|
-
|
47
|
-
Thread.new do
|
48
|
-
Thread.current[:influxdb] = self.object_id
|
49
|
-
|
50
|
-
while !client.stopped?
|
51
|
-
self.check_background_queue(thread_num)
|
52
|
-
sleep rand(SLEEP_INTERVAL)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def check_background_queue(thread_num = 0)
|
59
|
-
log :debug, "Checking background queue on thread #{thread_num} (#{self.current_thread_count} active)"
|
60
|
-
|
61
|
-
begin
|
62
|
-
data = []
|
63
|
-
|
64
|
-
while data.size < MAX_POST_POINTS && !@queue.empty?
|
65
|
-
p = @queue.pop(true) rescue next;
|
66
|
-
data.push p
|
67
|
-
end
|
68
|
-
|
69
|
-
return if data.empty?
|
70
|
-
|
71
|
-
begin
|
72
|
-
log :debug, "Found data in the queue! (#{data.length} points)"
|
73
|
-
@client._write(data)
|
74
|
-
rescue => e
|
75
|
-
puts "Cannot write data: #{e.inspect}"
|
76
|
-
end
|
77
|
-
end while @queue.length > MAX_POST_POINTS
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "json"
|
3
|
-
|
4
|
-
describe InfluxDB::UDPClient do
|
5
|
-
subject { described_class.new("localhost", 44444) }
|
6
|
-
let(:message) { [{ "foo" => "bar" }] }
|
7
|
-
|
8
|
-
describe "#send" do
|
9
|
-
it "sends a UPD packet" do
|
10
|
-
s = UDPSocket.new
|
11
|
-
s.bind("localhost", 44444)
|
12
|
-
subject.send(message)
|
13
|
-
rec_mesage = JSON.parse(s.recvfrom(15).first)
|
14
|
-
expect(rec_mesage).to eq message
|
15
|
-
end
|
16
|
-
|
17
|
-
context "it can't connect" do
|
18
|
-
before do
|
19
|
-
subject.socket = FailingSocket.new
|
20
|
-
end
|
21
|
-
|
22
|
-
it "doesn't blow up" do
|
23
|
-
expect { subject.send(message) }.to_not raise_error
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class FailingSocket < UDPSocket
|
28
|
-
def send(*args)
|
29
|
-
fail
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/spec/influxdb_spec.rb
DELETED
data/spec/max_queue_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe InfluxDB::MaxQueue do
|
4
|
-
it "should inherit from Queue" do
|
5
|
-
InfluxDB::MaxQueue.new.should be_a(Queue)
|
6
|
-
end
|
7
|
-
|
8
|
-
context "#new" do
|
9
|
-
it "should allow max_depth to be set" do
|
10
|
-
queue = InfluxDB::MaxQueue.new(500)
|
11
|
-
queue.max.should == 500
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "#push" do
|
16
|
-
it "should allow an item to be added if the queue is not full" do
|
17
|
-
queue = InfluxDB::MaxQueue.new(5)
|
18
|
-
queue.size.should be_zero
|
19
|
-
queue.push(1)
|
20
|
-
queue.size.should == 1
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should not allow items to be added if the queue is full" do
|
24
|
-
queue = InfluxDB::MaxQueue.new(5)
|
25
|
-
queue.size.should be_zero
|
26
|
-
5.times { |n| queue.push(n) }
|
27
|
-
queue.size.should == 5
|
28
|
-
queue.push(6)
|
29
|
-
queue.size.should == 5
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|