us-carbon 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/carbon/reader.rb +86 -0
- data/lib/carbon/writer.rb +35 -0
- data/lib/version.rb +3 -0
- data/us-carbon.gemspec +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daf77aaea2d492588e16f2b14f6327612593667d
|
4
|
+
data.tar.gz: ddea4d861ccf8da4328e0af015a9154ee55c8e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee6fd1f75d8a31a08839b534b831925d8cbf106329708678af4f4c051e515e58095e650d4baf78d5bdfba21f4b427e03b79b94f5d1def7e18a551b1207b5c108
|
7
|
+
data.tar.gz: 2816ccbe944e48dd19664733b788cf1e41c4764775cfd722cf96f296e1684068c881af2d75bbc666a03b1f60268877b247d21a94a9e9e4867623d4a0a235706f
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Carbon
|
2
|
+
class Reader
|
3
|
+
def initialize(hostname, port, logger)
|
4
|
+
@queue = FetchQueue.new
|
5
|
+
@logger = logger
|
6
|
+
connection = EM::connect(hostname, port, ServerProtocol, @queue, @logger)
|
7
|
+
end
|
8
|
+
|
9
|
+
def fetch(query, &callback)
|
10
|
+
@queue.push([query, callback])
|
11
|
+
end
|
12
|
+
|
13
|
+
class FetchQueue
|
14
|
+
def initialize
|
15
|
+
@queue = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def push(value)
|
19
|
+
EM::next_tick do
|
20
|
+
@queue.push(value)
|
21
|
+
@on_push[]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def shift
|
26
|
+
@queue.shift
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_push(&block)
|
30
|
+
@on_push = block
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module ServerProtocol
|
35
|
+
include EventMachine::Protocols::LineText2
|
36
|
+
|
37
|
+
attr_accessor :logger
|
38
|
+
|
39
|
+
def initialize(queue,logger)
|
40
|
+
set_delimiter ';'
|
41
|
+
@queue = queue
|
42
|
+
@callback = nil
|
43
|
+
@logger = logger
|
44
|
+
@queue.on_push do
|
45
|
+
next_action() if @callback.nil?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def receive_data(data)
|
50
|
+
#logger.debug "Carbon_server_connection got data: #{data}"
|
51
|
+
super(data)
|
52
|
+
end
|
53
|
+
|
54
|
+
def receive_line(line)
|
55
|
+
#logger.debug "Carbon_server_connection got line: #{line}"
|
56
|
+
@callback[line] unless @callback.nil?
|
57
|
+
@callback = nil
|
58
|
+
next_action()
|
59
|
+
end
|
60
|
+
|
61
|
+
def next_action()
|
62
|
+
action = @queue.shift()
|
63
|
+
return if action.nil?
|
64
|
+
|
65
|
+
query = action[0]
|
66
|
+
@callback = action[1]
|
67
|
+
|
68
|
+
request = "get-metric #{query['path']} #{query['start']} #{query['end']}"
|
69
|
+
send_line request
|
70
|
+
end
|
71
|
+
|
72
|
+
def send_line(data)
|
73
|
+
#logger.debug "Carbon_server_connection sending line: #{data}"
|
74
|
+
send_data "#{data};"
|
75
|
+
end
|
76
|
+
|
77
|
+
def connection_completed
|
78
|
+
logger.info "Connected to CarbonServer"
|
79
|
+
end
|
80
|
+
|
81
|
+
def unbind
|
82
|
+
logger.info "Closing CarbonServer connection"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Carbon
|
2
|
+
class Writer
|
3
|
+
def initialize(host, port, logger)
|
4
|
+
@host = host
|
5
|
+
@port = port
|
6
|
+
@logger = logger
|
7
|
+
@retries = 0
|
8
|
+
make_connection()
|
9
|
+
end
|
10
|
+
|
11
|
+
def make_connection
|
12
|
+
@connection = TCPSocket.open(@host, @port)
|
13
|
+
end
|
14
|
+
|
15
|
+
def close_connection
|
16
|
+
begin
|
17
|
+
@connection.close()
|
18
|
+
rescue SocketError => e
|
19
|
+
puts "Exception closing Carbon connection: #{e.message}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_metric(group, node, name, timestamp, value)
|
24
|
+
command = "us-metrics.#{group}.#{node}.#{name} #{value} #{timestamp}"
|
25
|
+
#@logger.info "EXECUTING CARBON COMMAND: #{command}"
|
26
|
+
@connection.puts command
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_aggregated_metric(group, name, timestamp, value)
|
30
|
+
command = "us-metrics.#{group}.#{name} #{value} #{timestamp}"
|
31
|
+
#@logger.info "EXECUTING CARBON COMMAND: #{command}"
|
32
|
+
@connection.puts command
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/version.rb
ADDED
data/us-carbon.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.summary = 'Carbon client of the Union Station system.'
|
15
15
|
s.description = 'Carbon client of the Union Station system.'
|
16
16
|
|
17
|
-
s.files =['us-carbon.gemspec','README.md']
|
17
|
+
s.files = Dir["{lib}/**/*"] + ['us-carbon.gemspec','README.md']
|
18
18
|
|
19
19
|
s.add_runtime_dependency 'eventmachine'
|
20
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: us-carbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phusion
|
@@ -32,6 +32,9 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- README.md
|
35
|
+
- lib/carbon/reader.rb
|
36
|
+
- lib/carbon/writer.rb
|
37
|
+
- lib/version.rb
|
35
38
|
- us-carbon.gemspec
|
36
39
|
homepage: https://www.unionstationapp.com/
|
37
40
|
licenses: []
|