ruby-metrics 0.9.0 → 0.9.1
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/Rakefile +2 -2
- data/lib/ruby-metrics/agent.rb +4 -0
- data/lib/ruby-metrics/instruments/counter.rb +4 -1
- data/lib/ruby-metrics/instruments/gauge.rb +3 -1
- data/lib/ruby-metrics/instruments/histogram.rb +2 -1
- data/lib/ruby-metrics/instruments/instrument.rb +14 -0
- data/lib/ruby-metrics/instruments/meter.rb +3 -2
- data/lib/ruby-metrics/instruments/timer.rb +3 -2
- data/lib/ruby-metrics/reporter.rb +7 -2
- data/lib/ruby-metrics/reporters/ganglia.rb +79 -0
- data/lib/ruby-metrics/reporters/librato.rb +83 -0
- data/lib/ruby-metrics/version.rb +1 -1
- data/spec/instruments/counter_spec.rb +37 -27
- data/spec/reporter_spec.rb +27 -0
- data/spec/reporters/opentsdb_spec.rb +299 -0
- metadata +7 -4
- data/ruby-metrics-ganglia.gemspec +0 -21
- data/ruby-metrics-librato.gemspec +0 -20
data/Rakefile
CHANGED
@@ -15,13 +15,13 @@ task :build do
|
|
15
15
|
FileUtils.mv(Dir['*.gem'], 'pkg')
|
16
16
|
end
|
17
17
|
|
18
|
-
desc
|
18
|
+
desc "Tags version as #{Metrics::VERSION}, pushes to remote, and pushes gem"
|
19
19
|
task :release => :build do
|
20
20
|
puts "Releasing v#{Metrics::VERSION}"
|
21
21
|
sh 'git', 'tag', '-m', "Version #{Metrics::VERSION}", "v#{Metrics::VERSION}"
|
22
22
|
sh "git push origin master"
|
23
23
|
sh "git push origin v#{Metrics::VERSION}"
|
24
|
-
|
24
|
+
sh "ls pkg/*.gem | xargs -n 1 gem push"
|
25
25
|
end
|
26
26
|
|
27
27
|
RSpec::Core::RakeTask.new do |t|
|
data/lib/ruby-metrics/agent.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
require_relative 'instrument'
|
1
2
|
require 'ruby-metrics/statistics/uniform_sample'
|
2
3
|
require 'ruby-metrics/statistics/exponential_sample'
|
3
4
|
|
4
5
|
module Metrics
|
5
6
|
module Instruments
|
6
|
-
class Histogram
|
7
|
+
class Histogram < Instrument
|
7
8
|
|
8
9
|
def initialize(type = :uniform)
|
9
10
|
@count = 0
|
@@ -1,8 +1,9 @@
|
|
1
|
+
require_relative 'instrument'
|
1
2
|
require 'ruby-metrics/time_units'
|
2
3
|
|
3
4
|
module Metrics
|
4
5
|
module Instruments
|
5
|
-
class Meter
|
6
|
+
class Meter < Instrument
|
6
7
|
include Metrics::TimeConversion
|
7
8
|
|
8
9
|
# From http://www.teamquest.com/pdfs/whitepaper/ldavg2.pdf
|
@@ -21,7 +22,7 @@ module Metrics
|
|
21
22
|
@count = 0
|
22
23
|
@initialized = false
|
23
24
|
@start_time = Time.now.to_f
|
24
|
-
@units =
|
25
|
+
@units = options[:units]
|
25
26
|
|
26
27
|
@timer_thread = Thread.new do
|
27
28
|
begin
|
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
require_relative 'instrument'
|
2
|
+
require 'ruby-metrics/time_units'
|
2
3
|
|
3
4
|
module Metrics
|
4
5
|
module Instruments
|
5
|
-
class Timer
|
6
|
+
class Timer < Instrument
|
6
7
|
include Metrics::TimeConversion
|
7
8
|
|
8
9
|
attr_reader :duration_unit, :rate_unit, :units
|
@@ -5,7 +5,12 @@ module Metrics
|
|
5
5
|
|
6
6
|
include Logging
|
7
7
|
|
8
|
+
def stop
|
9
|
+
@running = false
|
10
|
+
end
|
11
|
+
|
8
12
|
def initialize(options = {})
|
13
|
+
@running = true
|
9
14
|
|
10
15
|
if options[:agent] == nil
|
11
16
|
raise "Need an agent to report data from"
|
@@ -15,13 +20,13 @@ module Metrics
|
|
15
20
|
agent = options[:agent]
|
16
21
|
|
17
22
|
Thread.new {
|
18
|
-
while(
|
23
|
+
while(@running)
|
19
24
|
agent.reporters.each do |name, service|
|
20
25
|
service.report(agent)
|
21
26
|
end
|
22
27
|
sleep delay
|
23
28
|
end
|
24
|
-
}
|
29
|
+
}
|
25
30
|
end
|
26
31
|
|
27
32
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'ruby-metrics/version'
|
2
|
+
require 'ruby-metrics'
|
3
|
+
|
4
|
+
require 'gmetric'
|
5
|
+
|
6
|
+
module Metrics
|
7
|
+
module Reporters
|
8
|
+
class GangliaReporter
|
9
|
+
|
10
|
+
attr_reader :host_ip
|
11
|
+
attr_reader :host_port
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@host_ip = options[:host_ip]
|
15
|
+
@host_port = options[:host_port]
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_data(data)
|
19
|
+
puts "Sending data: #{data.inspect}"
|
20
|
+
data_type = case data[:value].class.to_s
|
21
|
+
when "Fixnum"
|
22
|
+
"uint32"
|
23
|
+
when "Float"
|
24
|
+
"float"
|
25
|
+
when "String"
|
26
|
+
"string"
|
27
|
+
else
|
28
|
+
"unknown"
|
29
|
+
end
|
30
|
+
|
31
|
+
Ganglia::GMetric.send(@host_ip, @host_port.to_i, {
|
32
|
+
:spoof => 0,
|
33
|
+
:name => data[:name],
|
34
|
+
:units => data[:units],
|
35
|
+
:type => data_type,
|
36
|
+
:value => data[:value],
|
37
|
+
:tmax => 60,
|
38
|
+
:dmax => 300,
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
def report(agent)
|
43
|
+
|
44
|
+
agent.instruments.each do |name, instrument|
|
45
|
+
nothing_to_do = false
|
46
|
+
data = { :name => name, :units => instrument.units }
|
47
|
+
case instrument
|
48
|
+
when Metrics::Instruments::Counter
|
49
|
+
value = instrument.to_i
|
50
|
+
data.merge! :value => value.to_i
|
51
|
+
send_data data
|
52
|
+
when Metrics::Instruments::Gauge
|
53
|
+
if instrument.get.is_a? Hash
|
54
|
+
instrument.get.each do |key, value|
|
55
|
+
data.merge! :name => "#{name}_#{key}", :value => value
|
56
|
+
send_data data
|
57
|
+
end
|
58
|
+
else
|
59
|
+
data.merge! :value => instrument.get
|
60
|
+
send_data data
|
61
|
+
end
|
62
|
+
when Metrics::Instruments::Timer
|
63
|
+
[:count, :fifteen_minute_rate, :five_minute_rate, :one_minute_rate, :min, :max, :mean].each do |attribute|
|
64
|
+
data.merge!(:name => "#{name}_#{attribute}", :value => instrument.send(attribute))
|
65
|
+
send_data data
|
66
|
+
end
|
67
|
+
when Metrics::Instruments::Meter
|
68
|
+
[:count, :fifteen_minute_rate, :five_minute_rate, :one_minute_rate, :mean_rate].each do |attribute|
|
69
|
+
data.merge!(:name => "#{name_attribute}", :value => instrument.send(attribute) )
|
70
|
+
end
|
71
|
+
else
|
72
|
+
puts "Unhandled instrument"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'ruby-metrics/version'
|
3
|
+
require 'ruby-metrics'
|
4
|
+
|
5
|
+
module Metrics
|
6
|
+
module Reporters
|
7
|
+
class Librato
|
8
|
+
attr_reader :api_token
|
9
|
+
attr_reader :user
|
10
|
+
|
11
|
+
API_URL = "https://metrics-api.librato.com/v1"
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@api_token = options[:api_token]
|
15
|
+
@user = options[:user]
|
16
|
+
@headers = {
|
17
|
+
'User-Agent' => "ruby-metrics #{Metrics::VERSION}"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_data(post_url, post_data)
|
22
|
+
url = URI.parse(post_url)
|
23
|
+
req = Net::HTTP::Post.new(url.path)
|
24
|
+
req.basic_auth @user, @api_token
|
25
|
+
@headers.each do |k,v|
|
26
|
+
req.add_field(k, v)
|
27
|
+
end
|
28
|
+
req.set_form_data(post_data)
|
29
|
+
https = Net::HTTP.new(url.host, url.port)
|
30
|
+
https.use_ssl = true
|
31
|
+
#https.set_debug_output($stdout)
|
32
|
+
|
33
|
+
https.start do |http|
|
34
|
+
result = http.request(req)
|
35
|
+
case result
|
36
|
+
when Net::HTTPCreated
|
37
|
+
# OK
|
38
|
+
puts "SENT!"
|
39
|
+
else
|
40
|
+
puts "FAILED TO SEND: #{https.inspect}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def report(agent)
|
46
|
+
|
47
|
+
agent.instruments.each do |name, instrument|
|
48
|
+
nothing_to_do = false
|
49
|
+
measure_time = Time.now.to_i
|
50
|
+
|
51
|
+
case instrument.class.to_s
|
52
|
+
when "Metrics::Instruments::Counter"
|
53
|
+
value = instrument.to_i
|
54
|
+
post_url = "#{API_URL}/counters/#{name}.json"
|
55
|
+
post_data = {:measure_time => measure_time, :value => value.to_i}
|
56
|
+
send_data(post_url, post_data)
|
57
|
+
when "Metrics::Instruments::Gauge"
|
58
|
+
post_url = "#{API_URL}/gauges/#{name}.json"
|
59
|
+
if instrument.get.is_a? Hash
|
60
|
+
instrument.get.each do |key, value|
|
61
|
+
post_data = {:measure_time => measure_time, :source => key, :value => value}
|
62
|
+
send_data(post_url, post_data)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
post_data = {:measure_time => measure_time, :value => instrument.get}
|
66
|
+
send_data(post_url, post_data)
|
67
|
+
end
|
68
|
+
when "Metrics::Instruments::Timer"
|
69
|
+
post_url = "#{API_URL}/gauges/#{name}.json"
|
70
|
+
common_data = {:measure_time => measure_time}
|
71
|
+
|
72
|
+
[:count, :fifteen_minute_rate, :five_minute_rate, :one_minute_rate, :min, :max, :mean].each do |attribute|
|
73
|
+
post_data = {:source => attribute, :value => instrument.send(attribute)}.merge(common_data)
|
74
|
+
send_data(post_url, post_data)
|
75
|
+
end
|
76
|
+
else
|
77
|
+
puts "Unhandled instrument"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/ruby-metrics/version.rb
CHANGED
@@ -1,78 +1,88 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Metrics::Instruments::Counter do
|
4
|
-
|
5
|
-
|
4
|
+
let(:counter) {
|
5
|
+
Metrics::Instruments::Counter.new
|
6
|
+
}
|
7
|
+
|
8
|
+
it 'can be tagged' do
|
9
|
+
counter.tag(:foo, 'bar')
|
10
|
+
expect(counter.tags.keys).to include(:foo)
|
11
|
+
expect(counter.tags.values).to include('bar')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'does not need to be tagged' do
|
15
|
+
expect(counter.tags.keys.size).to be 0
|
6
16
|
end
|
7
17
|
|
8
|
-
it
|
9
|
-
|
18
|
+
it 'should create a new entity with zero as its value' do
|
19
|
+
counter.to_i.should == 0
|
10
20
|
end
|
11
21
|
|
12
22
|
it "should increment its counter by the value specified" do
|
13
23
|
value = 1
|
14
24
|
lambda do
|
15
|
-
|
16
|
-
end.should change{
|
25
|
+
counter.inc(value)
|
26
|
+
end.should change{ counter.to_i }.by(value)
|
17
27
|
end
|
18
28
|
|
19
29
|
it "should increment its counter by one by default" do
|
20
30
|
lambda do
|
21
|
-
|
22
|
-
end.should change{
|
31
|
+
counter.inc
|
32
|
+
end.should change{ counter.to_i }.by(1)
|
23
33
|
end
|
24
34
|
|
25
35
|
it "should decrement its counter by the value specified" do
|
26
36
|
value = 1
|
27
37
|
lambda do
|
28
|
-
|
29
|
-
end.should change{
|
38
|
+
counter.dec(value)
|
39
|
+
end.should change{ counter.to_i }.by(-value)
|
30
40
|
end
|
31
41
|
|
32
42
|
it "should decrement its counter by one by default" do
|
33
43
|
lambda do
|
34
|
-
|
35
|
-
end.should change{
|
44
|
+
counter.dec
|
45
|
+
end.should change{ counter.to_i }.by(-1)
|
36
46
|
end
|
37
47
|
|
38
48
|
it "should alias #incr to #inc" do
|
39
49
|
lambda do
|
40
|
-
|
41
|
-
end.should change{
|
50
|
+
counter.incr
|
51
|
+
end.should change{ counter.to_i }.by(1)
|
42
52
|
end
|
43
53
|
|
44
54
|
it "should alias #decr to #dec" do
|
45
55
|
lambda do
|
46
|
-
|
47
|
-
end.should change{
|
56
|
+
counter.decr
|
57
|
+
end.should change{ counter.to_i }.by(-1)
|
48
58
|
end
|
49
59
|
|
50
60
|
it "should clear the counter correctly" do
|
51
|
-
|
52
|
-
|
61
|
+
counter.clear
|
62
|
+
counter.to_i.should == 0
|
53
63
|
end
|
54
64
|
|
55
65
|
it "should correctly represent the value as a string" do
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
counter.clear
|
67
|
+
counter.to_i.should == 0
|
68
|
+
counter.to_s.should == "0"
|
59
69
|
end
|
60
70
|
|
61
71
|
it "should return the new count when incrementing" do
|
62
|
-
count =
|
63
|
-
|
72
|
+
count = counter.to_i
|
73
|
+
counter.inc(value = 1).should == count + value
|
64
74
|
end
|
65
75
|
|
66
76
|
it "should return the new count when decrementing" do
|
67
77
|
lambda do
|
68
|
-
|
69
|
-
end.should change{
|
78
|
+
counter.dec(1)
|
79
|
+
end.should change{ counter.to_i }.by(-1)
|
70
80
|
end
|
71
81
|
|
72
82
|
context "to_json" do
|
73
|
-
let(:json) {
|
83
|
+
let(:json) { counter.to_json }
|
74
84
|
it "should serialize to its current value" do
|
75
|
-
json.should ==
|
85
|
+
json.should == counter.to_s
|
76
86
|
end
|
77
87
|
end
|
78
88
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ruby-metrics/agent'
|
2
|
+
require 'ruby-metrics/reporter'
|
3
|
+
require 'ruby-metrics/reporters/opentsdb'
|
4
|
+
|
5
|
+
module Metrics
|
6
|
+
describe 'Reporter' do
|
7
|
+
let(:mock_reporter) {
|
8
|
+
double(Metrics::Reporters::OpenTSDBReporter)
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:agent) {
|
12
|
+
agent = Metrics::Agent.new
|
13
|
+
agent.report_to 'opentsdb', mock_reporter
|
14
|
+
agent
|
15
|
+
}
|
16
|
+
|
17
|
+
it 'should report three times in 4 seconds with a 1 second interval' do
|
18
|
+
expect(mock_reporter).to receive(:report).exactly(3).times
|
19
|
+
agent.report_periodically(1)
|
20
|
+
puts "Sleeping"
|
21
|
+
sleep(4)
|
22
|
+
puts "Stopping..."
|
23
|
+
agent.stop_reporting
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,299 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'opentsdb/client'
|
3
|
+
require 'ruby-metrics/reporters/opentsdb'
|
4
|
+
require 'ruby-metrics'
|
5
|
+
require 'timecop'
|
6
|
+
|
7
|
+
module Metrics
|
8
|
+
module Reporters
|
9
|
+
describe 'OpenTSDBReporter' do
|
10
|
+
|
11
|
+
let(:mock_tsdb_client) {
|
12
|
+
mock_tsdb_client = double(OpenTSDB::Client)
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:reporter) {
|
16
|
+
expect(OpenTSDB::Client).to receive(:new).and_return mock_tsdb_client
|
17
|
+
OpenTSDBReporter.new(:tags => {:foo => 'bar'})
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:agent) {
|
21
|
+
Metrics::Agent.new
|
22
|
+
}
|
23
|
+
|
24
|
+
it 'should report a counter correctly' do
|
25
|
+
counter = agent.counter :my_counter
|
26
|
+
counter.incr
|
27
|
+
counter.incr
|
28
|
+
|
29
|
+
counter_data = {
|
30
|
+
:value => 2,
|
31
|
+
:timestamp => anything,
|
32
|
+
:tags => {
|
33
|
+
:units => '',
|
34
|
+
:foo => 'bar'
|
35
|
+
},
|
36
|
+
:metric => 'my_counter'
|
37
|
+
}
|
38
|
+
expect(mock_tsdb_client).to receive(:put).with(counter_data)
|
39
|
+
|
40
|
+
reporter.report(agent)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should report a tagged counter correctly' do
|
44
|
+
counter = agent.counter :logins, 'logins'
|
45
|
+
counter.incr
|
46
|
+
counter.tag(:user, 'sam')
|
47
|
+
|
48
|
+
counter_data = {
|
49
|
+
:value => 1,
|
50
|
+
:timestamp => anything,
|
51
|
+
:tags => {
|
52
|
+
:units => 'logins',
|
53
|
+
:foo => 'bar',
|
54
|
+
:user => 'sam'
|
55
|
+
},
|
56
|
+
:metric => 'logins'
|
57
|
+
}
|
58
|
+
expect(mock_tsdb_client).to receive(:put).with(counter_data)
|
59
|
+
|
60
|
+
reporter.report(agent)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should report a gauge that returns a hash' do
|
64
|
+
gauge = agent.gauge :my_gauge do
|
65
|
+
{
|
66
|
+
:hit_count => 42,
|
67
|
+
:http_requests => 320
|
68
|
+
}
|
69
|
+
end
|
70
|
+
gauge.tag(:mytag, 'somevalue')
|
71
|
+
|
72
|
+
|
73
|
+
tags = {
|
74
|
+
:units => '',
|
75
|
+
:foo => 'bar',
|
76
|
+
:mytag => 'somevalue'
|
77
|
+
}
|
78
|
+
|
79
|
+
gauge_hit_data = {
|
80
|
+
:value => 42,
|
81
|
+
:timestamp => anything,
|
82
|
+
:tags => tags,
|
83
|
+
:metric => 'my_gauge.hit_count'
|
84
|
+
}
|
85
|
+
gauge_requests_data = {
|
86
|
+
:value => 320,
|
87
|
+
:timestamp => anything,
|
88
|
+
:tags => tags,
|
89
|
+
:metric => 'my_gauge.http_requests'
|
90
|
+
}
|
91
|
+
expect(mock_tsdb_client).to receive(:put).with(gauge_hit_data)
|
92
|
+
expect(mock_tsdb_client).to receive(:put).with(gauge_requests_data)
|
93
|
+
|
94
|
+
reporter.report(agent)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
it 'should report a gauge that returns a non-hash value' do
|
99
|
+
agent.gauge :boring_gauge, 'units' do
|
100
|
+
42
|
101
|
+
end
|
102
|
+
|
103
|
+
gauge_data = {
|
104
|
+
:value => 42,
|
105
|
+
:timestamp => anything,
|
106
|
+
:tags => {
|
107
|
+
:units => 'units',
|
108
|
+
:foo => 'bar',
|
109
|
+
},
|
110
|
+
:metric => 'boring_gauge'
|
111
|
+
}
|
112
|
+
expect(mock_tsdb_client).to receive(:put).with(gauge_data)
|
113
|
+
|
114
|
+
reporter.report(agent)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should report a timer' do
|
118
|
+
timer = agent.timer :some_timer, 'requests'
|
119
|
+
timer.update(5, :seconds)
|
120
|
+
|
121
|
+
timer_counter_data = {
|
122
|
+
:value => 1,
|
123
|
+
:timestamp => anything,
|
124
|
+
:tags => {
|
125
|
+
:units => 'requests',
|
126
|
+
:foo => 'bar'
|
127
|
+
},
|
128
|
+
:metric => 'some_timer.count'
|
129
|
+
}
|
130
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_counter_data)
|
131
|
+
|
132
|
+
timer_fifteen = {
|
133
|
+
:value => 0.0,
|
134
|
+
:timestamp => anything,
|
135
|
+
:tags => {
|
136
|
+
:units => 'requests/sec',
|
137
|
+
:foo => 'bar'
|
138
|
+
},
|
139
|
+
:metric => 'some_timer.fifteen_minute_rate'
|
140
|
+
}
|
141
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_fifteen)
|
142
|
+
|
143
|
+
timer_five = {
|
144
|
+
:value => 0.0,
|
145
|
+
:timestamp => anything,
|
146
|
+
:tags => {
|
147
|
+
:units => 'requests/sec',
|
148
|
+
:foo => 'bar'
|
149
|
+
},
|
150
|
+
:metric => 'some_timer.five_minute_rate'
|
151
|
+
}
|
152
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_five)
|
153
|
+
|
154
|
+
|
155
|
+
timer_one = {
|
156
|
+
:value => 0.0,
|
157
|
+
:timestamp => anything,
|
158
|
+
:tags => {
|
159
|
+
:units => 'requests/sec',
|
160
|
+
:foo => 'bar'
|
161
|
+
},
|
162
|
+
:metric => 'some_timer.one_minute_rate'
|
163
|
+
}
|
164
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_one)
|
165
|
+
|
166
|
+
|
167
|
+
timer_min = {
|
168
|
+
:value => 5.0,
|
169
|
+
:timestamp => anything,
|
170
|
+
:tags => {
|
171
|
+
:units => 'sec/requests',
|
172
|
+
:foo => 'bar'
|
173
|
+
},
|
174
|
+
:metric => 'some_timer.min'
|
175
|
+
}
|
176
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_min)
|
177
|
+
|
178
|
+
|
179
|
+
timer_max = {
|
180
|
+
:value => 5.0,
|
181
|
+
:timestamp => anything,
|
182
|
+
:tags => {
|
183
|
+
:units => 'sec/requests',
|
184
|
+
:foo => 'bar'
|
185
|
+
},
|
186
|
+
:metric => 'some_timer.max'
|
187
|
+
}
|
188
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_max)
|
189
|
+
|
190
|
+
timer_mean = {
|
191
|
+
:value => 5.0,
|
192
|
+
:timestamp => anything,
|
193
|
+
:tags => {
|
194
|
+
:units => 'sec/requests',
|
195
|
+
:foo => 'bar'
|
196
|
+
},
|
197
|
+
:metric => 'some_timer.mean'
|
198
|
+
}
|
199
|
+
expect(mock_tsdb_client).to receive(:put).with(timer_mean)
|
200
|
+
|
201
|
+
reporter.report(agent)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should report a gauge that returns a non-hash value' do
|
205
|
+
agent.gauge :boring_gauge, 'units' do
|
206
|
+
42
|
207
|
+
end
|
208
|
+
|
209
|
+
gauge_data = {
|
210
|
+
:value => 42,
|
211
|
+
:timestamp => anything,
|
212
|
+
:tags => {
|
213
|
+
:units => 'units',
|
214
|
+
:foo => 'bar',
|
215
|
+
},
|
216
|
+
:metric => 'boring_gauge'
|
217
|
+
}
|
218
|
+
expect(mock_tsdb_client).to receive(:put).with(gauge_data)
|
219
|
+
|
220
|
+
reporter.report(agent)
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should report a meter' do
|
224
|
+
expect(Thread).to receive(:new).and_return nil
|
225
|
+
|
226
|
+
meter = agent.meter :http_requests, 'requests'
|
227
|
+
meter.mark
|
228
|
+
meter.mark
|
229
|
+
meter.mark
|
230
|
+
meter.tick
|
231
|
+
meter.mark
|
232
|
+
meter.tag :somekey, 'value'
|
233
|
+
|
234
|
+
meter_counter_data = {
|
235
|
+
:value => 1,
|
236
|
+
:timestamp => anything,
|
237
|
+
:tags => {
|
238
|
+
:units => 'requests',
|
239
|
+
:foo => 'bar',
|
240
|
+
:somekey => 'value'
|
241
|
+
},
|
242
|
+
:metric => 'http_requests.count'
|
243
|
+
}
|
244
|
+
expect(mock_tsdb_client).to receive(:put).with(meter_counter_data)
|
245
|
+
|
246
|
+
meter_fifteen = {
|
247
|
+
:value => 0.6,
|
248
|
+
:timestamp => anything,
|
249
|
+
:tags => {
|
250
|
+
:units => 'requests/sec',
|
251
|
+
:foo => 'bar',
|
252
|
+
:somekey => 'value'
|
253
|
+
},
|
254
|
+
:metric => 'http_requests.fifteen_minute_rate'
|
255
|
+
}
|
256
|
+
expect(mock_tsdb_client).to receive(:put).with(meter_fifteen)
|
257
|
+
|
258
|
+
meter_five = {
|
259
|
+
:value => 0.6,
|
260
|
+
:timestamp => anything,
|
261
|
+
:tags => {
|
262
|
+
:units => 'requests/sec',
|
263
|
+
:foo => 'bar',
|
264
|
+
:somekey => 'value'
|
265
|
+
},
|
266
|
+
:metric => 'http_requests.five_minute_rate'
|
267
|
+
}
|
268
|
+
expect(mock_tsdb_client).to receive(:put).with(meter_five)
|
269
|
+
|
270
|
+
|
271
|
+
meter_one = {
|
272
|
+
:value => 0.6,
|
273
|
+
:timestamp => anything,
|
274
|
+
:tags => {
|
275
|
+
:units => 'requests/sec',
|
276
|
+
:foo => 'bar',
|
277
|
+
:somekey => 'value'
|
278
|
+
},
|
279
|
+
:metric => 'http_requests.one_minute_rate'
|
280
|
+
}
|
281
|
+
expect(mock_tsdb_client).to receive(:put).with(meter_one)
|
282
|
+
|
283
|
+
meter_mean = {
|
284
|
+
:value => anything,
|
285
|
+
:timestamp => anything,
|
286
|
+
:tags => {
|
287
|
+
:units => 'requests/sec',
|
288
|
+
:foo => 'bar',
|
289
|
+
:somekey => 'value'
|
290
|
+
},
|
291
|
+
:metric => 'http_requests.mean_rate'
|
292
|
+
}
|
293
|
+
expect(mock_tsdb_client).to receive(:put).with(meter_mean)
|
294
|
+
|
295
|
+
reporter.report(agent)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -132,6 +132,7 @@ files:
|
|
132
132
|
- lib/ruby-metrics/instruments/counter.rb
|
133
133
|
- lib/ruby-metrics/instruments/gauge.rb
|
134
134
|
- lib/ruby-metrics/instruments/histogram.rb
|
135
|
+
- lib/ruby-metrics/instruments/instrument.rb
|
135
136
|
- lib/ruby-metrics/instruments/meter.rb
|
136
137
|
- lib/ruby-metrics/instruments/timer.rb
|
137
138
|
- lib/ruby-metrics/integration.rb
|
@@ -140,12 +141,12 @@ files:
|
|
140
141
|
- lib/ruby-metrics/integration/webrick.rb
|
141
142
|
- lib/ruby-metrics/logging.rb
|
142
143
|
- lib/ruby-metrics/reporter.rb
|
144
|
+
- lib/ruby-metrics/reporters/ganglia.rb
|
145
|
+
- lib/ruby-metrics/reporters/librato.rb
|
143
146
|
- lib/ruby-metrics/statistics/exponential_sample.rb
|
144
147
|
- lib/ruby-metrics/statistics/uniform_sample.rb
|
145
148
|
- lib/ruby-metrics/time_units.rb
|
146
149
|
- lib/ruby-metrics/version.rb
|
147
|
-
- ruby-metrics-ganglia.gemspec
|
148
|
-
- ruby-metrics-librato.gemspec
|
149
150
|
- ruby-metrics-opentsdb.gemspec
|
150
151
|
- ruby-metrics.gemspec
|
151
152
|
- spec/agent_spec.rb
|
@@ -156,6 +157,8 @@ files:
|
|
156
157
|
- spec/instruments/timer_spec.rb
|
157
158
|
- spec/integration/rack_endpoint_spec.rb
|
158
159
|
- spec/integration/rack_middleware_spec.rb
|
160
|
+
- spec/reporter_spec.rb
|
161
|
+
- spec/reporters/opentsdb_spec.rb
|
159
162
|
- spec/spec_helper.rb
|
160
163
|
- spec/statistics/exponential_sample_spec.rb
|
161
164
|
- spec/statistics/uniform_sample_spec.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
3
|
-
require 'ruby-metrics/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = 'ruby-metrics-ganglia'
|
7
|
-
s.version = Metrics::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ['John Ewart']
|
10
|
-
s.email = ['john@johnewart.net']
|
11
|
-
s.homepage = 'https://github.com/johnewart/ruby-metrics'
|
12
|
-
s.summary = %q{Ganglia reporter for ruby-metrics}
|
13
|
-
s.description = %q{A reporter that uses Ganglia's to stash metric data}
|
14
|
-
s.license = 'MIT'
|
15
|
-
|
16
|
-
s.files = ['lib/ruby-metrics/reporters/ganglia.rb']
|
17
|
-
s.require_paths = ['lib']
|
18
|
-
|
19
|
-
s.add_dependency 'gmetric', '0.1.3'
|
20
|
-
s.add_dependency 'ruby-metrics', Metrics::VERSION
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
3
|
-
require 'ruby-metrics/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = 'ruby-metrics-librato'
|
7
|
-
s.version = Metrics::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ['John Ewart']
|
10
|
-
s.email = ['john@johnewart.net']
|
11
|
-
s.homepage = 'https://github.com/johnewart/ruby-metrics'
|
12
|
-
s.summary = %q{Librato reporter for ruby-metrics}
|
13
|
-
s.description = %q{A reporter that uses Librato to stash metric data}
|
14
|
-
s.license = 'MIT'
|
15
|
-
|
16
|
-
s.files = ['lib/ruby-metrics/reporters/librato.rb']
|
17
|
-
s.require_paths = ['lib']
|
18
|
-
|
19
|
-
s.add_dependency 'ruby-metrics', Metrics::VERSION
|
20
|
-
end
|