graphite-api 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/graphite-api.rb +0 -1
- data/lib/graphite-api/buffer.rb +6 -3
- data/lib/graphite-api/cache.rb +5 -2
- data/lib/graphite-api/client.rb +15 -6
- data/lib/graphite-api/core_ext/numeric.rb +20 -1
- data/lib/graphite-api/version.rb +1 -1
- metadata +107 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0595ca2197bbdfe81fd61a7fc06f4949adea392b2c3ca7aee0d4c461eccb7479'
|
4
|
+
data.tar.gz: 4a8df14d1e1f7a7a39fde283eae647668f08c6ce4005a5dc4e435153cba417d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5373a60c92806962795637d6ab23bedf523db35a02fcaf6ae8f99b699c8f0e97e3aed3d952e03b891db1dde3c9388a7224a9753871b0b05f76be39bbd13730c5
|
7
|
+
data.tar.gz: 8148064e7eeeaa35847b8f50dc153cb33aa13277f2cab8b25a8c6d3570eb1bd33c59845550d2d7c25cdd58465305f24ee2d0d5df0e1362943b86a9ac2a40a287
|
data/README.md
CHANGED
@@ -175,6 +175,30 @@ client.every 52.minutes do |c|
|
|
175
175
|
end
|
176
176
|
```
|
177
177
|
|
178
|
+
Stopping the client loop
|
179
|
+
```ruby
|
180
|
+
require 'graphite-api'
|
181
|
+
|
182
|
+
client = GraphiteAPI.new( graphite: 'tcp://graphite:2003' )
|
183
|
+
|
184
|
+
# Lets send the metric every 2 minutes.
|
185
|
+
client.every(2.minutes) do |c|
|
186
|
+
c.metrics("webServer.web01.uptime" => `uptime`.split.first.to_i)
|
187
|
+
end
|
188
|
+
|
189
|
+
sleep 2.minutes # Client will send one message.
|
190
|
+
|
191
|
+
client.pause
|
192
|
+
sleep 6.minutes # Client will not send any messages.
|
193
|
+
|
194
|
+
client.resume
|
195
|
+
sleep 4.minutes # Client will send 2 messages.
|
196
|
+
|
197
|
+
client.cancel
|
198
|
+
client.resume
|
199
|
+
sleep 6.minutes # After cancel, client will not send any more messages.
|
200
|
+
```
|
201
|
+
|
178
202
|
Make your own custom metrics daemons, using `client#join`
|
179
203
|
```ruby
|
180
204
|
require 'graphite-api'
|
data/lib/graphite-api.rb
CHANGED
data/lib/graphite-api/buffer.rb
CHANGED
@@ -24,7 +24,10 @@ module GraphiteAPI
|
|
24
24
|
|
25
25
|
IGNORE = ["\r"]
|
26
26
|
END_OF_STREAM = "\n"
|
27
|
-
|
27
|
+
|
28
|
+
# Matches the metric name (string with dots and dashes), at least one space, the metric value (int or float),
|
29
|
+
# at least one space and finally the metric timestamp (int)
|
30
|
+
VALID_MESSAGE = /^[\w.-]+ +\d+(?:\.\d+)? +\d+$/
|
28
31
|
|
29
32
|
AGGREGATORS = {
|
30
33
|
sum: ->(*args) { args.reduce(0) { |sum, x| sum + x } },
|
@@ -32,11 +35,11 @@ module GraphiteAPI
|
|
32
35
|
replace: ->(*args) { args.last },
|
33
36
|
}
|
34
37
|
|
35
|
-
def initialize options
|
38
|
+
def initialize options, timers=false
|
36
39
|
@options = options
|
37
40
|
@queue = Queue.new
|
38
41
|
@streamer = Hash.new {|h,k| h[k] = ""}
|
39
|
-
@cache = Cache::Memory.new(options) if options[:cache]
|
42
|
+
@cache = Cache::Memory.new(options, timers) if options[:cache]
|
40
43
|
end
|
41
44
|
|
42
45
|
attr_reader :queue, :options, :streamer, :cache
|
data/lib/graphite-api/cache.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'timers'
|
2
|
+
|
1
3
|
module GraphiteAPI
|
2
4
|
module Cache
|
3
5
|
class Memory
|
6
|
+
extend Forwardable
|
4
7
|
|
5
|
-
def initialize options
|
6
|
-
|
8
|
+
def initialize options, timers=false
|
9
|
+
timers.every(120) { clean(options[:cache]) } if timers
|
7
10
|
end
|
8
11
|
|
9
12
|
def get time, key
|
data/lib/graphite-api/client.rb
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
require 'thread'
|
3
|
+
require 'timers'
|
3
4
|
|
4
5
|
module GraphiteAPI
|
5
6
|
class Client
|
6
7
|
extend Forwardable
|
7
8
|
|
8
|
-
def_delegator
|
9
|
+
def_delegator :timers, :cancel
|
10
|
+
def_delegator :timers, :pause
|
11
|
+
def_delegator :timers, :resume
|
12
|
+
|
13
|
+
def_delegator :buffer, :stream
|
9
14
|
|
10
15
|
attr_reader :options, :buffer, :connectors, :mu
|
11
16
|
private :options, :buffer, :connectors, :mu
|
12
17
|
|
13
18
|
def initialize opt
|
14
19
|
@options = build_options validate opt.clone
|
15
|
-
@buffer = GraphiteAPI::Buffer.new options
|
20
|
+
@buffer = GraphiteAPI::Buffer.new options, timers
|
16
21
|
@connectors = GraphiteAPI::Connector::Group.new options
|
17
22
|
@mu = Mutex.new
|
18
23
|
|
19
|
-
|
24
|
+
timers.every(options[:interval], true, &method(:send_metrics!)) unless options[:direct]
|
25
|
+
end
|
26
|
+
|
27
|
+
def timers
|
28
|
+
@timers ||= Timers::Group.new.tap {|t| Thread.new { loop { t.wait } } }
|
20
29
|
end
|
21
30
|
|
22
31
|
# throw exception on Socket error
|
@@ -25,7 +34,7 @@ module GraphiteAPI
|
|
25
34
|
end
|
26
35
|
|
27
36
|
def every interval, &block
|
28
|
-
|
37
|
+
@timers.every(interval) { block.arity == 1 ? block.call(self) : block.call }
|
29
38
|
end
|
30
39
|
|
31
40
|
def metrics metric, time = nil, aggregation_method = nil
|
@@ -73,14 +82,14 @@ module GraphiteAPI
|
|
73
82
|
|
74
83
|
def build_options opt
|
75
84
|
self.class.default_options.tap do |options_hash|
|
76
|
-
options_hash[:backends]
|
85
|
+
options_hash[:backends] = Array(opt.delete :graphite)
|
77
86
|
options_hash.merge! opt
|
78
87
|
options_hash[:direct] = options_hash[:interval] == 0
|
79
88
|
options_hash[:slice] = 1 if options_hash[:direct]
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
83
|
-
def send_metrics!
|
92
|
+
def send_metrics! *_
|
84
93
|
mu.synchronize { connectors.publish buffer.pull :string if buffer.new_records? }
|
85
94
|
end
|
86
95
|
|
@@ -1 +1,20 @@
|
|
1
|
-
|
1
|
+
class Numeric
|
2
|
+
{
|
3
|
+
:year => 365 * 24 * 3600,
|
4
|
+
:month => 30 * 24 * 3600,
|
5
|
+
:week => 7 * 24 * 3600,
|
6
|
+
:day => 24 * 3600,
|
7
|
+
:hour => 3600,
|
8
|
+
:minute => 60,
|
9
|
+
:second => 1
|
10
|
+
}.each do |m, val|
|
11
|
+
respond_to? m or define_method m do
|
12
|
+
self * val
|
13
|
+
end
|
14
|
+
|
15
|
+
"#{m}s".tap do |plural|
|
16
|
+
respond_to? plural or alias_method plural, m
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/graphite-api/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,141 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphite-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eran Barak Levi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: timers
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.2.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: eventmachine
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
16
58
|
requirements:
|
17
59
|
- - ">="
|
18
60
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
20
|
-
type: :
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
21
63
|
prerelease: false
|
22
64
|
version_requirements: !ruby/object:Gem::Requirement
|
23
65
|
requirements:
|
24
66
|
- - ">="
|
25
67
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
70
|
+
name: mocha
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
73
|
- - ">="
|
32
74
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
34
|
-
type: :
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
35
77
|
prerelease: false
|
36
78
|
version_requirements: !ruby/object:Gem::Requirement
|
37
79
|
requirements:
|
38
80
|
- - ">="
|
39
81
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov-rcov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: gem-release
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.0'
|
41
139
|
description: Graphite API - A Simple ruby client, aggregator daemon and API tools
|
42
140
|
email: eran@kontera.com
|
43
141
|
executables: []
|