metriks 0.9.8.4 → 0.9.9
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.
- data/README.md +7 -5
- data/lib/metriks.rb +5 -1
- data/lib/metriks/registry.rb +19 -2
- data/lib/metriks/reporter/graphite.rb +6 -0
- data/lib/metriks/reporter/librato_metrics.rb +32 -7
- data/lib/metriks/reporter/logger.rb +9 -22
- data/lib/metriks/reporter/riemann.rb +6 -0
- data/lib/metriks/time_tracker.rb +26 -0
- data/metriks.gemspec +3 -2
- data/test/graphite_reporter_test.rb +1 -0
- data/test/librato_metrics_reporter_test.rb +1 -0
- data/test/logger_reporter_test.rb +1 -0
- data/test/metriks_test.rb +4 -0
- data/test/registry_test.rb +12 -0
- data/test/riemann_reporter_test.rb +8 -0
- metadata +4 -4
data/README.md
CHANGED
|
@@ -14,7 +14,9 @@ the gem.
|
|
|
14
14
|
|
|
15
15
|
To install, add this to your `Gemfile`:
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
``` ruby
|
|
18
|
+
gem 'metriks'
|
|
19
|
+
```
|
|
18
20
|
|
|
19
21
|
and re-run `bundle`.
|
|
20
22
|
|
|
@@ -287,7 +289,7 @@ How to get metrics out of the process.
|
|
|
287
289
|
|
|
288
290
|
Sends metrics to Graphite every 60 seconds.
|
|
289
291
|
|
|
290
|
-
```ruby
|
|
292
|
+
``` ruby
|
|
291
293
|
reporter = Metriks::Reporter::Graphite.new 'localhost', 3004
|
|
292
294
|
reporter.start
|
|
293
295
|
```
|
|
@@ -297,7 +299,7 @@ Sends metrics to Graphite every 60 seconds.
|
|
|
297
299
|
|
|
298
300
|
Send metrics to a logger every 60 seconds.
|
|
299
301
|
|
|
300
|
-
```
|
|
302
|
+
``` ruby
|
|
301
303
|
reporter = Metriks::Reporter::Logger.new(:logger => Logger.new('log/metrics.log'))
|
|
302
304
|
reporter.start
|
|
303
305
|
```
|
|
@@ -307,7 +309,7 @@ Send metrics to a logger every 60 seconds.
|
|
|
307
309
|
|
|
308
310
|
Send metrics to Librato Metrics every 60 seconds.
|
|
309
311
|
|
|
310
|
-
```
|
|
312
|
+
``` ruby
|
|
311
313
|
reporter = Metriks::Reporter::LibratoMetrics.new('email', 'token')
|
|
312
314
|
reporter.start
|
|
313
315
|
```
|
|
@@ -318,7 +320,7 @@ Send metrics to Librato Metrics every 60 seconds.
|
|
|
318
320
|
Provides a simple way to get up-to-date statistics from a process by
|
|
319
321
|
updating the proctitle every 5 seconds (default).
|
|
320
322
|
|
|
321
|
-
```ruby
|
|
323
|
+
``` ruby
|
|
322
324
|
reporter = Metriks::Reporter::ProcTitle.new :interval => 5
|
|
323
325
|
reporter.add 'reqs', 'sec' do
|
|
324
326
|
Metriks.meter('rack.requests').one_minute_rate
|
data/lib/metriks.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
module Metriks
|
|
3
|
-
VERSION = '0.9.
|
|
3
|
+
VERSION = '0.9.9'
|
|
4
4
|
|
|
5
5
|
def self.get(name)
|
|
6
6
|
Metriks::Registry.default.get(name)
|
|
@@ -21,6 +21,10 @@ module Metriks
|
|
|
21
21
|
def self.meter(name)
|
|
22
22
|
Metriks::Registry.default.meter(name)
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
def self.histogram(name)
|
|
26
|
+
Metriks::Registry.default.histogram(name)
|
|
27
|
+
end
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
require 'metriks/registry'
|
data/lib/metriks/registry.rb
CHANGED
|
@@ -120,6 +120,23 @@ module Metriks
|
|
|
120
120
|
add_or_get(name, Metriks::UtilizationTimer)
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
+
# Public: Fetch or create a new histogram metric. Histograms record values
|
|
124
|
+
# and expose statistics about the distribution of the data like median and
|
|
125
|
+
# 95th percentile.
|
|
126
|
+
#
|
|
127
|
+
# name - The String name of the metric to define or fetch
|
|
128
|
+
#
|
|
129
|
+
# Examples
|
|
130
|
+
#
|
|
131
|
+
# registry.histogram('backlog.wait')
|
|
132
|
+
#
|
|
133
|
+
# Returns the Metricks::Histogram identified by the name.
|
|
134
|
+
def histogram(name)
|
|
135
|
+
add_or_get(name, Metriks::Histogram) do
|
|
136
|
+
Metriks::Histogram.new_exponentially_decaying
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
123
140
|
# Public: Fetch an existing metric.
|
|
124
141
|
#
|
|
125
142
|
# name - The String name of the metric to fetch
|
|
@@ -157,7 +174,7 @@ module Metriks
|
|
|
157
174
|
end
|
|
158
175
|
|
|
159
176
|
protected
|
|
160
|
-
def add_or_get(name, klass)
|
|
177
|
+
def add_or_get(name, klass, &create_metric)
|
|
161
178
|
@mutex.synchronize do
|
|
162
179
|
if metric = @metrics[name]
|
|
163
180
|
if !metric.is_a?(klass)
|
|
@@ -166,7 +183,7 @@ module Metriks
|
|
|
166
183
|
return metric
|
|
167
184
|
end
|
|
168
185
|
else
|
|
169
|
-
@metrics[name] = klass.new
|
|
186
|
+
@metrics[name] = create_metric ? create_metric.call : klass.new
|
|
170
187
|
end
|
|
171
188
|
end
|
|
172
189
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'metriks/time_tracker'
|
|
1
2
|
require 'net/https'
|
|
2
3
|
|
|
3
4
|
module Metriks::Reporter
|
|
@@ -12,14 +13,14 @@ module Metriks::Reporter
|
|
|
12
13
|
@source = options[:source]
|
|
13
14
|
|
|
14
15
|
@registry = options[:registry] || Metriks::Registry.default
|
|
15
|
-
@
|
|
16
|
+
@time_tracker = Metriks::TimeTracker.new(options[:interval] || 60)
|
|
16
17
|
@on_error = options[:on_error] || proc { |ex| }
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def start
|
|
20
21
|
@thread ||= Thread.new do
|
|
21
22
|
loop do
|
|
22
|
-
sleep
|
|
23
|
+
@time_tracker.sleep
|
|
23
24
|
|
|
24
25
|
Thread.new do
|
|
25
26
|
begin
|
|
@@ -73,10 +74,20 @@ module Metriks::Reporter
|
|
|
73
74
|
], [
|
|
74
75
|
:median, :get_95th_percentile
|
|
75
76
|
]
|
|
77
|
+
when Metriks::Histogram
|
|
78
|
+
prepare_metric name, metric, [
|
|
79
|
+
:count, :min, :max, :mean, :stddev
|
|
80
|
+
], [
|
|
81
|
+
:median, :get_95th_percentile
|
|
82
|
+
]
|
|
76
83
|
end
|
|
77
84
|
end
|
|
78
85
|
|
|
79
|
-
|
|
86
|
+
gauges.flatten!
|
|
87
|
+
|
|
88
|
+
unless gauges.empty?
|
|
89
|
+
submit(form_data(gauges.flatten))
|
|
90
|
+
end
|
|
80
91
|
end
|
|
81
92
|
|
|
82
93
|
def submit(data)
|
|
@@ -100,9 +111,11 @@ module Metriks::Reporter
|
|
|
100
111
|
end
|
|
101
112
|
end
|
|
102
113
|
|
|
103
|
-
def form_data(
|
|
114
|
+
def form_data(metrics)
|
|
104
115
|
data = {}
|
|
105
116
|
|
|
117
|
+
gauges = metrics.select { |m| m[:type] == "gauge" }
|
|
118
|
+
|
|
106
119
|
gauges.each_with_index do |gauge, idx|
|
|
107
120
|
gauge.each do |key, value|
|
|
108
121
|
if value
|
|
@@ -111,12 +124,22 @@ module Metriks::Reporter
|
|
|
111
124
|
end
|
|
112
125
|
end
|
|
113
126
|
|
|
127
|
+
counters = metrics.select { |m| m[:type] == "counter" }
|
|
128
|
+
|
|
129
|
+
counters.each_with_index do |counter, idx|
|
|
130
|
+
counter.each do |key, value|
|
|
131
|
+
if value
|
|
132
|
+
data["counters[#{idx}][#{key}]"] = value.to_s
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
114
137
|
data
|
|
115
138
|
end
|
|
116
139
|
|
|
117
140
|
def prepare_metric(base_name, metric, keys, snapshot_keys = [])
|
|
118
141
|
results = []
|
|
119
|
-
time =
|
|
142
|
+
time = @time_tracker.now_floored
|
|
120
143
|
|
|
121
144
|
base_name = base_name.to_s.gsub(/ +/, '_')
|
|
122
145
|
if @prefix
|
|
@@ -128,9 +151,10 @@ module Metriks::Reporter
|
|
|
128
151
|
value = metric.send(key)
|
|
129
152
|
|
|
130
153
|
results << {
|
|
154
|
+
:type => name.to_s == "count" ? "counter" : "gauge",
|
|
131
155
|
:name => "#{base_name}.#{name}",
|
|
132
156
|
:source => @source,
|
|
133
|
-
:
|
|
157
|
+
:measure_time => time,
|
|
134
158
|
:value => value
|
|
135
159
|
}
|
|
136
160
|
end
|
|
@@ -142,9 +166,10 @@ module Metriks::Reporter
|
|
|
142
166
|
value = snapshot.send(key)
|
|
143
167
|
|
|
144
168
|
results << {
|
|
169
|
+
:type => name.to_s == "count" ? "counter" : "gauge",
|
|
145
170
|
:name => "#{base_name}.#{name}",
|
|
146
171
|
:source => @source,
|
|
147
|
-
:
|
|
172
|
+
:measure_time => time,
|
|
148
173
|
:value => value
|
|
149
174
|
}
|
|
150
175
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'logger'
|
|
2
|
+
require 'metriks/time_tracker'
|
|
2
3
|
|
|
3
4
|
module Metriks::Reporter
|
|
4
5
|
class Logger
|
|
@@ -10,7 +11,7 @@ module Metriks::Reporter
|
|
|
10
11
|
@prefix = options[:prefix] || 'metriks:'
|
|
11
12
|
|
|
12
13
|
@registry = options[:registry] || Metriks::Registry.default
|
|
13
|
-
@time_tracker = TimeTracker.new(options[:interval] || 60)
|
|
14
|
+
@time_tracker = Metriks::TimeTracker.new(options[:interval] || 60)
|
|
14
15
|
@on_error = options[:on_error] || proc { |ex| }
|
|
15
16
|
end
|
|
16
17
|
|
|
@@ -76,6 +77,12 @@ module Metriks::Reporter
|
|
|
76
77
|
], [
|
|
77
78
|
:median, :get_95th_percentile
|
|
78
79
|
]
|
|
80
|
+
when Metriks::Histogram
|
|
81
|
+
log_metric name, 'histogram', metric, [
|
|
82
|
+
:count, :min, :max, :mean, :stddev
|
|
83
|
+
], [
|
|
84
|
+
:median, :get_95th_percentile
|
|
85
|
+
]
|
|
79
86
|
end
|
|
80
87
|
end
|
|
81
88
|
end
|
|
@@ -114,25 +121,5 @@ module Metriks::Reporter
|
|
|
114
121
|
end
|
|
115
122
|
end.join(' ')
|
|
116
123
|
end
|
|
117
|
-
|
|
118
|
-
class TimeTracker
|
|
119
|
-
def initialize(interval)
|
|
120
|
-
@interval = interval
|
|
121
|
-
@next_time = Time.now.to_f
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def sleep
|
|
125
|
-
sleep_time = next_time - Time.now.to_f
|
|
126
|
-
if sleep_time > 0
|
|
127
|
-
Kernel.sleep(sleep_time)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def next_time
|
|
132
|
-
now = Time.now.to_f
|
|
133
|
-
@next_time = now if @next_time <= now
|
|
134
|
-
@next_time += @interval - (@next_time % @interval)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
124
|
end
|
|
138
|
-
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Metriks
|
|
2
|
+
class TimeTracker
|
|
3
|
+
def initialize(interval)
|
|
4
|
+
@interval = interval
|
|
5
|
+
@next_time = Time.now.to_f
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def sleep
|
|
9
|
+
sleep_time = next_time - Time.now.to_f
|
|
10
|
+
if sleep_time > 0
|
|
11
|
+
Kernel.sleep(sleep_time)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def now_floored
|
|
16
|
+
time = Time.now.to_i
|
|
17
|
+
time - (time % @interval)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def next_time
|
|
21
|
+
now = Time.now.to_f
|
|
22
|
+
@next_time = now if @next_time <= now
|
|
23
|
+
@next_time += @interval - (@next_time % @interval)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/metriks.gemspec
CHANGED
|
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
|
14
14
|
## the sub! line in the Rakefile
|
|
15
15
|
s.name = 'metriks'
|
|
16
|
-
s.version = '0.9.
|
|
17
|
-
s.date = '2012-
|
|
16
|
+
s.version = '0.9.9'
|
|
17
|
+
s.date = '2012-06-29'
|
|
18
18
|
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
|
20
20
|
## as you like.
|
|
@@ -72,6 +72,7 @@ Gem::Specification.new do |s|
|
|
|
72
72
|
lib/metriks/reporter/riemann.rb
|
|
73
73
|
lib/metriks/simple_moving_average.rb
|
|
74
74
|
lib/metriks/snapshot.rb
|
|
75
|
+
lib/metriks/time_tracker.rb
|
|
75
76
|
lib/metriks/timer.rb
|
|
76
77
|
lib/metriks/uniform_sample.rb
|
|
77
78
|
lib/metriks/utilization_timer.rb
|
|
@@ -27,6 +27,7 @@ class GraphiteReporterTest < Test::Unit::TestCase
|
|
|
27
27
|
@registry.meter('meter.testing').mark
|
|
28
28
|
@registry.counter('counter.testing').increment
|
|
29
29
|
@registry.timer('timer.testing').update(1.5)
|
|
30
|
+
@registry.histogram('histogram.testing').update(1.5)
|
|
30
31
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
31
32
|
|
|
32
33
|
@reporter.write
|
|
@@ -24,6 +24,7 @@ class LibratoMetricsReporterTest < Test::Unit::TestCase
|
|
|
24
24
|
@registry.meter('meter.testing').mark
|
|
25
25
|
@registry.counter('counter.testing').increment
|
|
26
26
|
@registry.timer('timer.testing').update(1.5)
|
|
27
|
+
@registry.histogram('histogram.testing').update(1.5)
|
|
27
28
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
28
29
|
|
|
29
30
|
@reporter.expects(:submit)
|
|
@@ -21,6 +21,7 @@ class LoggerReporterTest < Test::Unit::TestCase
|
|
|
21
21
|
@registry.meter('meter.testing').mark
|
|
22
22
|
@registry.counter('counter.testing').increment
|
|
23
23
|
@registry.timer('timer.testing').update(1.5)
|
|
24
|
+
@registry.histogram('histogram.testing').update(1.5)
|
|
24
25
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
25
26
|
end
|
|
26
27
|
|
data/test/metriks_test.rb
CHANGED
data/test/registry_test.rb
CHANGED
|
@@ -27,6 +27,18 @@ class RegistryTest < Test::Unit::TestCase
|
|
|
27
27
|
assert_not_nil @registry.utilization_timer('testing')
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def test_histogram
|
|
31
|
+
assert_not_nil @registry.histogram('testing')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_mismatched_metrics
|
|
35
|
+
@registry.histogram('histogram')
|
|
36
|
+
assert_raises(RuntimeError) { @registry.timer('histogram') }
|
|
37
|
+
|
|
38
|
+
@registry.timer('timer')
|
|
39
|
+
assert_raises(RuntimeError) { @registry.histogram('timer') }
|
|
40
|
+
end
|
|
41
|
+
|
|
30
42
|
def test_calling_counter_twice
|
|
31
43
|
assert_not_nil @registry.counter('testing')
|
|
32
44
|
end
|
|
@@ -34,6 +34,7 @@ class RiemannReporterTest < Test::Unit::TestCase
|
|
|
34
34
|
@registry.meter('meter.testing').mark
|
|
35
35
|
@registry.counter('counter.testing').increment
|
|
36
36
|
@registry.timer('timer.testing').update(1.5)
|
|
37
|
+
@registry.histogram('histogram.testing').update(1.5)
|
|
37
38
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
38
39
|
|
|
39
40
|
@reporter.client.expects(:<<).at_least_once
|
|
@@ -58,6 +59,13 @@ class RiemannReporterTest < Test::Unit::TestCase
|
|
|
58
59
|
:tags => ["timer"],
|
|
59
60
|
:ttl => 90
|
|
60
61
|
)
|
|
62
|
+
@reporter.client.expects(:<<).with(
|
|
63
|
+
:host => "h",
|
|
64
|
+
:service => "histogram.testing max",
|
|
65
|
+
:metric => 1.5,
|
|
66
|
+
:tags => ["histogram"],
|
|
67
|
+
:ttl => 90
|
|
68
|
+
)
|
|
61
69
|
@reporter.client.expects(:<<).with(
|
|
62
70
|
:host => "h",
|
|
63
71
|
:service => "utilization_timer.testing mean",
|
metadata
CHANGED
|
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 9
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
version: 0.9.8.4
|
|
8
|
+
- 9
|
|
9
|
+
version: 0.9.9
|
|
11
10
|
platform: ruby
|
|
12
11
|
authors:
|
|
13
12
|
- Eric Lindvall
|
|
@@ -15,7 +14,7 @@ autorequire:
|
|
|
15
14
|
bindir: bin
|
|
16
15
|
cert_chain: []
|
|
17
16
|
|
|
18
|
-
date: 2012-
|
|
17
|
+
date: 2012-06-29 00:00:00 -07:00
|
|
19
18
|
default_executable:
|
|
20
19
|
dependencies:
|
|
21
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -100,6 +99,7 @@ files:
|
|
|
100
99
|
- lib/metriks/reporter/riemann.rb
|
|
101
100
|
- lib/metriks/simple_moving_average.rb
|
|
102
101
|
- lib/metriks/snapshot.rb
|
|
102
|
+
- lib/metriks/time_tracker.rb
|
|
103
103
|
- lib/metriks/timer.rb
|
|
104
104
|
- lib/metriks/uniform_sample.rb
|
|
105
105
|
- lib/metriks/utilization_timer.rb
|