ruby-metrics 0.8.5 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/ruby-metrics/instruments.rb +1 -1
- data/lib/ruby-metrics/instruments/base.rb +5 -1
- data/lib/ruby-metrics/instruments/counter.rb +1 -1
- data/lib/ruby-metrics/instruments/gauge.rb +1 -1
- data/lib/ruby-metrics/instruments/histogram.rb +1 -1
- data/lib/ruby-metrics/instruments/meter.rb +1 -1
- data/lib/ruby-metrics/instruments/timer.rb +1 -1
- data/lib/ruby-metrics/version.rb +1 -1
- data/spec/instruments/base_spec.rb +1 -1
- data/spec/instruments/counter_spec.rb +7 -0
- data/spec/instruments/gauge_spec.rb +9 -11
- data/spec/instruments/histogram_spec.rb +20 -4
- data/spec/instruments/meter_spec.rb +14 -1
- data/spec/instruments/timer_spec.rb +30 -3
- data/spec/instruments_spec.rb +1 -1
- metadata +5 -5
data/Gemfile.lock
CHANGED
data/lib/ruby-metrics/version.rb
CHANGED
@@ -5,7 +5,7 @@ describe Metrics::Instruments::Base do
|
|
5
5
|
@base = Metrics::Instruments::Base.new
|
6
6
|
end
|
7
7
|
|
8
|
-
%w( to_i to_f to_s ).each do |method|
|
8
|
+
%w( to_i to_f to_json to_s ).each do |method|
|
9
9
|
it "should raise a NotImplementedError for ##{method}" do
|
10
10
|
lambda do
|
11
11
|
@base.send(method)
|
@@ -69,4 +69,11 @@ describe Metrics::Instruments::Counter do
|
|
69
69
|
end.should change{ @counter.to_i }.by(-1)
|
70
70
|
end
|
71
71
|
|
72
|
+
context "to_json" do
|
73
|
+
let(:json) { @counter.to_json }
|
74
|
+
it "should serialize to its current value" do
|
75
|
+
json.should == @counter.to_s
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
72
79
|
end
|
@@ -27,18 +27,16 @@ describe Metrics::Instruments::Gauge do
|
|
27
27
|
@gauge.get[:result].should == 43
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
context "to_json" do
|
31
|
+
it "should serialize the current value" do
|
32
|
+
result = 0
|
33
|
+
gauge = Metrics::Instruments::Gauge.new{ result }
|
34
|
+
|
35
|
+
gauge.to_json.should == result.to_s
|
36
|
+
|
37
|
+
result = 2
|
38
|
+
gauge.to_json.should == result.to_s
|
37
39
|
end
|
38
|
-
|
39
|
-
@gauge = Metrics::Instruments::Gauge.new &callback
|
40
|
-
|
41
|
-
@gauge.to_s.should == "{\"result\":42}"
|
42
40
|
end
|
43
41
|
|
44
42
|
end
|
@@ -39,10 +39,6 @@ describe Metrics::Instruments::Histogram do
|
|
39
39
|
@histogram.mean.should == 3.4877830882352936
|
40
40
|
end
|
41
41
|
|
42
|
-
it "should accurately represent itself using JSON" do
|
43
|
-
@histogram.to_s.should == "{\"min\":1.6,\"max\":5.1,\"mean\":3.4877830882352936,\"variance\":1.3027283328494685,\"percentiles\":{\"0.25\":2.16275,\"0.5\":4.0,\"0.75\":4.45425,\"0.95\":4.817,\"0.97\":4.8977900000000005,\"0.98\":4.933,\"0.99\":5.009570000000001}}"
|
44
|
-
end
|
45
|
-
|
46
42
|
it "should return correct values for mean, std. deviation and variance when no elements are in the histogram" do
|
47
43
|
histogram = Metrics::Instruments::Histogram.new
|
48
44
|
histogram.variance.should == 0.0
|
@@ -96,4 +92,24 @@ describe Metrics::Instruments::Histogram do
|
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
95
|
+
context "to_json" do
|
96
|
+
before(:each) do
|
97
|
+
@histogram = Metrics::Instruments::Histogram.new
|
98
|
+
@hash = JSON.parse(@histogram.to_json)
|
99
|
+
end
|
100
|
+
|
101
|
+
%w( min max mean variance ).each do |attr|
|
102
|
+
it "should serialize with the #{attr} value" do
|
103
|
+
@hash[attr].should_not be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
%w( 0.25 0.5 0.75 0.95 0.97 0.98 0.99 ).each do |percentile|
|
108
|
+
it "should have the #{percentile} percentile" do
|
109
|
+
@hash["percentiles"][percentile].should_not be_nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
99
115
|
end
|
@@ -81,6 +81,19 @@ describe Metrics::Instruments::Meter do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
end
|
84
|
+
|
85
|
+
context "to_json" do
|
86
|
+
before(:each) do
|
87
|
+
@meter = Metrics::Instruments::Meter.new
|
88
|
+
@hash = JSON.parse(@meter.to_json)
|
89
|
+
end
|
90
|
+
|
91
|
+
%w( one_minute_rate five_minute_rate fifteen_minute_rate ).each do |attr|
|
92
|
+
it "should serialize with the #{attr} value" do
|
93
|
+
@hash[attr].should_not be_nil
|
94
|
+
end
|
95
|
+
end
|
84
96
|
|
97
|
+
end
|
85
98
|
|
86
|
-
end
|
99
|
+
end
|
@@ -92,9 +92,6 @@ describe Metrics::Instruments::Timer do
|
|
92
92
|
@timer.values.sort.should == [10, 20, 20, 30, 40]
|
93
93
|
end
|
94
94
|
|
95
|
-
it "should accurately represent itself using JSON" do
|
96
|
-
@timer.to_s.should == "{\"count\":5,\"rates\":{\"one_minute_rate\":0.0,\"five_minute_rate\":0.0,\"fifteen_minute_rate\":0.0,\"unit\":\"seconds\"},\"durations\":{\"min\":10.0,\"max\":40.0,\"mean\":24.0,\"percentiles\":{\"0.25\":20.0,\"0.5\":20.0,\"0.75\":30.0,\"0.95\":38.0,\"0.97\":38.8,\"0.98\":39.2,\"0.99\":39.6},\"unit\":\"milliseconds\"}}"
|
97
|
-
end
|
98
95
|
end
|
99
96
|
|
100
97
|
context "Timing blocks of code" do
|
@@ -116,4 +113,34 @@ describe Metrics::Instruments::Timer do
|
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
116
|
+
context "to_json" do
|
117
|
+
before(:each) do
|
118
|
+
@timer = Metrics::Instruments::Timer.new
|
119
|
+
@hash = JSON.parse(@timer.to_json)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should serialize with the count value" do
|
123
|
+
@hash["count"].should_not be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
%w( one_minute_rate five_minute_rate fifteen_minute_rate ).each do |rate|
|
127
|
+
it "should serialize with the #{rate} rate" do
|
128
|
+
@hash["rates"][rate].should_not be_nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
%w( min max mean ).each do |duration|
|
133
|
+
it "should serialize with the #{duration} duration" do
|
134
|
+
@hash["durations"][duration].should_not be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
%w( 0.25 0.5 0.75 0.95 0.97 0.98 0.99 ).each do |percentile|
|
139
|
+
it "should serialize with the #{percentile} duration percentile" do
|
140
|
+
@hash["durations"]["percentiles"][percentile].should_not be_nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
119
146
|
end
|
data/spec/instruments_spec.rb
CHANGED
@@ -45,7 +45,7 @@ describe Metrics::Instruments do
|
|
45
45
|
@instruments.register(:meter, :test_meter).should == @meter
|
46
46
|
@instruments.registered.should == {:test_meter => @meter}
|
47
47
|
|
48
|
-
@instruments.to_json.should ==
|
48
|
+
@instruments.to_json.should == %({"test_meter":{"one_minute_rate":0.0,"five_minute_rate":0.0,"fifteen_minute_rate":0.0}})
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not allow for creating a gauge with no block" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 8
|
8
|
-
-
|
9
|
-
version: 0.8.
|
8
|
+
- 6
|
9
|
+
version: 0.8.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Ewart
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-06-02 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
requirements:
|
149
149
|
- - ">="
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
hash: -
|
151
|
+
hash: -4510992277753869263
|
152
152
|
segments:
|
153
153
|
- 0
|
154
154
|
version: "0"
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
hash: -
|
160
|
+
hash: -4510992277753869263
|
161
161
|
segments:
|
162
162
|
- 0
|
163
163
|
version: "0"
|