metriks 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/lib/metriks.rb +1 -1
- data/lib/metriks/reporter/riemann.rb +109 -0
- data/metriks.gemspec +3 -1
- data/test/riemann_reporter_test.rb +69 -0
- metadata +5 -2
data/Gemfile
CHANGED
data/lib/metriks.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
module Metriks::Reporter
|
2
|
+
class Riemann
|
3
|
+
require 'riemann/client'
|
4
|
+
|
5
|
+
attr_accessor :client
|
6
|
+
def initialize(options = {})
|
7
|
+
@client = ::Riemann::Client.new(
|
8
|
+
:host => options[:host],
|
9
|
+
:port => options[:port]
|
10
|
+
)
|
11
|
+
@registry = options[:registry] || Metrics::Registry.default
|
12
|
+
@interval = options[:interval] || 60
|
13
|
+
@on_error = options[:on_error] || proc { |ex| }
|
14
|
+
|
15
|
+
@default_event = options[:default_event] || {}
|
16
|
+
@default_event[:ttl] ||= @interval * 1.5
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
@thread ||= Thread.new do
|
21
|
+
loop do
|
22
|
+
sleep @interval
|
23
|
+
|
24
|
+
Thread.new do
|
25
|
+
begin
|
26
|
+
write
|
27
|
+
rescue Exception => ex
|
28
|
+
@on_error[ex] rescue nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def stop
|
36
|
+
@thread.kill if @thread
|
37
|
+
@thread = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def restart
|
41
|
+
stop
|
42
|
+
start
|
43
|
+
end
|
44
|
+
|
45
|
+
def flush
|
46
|
+
# Is this supposed to take interval into account? --aphyr
|
47
|
+
if !@last_write || @last_write.min != Time.now.min
|
48
|
+
write
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def write
|
53
|
+
@last_write = Time.now
|
54
|
+
|
55
|
+
@registry.each do |name, metric|
|
56
|
+
case metric
|
57
|
+
when Metriks::Meter
|
58
|
+
send_metric name, 'meter', metric, [
|
59
|
+
:count, :one_minute_rate, :five_minute_rate,
|
60
|
+
:fifteen_minute_rate, :mean_rate
|
61
|
+
]
|
62
|
+
when Metriks::Counter
|
63
|
+
send_metric name, 'counter', metric, [
|
64
|
+
:count
|
65
|
+
]
|
66
|
+
when Metriks::UtilizationTimer
|
67
|
+
send_metric name, 'utilization_timer', metric, [
|
68
|
+
:count, :one_minute_rate, :five_minute_rate,
|
69
|
+
:fifteen_minute_rate, :mean_rate,
|
70
|
+
:min, :max, :mean, :stddev,
|
71
|
+
:one_minute_utilization, :five_minute_utilization,
|
72
|
+
:fifteen_minute_utilization, :mean_utilization,
|
73
|
+
], [
|
74
|
+
:median, :get_95th_percentile
|
75
|
+
]
|
76
|
+
when Metriks::Timer
|
77
|
+
send_metric name, 'timer', metric, [
|
78
|
+
:count, :one_minute_rate, :five_minute_rate,
|
79
|
+
:fifteen_minute_rate, :mean_rate,
|
80
|
+
:min, :max, :mean, :stddev
|
81
|
+
], [
|
82
|
+
:median, :get_95th_percentile
|
83
|
+
]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def send_metric(name, type, metric, keys, snapshot_keys = [])
|
89
|
+
keys.each do |key|
|
90
|
+
@client << @default_event.merge(
|
91
|
+
:service => "#{name} #{key}",
|
92
|
+
:metric => metric.send(key),
|
93
|
+
:tags => [type]
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
unless snapshot_keys.empty?
|
98
|
+
snapshot = metric.snapshot
|
99
|
+
snapshot_keys.each do |key|
|
100
|
+
@client << @default_event.merge(
|
101
|
+
:service => "#{name} #{key}",
|
102
|
+
:metric => snapshot.send(key),
|
103
|
+
:tags => [type]
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/metriks.gemspec
CHANGED
@@ -13,7 +13,7 @@ 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.
|
16
|
+
s.version = '0.9.4'
|
17
17
|
s.date = '2012-03-12'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
@@ -69,6 +69,7 @@ Gem::Specification.new do |s|
|
|
69
69
|
lib/metriks/reporter/librato_metrics.rb
|
70
70
|
lib/metriks/reporter/logger.rb
|
71
71
|
lib/metriks/reporter/proc_title.rb
|
72
|
+
lib/metriks/reporter/riemann.rb
|
72
73
|
lib/metriks/simple_moving_average.rb
|
73
74
|
lib/metriks/snapshot.rb
|
74
75
|
lib/metriks/timer.rb
|
@@ -84,6 +85,7 @@ Gem::Specification.new do |s|
|
|
84
85
|
test/metriks_test.rb
|
85
86
|
test/proc_title_reporter_test.rb
|
86
87
|
test/registry_test.rb
|
88
|
+
test/riemann_reporter_test.rb
|
87
89
|
test/test_helper.rb
|
88
90
|
test/timer_test.rb
|
89
91
|
test/utilization_timer_test.rb
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# riemann only works in 1.9
|
4
|
+
if RUBY_VERSION > '1.9'
|
5
|
+
|
6
|
+
require 'metriks/reporter/riemann'
|
7
|
+
|
8
|
+
class RiemannReporterTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@registry = Metriks::Registry.new
|
11
|
+
@reporter = Metriks::Reporter::Riemann.new(
|
12
|
+
:host => "foo",
|
13
|
+
:port => 1234,
|
14
|
+
:registry => @registry,
|
15
|
+
:default_event => {:host => "h"}
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
@reporter.stop
|
21
|
+
@registry.stop
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_init
|
25
|
+
assert_equal @reporter.client.host, "foo"
|
26
|
+
assert_equal @reporter.client.port, 1234
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_write
|
30
|
+
@registry.meter('meter.testing').mark
|
31
|
+
@registry.counter('counter.testing').increment
|
32
|
+
@registry.timer('timer.testing').update(1.5)
|
33
|
+
@registry.utilization_timer('utilization_timer.testing').update(1.5)
|
34
|
+
|
35
|
+
@reporter.client.expects(:<<).at_least_once
|
36
|
+
@reporter.client.expects(:<<).with(
|
37
|
+
:host => "h",
|
38
|
+
:service => "meter.testing count",
|
39
|
+
:metric => 1,
|
40
|
+
:tags => ["meter"],
|
41
|
+
:ttl => 90
|
42
|
+
)
|
43
|
+
@reporter.client.expects(:<<).with(
|
44
|
+
:host => "h",
|
45
|
+
:service => "counter.testing count",
|
46
|
+
:metric => 1,
|
47
|
+
:tags => ["counter"],
|
48
|
+
:ttl => 90
|
49
|
+
)
|
50
|
+
@reporter.client.expects(:<<).with(
|
51
|
+
:host => "h",
|
52
|
+
:service => "timer.testing max",
|
53
|
+
:metric => 1.5,
|
54
|
+
:tags => ["timer"],
|
55
|
+
:ttl => 90
|
56
|
+
)
|
57
|
+
@reporter.client.expects(:<<).with(
|
58
|
+
:host => "h",
|
59
|
+
:service => "utilization_timer.testing mean",
|
60
|
+
:metric => 1.5,
|
61
|
+
:tags => ["utilization_timer"],
|
62
|
+
:ttl => 90
|
63
|
+
)
|
64
|
+
|
65
|
+
@reporter.write
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 4
|
9
|
+
version: 0.9.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Eric Lindvall
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/metriks/reporter/librato_metrics.rb
|
109
109
|
- lib/metriks/reporter/logger.rb
|
110
110
|
- lib/metriks/reporter/proc_title.rb
|
111
|
+
- lib/metriks/reporter/riemann.rb
|
111
112
|
- lib/metriks/simple_moving_average.rb
|
112
113
|
- lib/metriks/snapshot.rb
|
113
114
|
- lib/metriks/timer.rb
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- test/metriks_test.rb
|
124
125
|
- test/proc_title_reporter_test.rb
|
125
126
|
- test/registry_test.rb
|
127
|
+
- test/riemann_reporter_test.rb
|
126
128
|
- test/test_helper.rb
|
127
129
|
- test/timer_test.rb
|
128
130
|
- test/utilization_timer_test.rb
|
@@ -166,5 +168,6 @@ test_files:
|
|
166
168
|
- test/metriks_test.rb
|
167
169
|
- test/proc_title_reporter_test.rb
|
168
170
|
- test/registry_test.rb
|
171
|
+
- test/riemann_reporter_test.rb
|
169
172
|
- test/timer_test.rb
|
170
173
|
- test/utilization_timer_test.rb
|