metriks 0.9.9.4 → 0.9.9.5
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 +43 -0
- data/lib/metriks.rb +5 -1
- data/lib/metriks/gauge.rb +27 -0
- data/lib/metriks/registry.rb +22 -6
- data/lib/metriks/reporter/graphite.rb +4 -0
- data/lib/metriks/reporter/librato_metrics.rb +4 -0
- data/lib/metriks/reporter/logger.rb +4 -0
- data/lib/metriks/reporter/riemann.rb +5 -1
- data/metriks.gemspec +4 -2
- data/test/gauge_test.rb +46 -0
- data/test/graphite_reporter_test.rb +5 -1
- data/test/librato_metrics_reporter_test.rb +2 -1
- data/test/logger_reporter_test.rb +4 -1
- data/test/riemann_reporter_test.rb +9 -0
- metadata +6 -3
data/README.md
CHANGED
|
@@ -56,6 +56,45 @@ Return the current value of the counter.
|
|
|
56
56
|
puts "counter: #{counter.count}"
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
## Gauges
|
|
60
|
+
|
|
61
|
+
A gauge is an instantaneous measurement of a value.
|
|
62
|
+
|
|
63
|
+
It takes a callback to measure the value in form of a block or a callable
|
|
64
|
+
object.
|
|
65
|
+
|
|
66
|
+
**WARNING:** The code in the callback is executed every time the `#value`
|
|
67
|
+
method is called on the gauge. Most of the time this will be done by a
|
|
68
|
+
metriks reporter that is running in a separate thread.
|
|
69
|
+
|
|
70
|
+
``` ruby
|
|
71
|
+
# Callback as block
|
|
72
|
+
gauge = Metriks.gauge('queue.size') { queue.size }
|
|
73
|
+
|
|
74
|
+
# Callback as object responding to #call
|
|
75
|
+
callable = proc { queue.size }
|
|
76
|
+
gauge = Metriks.gauge('queue.size', callable)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### set(val)
|
|
80
|
+
|
|
81
|
+
Set the current value.
|
|
82
|
+
|
|
83
|
+
``` ruby
|
|
84
|
+
gauge = Metriks.gauge('queue_size')
|
|
85
|
+
gauge.set(queue.size)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### value()
|
|
89
|
+
|
|
90
|
+
Returns the value returned by the callback (if one is defined), returns the
|
|
91
|
+
value set via `#set` (or the default of 0) otherwise.
|
|
92
|
+
|
|
93
|
+
``` ruby
|
|
94
|
+
gauge = Metriks.gauge('queue_size')
|
|
95
|
+
puts "queue size: #{gauge.value}"
|
|
96
|
+
```
|
|
97
|
+
|
|
59
98
|
## Meters
|
|
60
99
|
|
|
61
100
|
A meter that measures the mean throughput and the one-, five-, and
|
|
@@ -334,6 +373,10 @@ will display:
|
|
|
334
373
|
501 17015 26.0 1.9 416976 246956 ? Ss 18:54 11:43 thin reqs: 273.3/sec
|
|
335
374
|
```
|
|
336
375
|
|
|
376
|
+
## Sematext Metrics Reporter
|
|
377
|
+
|
|
378
|
+
[metriks-sematext](https://github.com/sematext/metriks-sematext) gem provides reporter for sending metrics to [SPM](http://sematext.com/spm/index.html).
|
|
379
|
+
|
|
337
380
|
# Application Server Configuration
|
|
338
381
|
|
|
339
382
|
Depending on how your application server operates, you may need to configure how reporters are created. Please look at [Troubleshooting](https://github.com/eric/metriks/wiki/Troubleshooting) for more information.
|
data/lib/metriks.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
module Metriks
|
|
3
|
-
VERSION = '0.9.9.
|
|
3
|
+
VERSION = '0.9.9.5'
|
|
4
4
|
|
|
5
5
|
def self.get(name)
|
|
6
6
|
Metriks::Registry.default.get(name)
|
|
@@ -10,6 +10,10 @@ module Metriks
|
|
|
10
10
|
Metriks::Registry.default.counter(name)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
def self.gauge(name, callable = nil, &block)
|
|
14
|
+
Metriks::Registry.default.gauge(name, callable, &block)
|
|
15
|
+
end
|
|
16
|
+
|
|
13
17
|
def self.timer(name)
|
|
14
18
|
Metriks::Registry.default.timer(name)
|
|
15
19
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'atomic'
|
|
2
|
+
|
|
3
|
+
module Metriks
|
|
4
|
+
class Gauge
|
|
5
|
+
# Public: Initialize a new Gauge.
|
|
6
|
+
def initialize(callable = nil, &block)
|
|
7
|
+
@gauge = Atomic.new(nil)
|
|
8
|
+
@callback = callable || block
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Public: Set a new value.
|
|
12
|
+
#
|
|
13
|
+
# val - The new value.
|
|
14
|
+
#
|
|
15
|
+
# Returns nothing.
|
|
16
|
+
def set(val)
|
|
17
|
+
@gauge.value = val
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Public: The current value.
|
|
21
|
+
#
|
|
22
|
+
# Returns the gauge value.
|
|
23
|
+
def value
|
|
24
|
+
@callback ? @callback.call : @gauge.value
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/metriks/registry.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'metriks/counter'
|
|
|
2
2
|
require 'metriks/timer'
|
|
3
3
|
require 'metriks/utilization_timer'
|
|
4
4
|
require 'metriks/meter'
|
|
5
|
+
require 'metriks/gauge'
|
|
5
6
|
|
|
6
7
|
module Metriks
|
|
7
8
|
# Public: A collection of metrics
|
|
@@ -67,11 +68,26 @@ module Metriks
|
|
|
67
68
|
#
|
|
68
69
|
# registry.counter('method.calls')
|
|
69
70
|
#
|
|
70
|
-
# Returns the
|
|
71
|
+
# Returns the Metriks::Counter identified by the name.
|
|
71
72
|
def counter(name)
|
|
72
73
|
add_or_get(name, Metriks::Counter)
|
|
73
74
|
end
|
|
74
75
|
|
|
76
|
+
# Public: Fetch or create a new gauge metric.
|
|
77
|
+
#
|
|
78
|
+
# name - The String name of the metric to define or fetch
|
|
79
|
+
#
|
|
80
|
+
# Examples
|
|
81
|
+
#
|
|
82
|
+
# registry.gauge('disk_space.used') { 1 }
|
|
83
|
+
#
|
|
84
|
+
# Returns the Metriks::Gauge identified by the name.
|
|
85
|
+
def gauge(name, callable = nil, &block)
|
|
86
|
+
add_or_get(name, Metriks::Gauge) do
|
|
87
|
+
Metriks::Gauge.new(callable, &block)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
75
91
|
# Public: Fetch or create a new meter metric. Meters are a counter that
|
|
76
92
|
# tracks throughput along with the count.
|
|
77
93
|
#
|
|
@@ -81,7 +97,7 @@ module Metriks
|
|
|
81
97
|
#
|
|
82
98
|
# registry.meter('resque.calls')
|
|
83
99
|
#
|
|
84
|
-
# Returns the
|
|
100
|
+
# Returns the Metriks::Meter identified by the name.
|
|
85
101
|
def meter(name)
|
|
86
102
|
add_or_get(name, Metriks::Meter)
|
|
87
103
|
end
|
|
@@ -96,7 +112,7 @@ module Metriks
|
|
|
96
112
|
#
|
|
97
113
|
# registry.timer('resque.worker')
|
|
98
114
|
#
|
|
99
|
-
# Returns the
|
|
115
|
+
# Returns the Metriks::Timer identified by the name.
|
|
100
116
|
def timer(name)
|
|
101
117
|
add_or_get(name, Metriks::Timer)
|
|
102
118
|
end
|
|
@@ -115,7 +131,7 @@ module Metriks
|
|
|
115
131
|
#
|
|
116
132
|
# registry.utilization_timer('rack.utilization')
|
|
117
133
|
#
|
|
118
|
-
# Returns the
|
|
134
|
+
# Returns the Metriks::UtilizationTimer identified by the name.
|
|
119
135
|
def utilization_timer(name)
|
|
120
136
|
add_or_get(name, Metriks::UtilizationTimer)
|
|
121
137
|
end
|
|
@@ -130,7 +146,7 @@ module Metriks
|
|
|
130
146
|
#
|
|
131
147
|
# registry.histogram('backlog.wait')
|
|
132
148
|
#
|
|
133
|
-
# Returns the
|
|
149
|
+
# Returns the Metriks::Histogram identified by the name.
|
|
134
150
|
def histogram(name)
|
|
135
151
|
add_or_get(name, Metriks::Histogram) do
|
|
136
152
|
Metriks::Histogram.new_exponentially_decaying
|
|
@@ -188,4 +204,4 @@ module Metriks
|
|
|
188
204
|
end
|
|
189
205
|
end
|
|
190
206
|
end
|
|
191
|
-
end
|
|
207
|
+
end
|
|
@@ -58,6 +58,10 @@ module Metriks::Reporter
|
|
|
58
58
|
write_metric name, metric, [
|
|
59
59
|
:count
|
|
60
60
|
]
|
|
61
|
+
when Metriks::Gauge
|
|
62
|
+
write_metric name, metric, [
|
|
63
|
+
:value
|
|
64
|
+
]
|
|
61
65
|
when Metriks::UtilizationTimer
|
|
62
66
|
write_metric name, metric, [
|
|
63
67
|
:count, :one_minute_rate, :five_minute_rate,
|
|
@@ -56,6 +56,10 @@ module Metriks::Reporter
|
|
|
56
56
|
prepare_metric name, metric, [
|
|
57
57
|
:count
|
|
58
58
|
]
|
|
59
|
+
when Metriks::Gauge
|
|
60
|
+
prepare_metric name, metric, [
|
|
61
|
+
:value
|
|
62
|
+
]
|
|
59
63
|
when Metriks::UtilizationTimer
|
|
60
64
|
prepare_metric name, metric, [
|
|
61
65
|
:count, :one_minute_rate, :five_minute_rate,
|
|
@@ -59,6 +59,10 @@ module Metriks::Reporter
|
|
|
59
59
|
log_metric name, 'counter', metric, [
|
|
60
60
|
:count
|
|
61
61
|
]
|
|
62
|
+
when Metriks::Gauge
|
|
63
|
+
log_metric name, 'gauge', metric, [
|
|
64
|
+
:value
|
|
65
|
+
]
|
|
62
66
|
when Metriks::UtilizationTimer
|
|
63
67
|
log_metric name, 'utilization_timer', metric, [
|
|
64
68
|
:count, :one_minute_rate, :five_minute_rate,
|
|
@@ -8,7 +8,7 @@ module Metriks::Reporter
|
|
|
8
8
|
:host => options[:host],
|
|
9
9
|
:port => options[:port]
|
|
10
10
|
)
|
|
11
|
-
@registry = options[:registry] ||
|
|
11
|
+
@registry = options[:registry] || Metriks::Registry.default
|
|
12
12
|
@interval = options[:interval] || 60
|
|
13
13
|
@on_error = options[:on_error] || proc { |ex| }
|
|
14
14
|
|
|
@@ -63,6 +63,10 @@ module Metriks::Reporter
|
|
|
63
63
|
send_metric name, 'counter', metric, [
|
|
64
64
|
:count
|
|
65
65
|
]
|
|
66
|
+
when Metriks::Gauge
|
|
67
|
+
send_metric name, 'gauge', metric, [
|
|
68
|
+
:value
|
|
69
|
+
]
|
|
66
70
|
when Metriks::UtilizationTimer
|
|
67
71
|
send_metric name, 'utilization_timer', metric, [
|
|
68
72
|
:count, :one_minute_rate, :five_minute_rate,
|
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.9.
|
|
17
|
-
s.date = '2013-
|
|
16
|
+
s.version = '0.9.9.5'
|
|
17
|
+
s.date = '2013-07-05'
|
|
18
18
|
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
|
20
20
|
## as you like.
|
|
@@ -62,6 +62,7 @@ Gem::Specification.new do |s|
|
|
|
62
62
|
lib/metriks/counter.rb
|
|
63
63
|
lib/metriks/ewma.rb
|
|
64
64
|
lib/metriks/exponentially_decaying_sample.rb
|
|
65
|
+
lib/metriks/gauge.rb
|
|
65
66
|
lib/metriks/histogram.rb
|
|
66
67
|
lib/metriks/meter.rb
|
|
67
68
|
lib/metriks/registry.rb
|
|
@@ -78,6 +79,7 @@ Gem::Specification.new do |s|
|
|
|
78
79
|
lib/metriks/utilization_timer.rb
|
|
79
80
|
metriks.gemspec
|
|
80
81
|
test/counter_test.rb
|
|
82
|
+
test/gauge_test.rb
|
|
81
83
|
test/graphite_reporter_test.rb
|
|
82
84
|
test/histogram_test.rb
|
|
83
85
|
test/librato_metrics_reporter_test.rb
|
data/test/gauge_test.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
require 'metriks/gauge'
|
|
4
|
+
|
|
5
|
+
class GaugeTest < Test::Unit::TestCase
|
|
6
|
+
def test_gauge
|
|
7
|
+
gauge = Metriks::Gauge.new
|
|
8
|
+
|
|
9
|
+
3.times do |i|
|
|
10
|
+
gauge.set(i + 1)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
assert_equal 3, gauge.value
|
|
14
|
+
|
|
15
|
+
gauge.set(1)
|
|
16
|
+
|
|
17
|
+
assert_equal 1, gauge.value
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_gauge_default
|
|
21
|
+
gauge = Metriks::Gauge.new
|
|
22
|
+
assert_equal nil, gauge.value
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_gauge_callback_via_block
|
|
26
|
+
gauge = Metriks::Gauge.new { 56 }
|
|
27
|
+
|
|
28
|
+
assert_equal 56, gauge.value
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_gauge_callback_via_callable_object
|
|
32
|
+
callable = Class.new(Struct.new(:value)) {
|
|
33
|
+
def call
|
|
34
|
+
value
|
|
35
|
+
end
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
gauge = Metriks::Gauge.new(callable.new(987))
|
|
39
|
+
|
|
40
|
+
assert_equal 987, gauge.value
|
|
41
|
+
|
|
42
|
+
gauge = Metriks::Gauge.new(proc { 123 })
|
|
43
|
+
|
|
44
|
+
assert_equal 123, gauge.value
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -29,9 +29,13 @@ class GraphiteReporterTest < Test::Unit::TestCase
|
|
|
29
29
|
@registry.timer('timer.testing').update(1.5)
|
|
30
30
|
@registry.histogram('histogram.testing').update(1.5)
|
|
31
31
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
32
|
+
@registry.gauge('gauge.testing').set(123)
|
|
33
|
+
@registry.gauge('gauge.testing.block') { 456 }
|
|
32
34
|
|
|
33
35
|
@reporter.write
|
|
34
36
|
|
|
35
37
|
assert_match /timer.testing.median \d/, @stringio.string
|
|
38
|
+
assert_match /gauge.testing.value 123/, @stringio.string
|
|
39
|
+
assert_match /gauge.testing.block.value 456/, @stringio.string
|
|
36
40
|
end
|
|
37
|
-
end
|
|
41
|
+
end
|
|
@@ -26,9 +26,10 @@ class LibratoMetricsReporterTest < Test::Unit::TestCase
|
|
|
26
26
|
@registry.timer('timer.testing').update(1.5)
|
|
27
27
|
@registry.histogram('histogram.testing').update(1.5)
|
|
28
28
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
29
|
+
@registry.gauge('gauge.testing') { 123 }
|
|
29
30
|
|
|
30
31
|
@reporter.expects(:submit)
|
|
31
32
|
|
|
32
33
|
@reporter.write
|
|
33
34
|
end
|
|
34
|
-
end
|
|
35
|
+
end
|
|
@@ -23,6 +23,7 @@ class LoggerReporterTest < Test::Unit::TestCase
|
|
|
23
23
|
@registry.timer('timer.testing').update(1.5)
|
|
24
24
|
@registry.histogram('histogram.testing').update(1.5)
|
|
25
25
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
26
|
+
@registry.gauge('gauge.testing').set(123)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def teardown
|
|
@@ -35,6 +36,7 @@ class LoggerReporterTest < Test::Unit::TestCase
|
|
|
35
36
|
|
|
36
37
|
assert_match /time=\d/, @stringio.string
|
|
37
38
|
assert_match /median=\d/, @stringio.string
|
|
39
|
+
assert_match /value=123/, @stringio.string
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def test_flush
|
|
@@ -42,5 +44,6 @@ class LoggerReporterTest < Test::Unit::TestCase
|
|
|
42
44
|
|
|
43
45
|
assert_match /time=\d/, @stringio.string
|
|
44
46
|
assert_match /median=\d/, @stringio.string
|
|
47
|
+
assert_match /value=123/, @stringio.string
|
|
45
48
|
end
|
|
46
|
-
end
|
|
49
|
+
end
|
|
@@ -36,6 +36,7 @@ class RiemannReporterTest < Test::Unit::TestCase
|
|
|
36
36
|
@registry.timer('timer.testing').update(1.5)
|
|
37
37
|
@registry.histogram('histogram.testing').update(1.5)
|
|
38
38
|
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
|
39
|
+
@registry.gauge('gauge.testing') { 123 }
|
|
39
40
|
|
|
40
41
|
@reporter.client.expects(:<<).at_least_once
|
|
41
42
|
@reporter.client.expects(:<<).with(
|
|
@@ -74,6 +75,14 @@ class RiemannReporterTest < Test::Unit::TestCase
|
|
|
74
75
|
:ttl => 90
|
|
75
76
|
)
|
|
76
77
|
|
|
78
|
+
@reporter.client.expects(:<<).with(
|
|
79
|
+
:host => "h",
|
|
80
|
+
:service => "gauge.testing value",
|
|
81
|
+
:metric => 123,
|
|
82
|
+
:tags => ["gauge"],
|
|
83
|
+
:ttl => 90
|
|
84
|
+
)
|
|
85
|
+
|
|
77
86
|
@reporter.write
|
|
78
87
|
end
|
|
79
88
|
end
|
metadata
CHANGED
|
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
|
6
6
|
- 0
|
|
7
7
|
- 9
|
|
8
8
|
- 9
|
|
9
|
-
-
|
|
10
|
-
version: 0.9.9.
|
|
9
|
+
- 5
|
|
10
|
+
version: 0.9.9.5
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Eric Lindvall
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2013-
|
|
18
|
+
date: 2013-07-05 00:00:00 -07:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -90,6 +90,7 @@ files:
|
|
|
90
90
|
- lib/metriks/counter.rb
|
|
91
91
|
- lib/metriks/ewma.rb
|
|
92
92
|
- lib/metriks/exponentially_decaying_sample.rb
|
|
93
|
+
- lib/metriks/gauge.rb
|
|
93
94
|
- lib/metriks/histogram.rb
|
|
94
95
|
- lib/metriks/meter.rb
|
|
95
96
|
- lib/metriks/registry.rb
|
|
@@ -106,6 +107,7 @@ files:
|
|
|
106
107
|
- lib/metriks/utilization_timer.rb
|
|
107
108
|
- metriks.gemspec
|
|
108
109
|
- test/counter_test.rb
|
|
110
|
+
- test/gauge_test.rb
|
|
109
111
|
- test/graphite_reporter_test.rb
|
|
110
112
|
- test/histogram_test.rb
|
|
111
113
|
- test/librato_metrics_reporter_test.rb
|
|
@@ -151,6 +153,7 @@ specification_version: 2
|
|
|
151
153
|
summary: An experimental metrics client
|
|
152
154
|
test_files:
|
|
153
155
|
- test/counter_test.rb
|
|
156
|
+
- test/gauge_test.rb
|
|
154
157
|
- test/graphite_reporter_test.rb
|
|
155
158
|
- test/histogram_test.rb
|
|
156
159
|
- test/librato_metrics_reporter_test.rb
|