Permalink
Browse files

Continue to improve the README documentation

  • Loading branch information...
1 parent 19225a9 commit 81a80ba3ffb20e8e70133bd36444c562f0082bc7 @eric committed Feb 5, 2012
Showing with 183 additions and 18 deletions.
  1. +158 −13 README.md
  2. +24 −5 lib/metriks/utilization_timer.rb
  3. +1 −0 test/utilization_timer_test.rb
View
171 README.md
@@ -63,6 +63,15 @@ Record an event with the meter. Without an argument it will record one event.
meter.mark
```
+### count()
+
+Returns the total number of events that have been recorded.
+
+``` ruby
+ meter = Metriks.meter('requests')
+ puts "total: #{meter.total}"
+```
+
### one_minute_rate()
Returns the one-minute average rate.
@@ -90,45 +99,181 @@ Returns the fifteen-minute average rate.
puts "rate: #{meter.fifteen_minute_rater}/sec"
```
+### mean_rate()
+
+Returns the mean (average) rate of the events since the start of the process.
+
+``` ruby
+ meter = Metriks.meter('requests')
+ puts "rate: #{meter.mean_rate}/sec"
+```
+
## Timers
A timer that measures the average time as well as throughput metrics via
a meter.
+### update(duration)
+
+Records the duration of an operation. This normally wouldn't need to be
+called — the `#time` method is provided to simplify recording a duration.
+
+``` ruby
+ timer = Metriks.timer('requests')
+ t0 = Time.now
+ work
+ timer.update(Time.now - t0)
+```
+
+### time(callable = nil, &block)
+
+Measure the amount of time a proc takes to execute. Takes either a block
+or an object responding to `#call` (normally a `proc` or `lambda`).
+
``` ruby
timer = Metriks.timer('requests')
timer.time do
work
end
+```
+
+If neither a block or an object is passed to the method, an object that
+responds to `#stop` will be returned. When `#stop` is called, the time
+will be recorded.
+``` ruby
+ timer = Metriks.timer('requests')
t = timer.time
work
t.stop
+```
+
+### count()
+
+Returns the number of measurements that have been made.
+
+``` ruby
+ timer = Metriks.timer('requests')
+ puts "calls: #{timer.count}"
+```
+
+### one_minute_rate()
+
+Returns the one-minute average rate.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "rate: #{meter.one_minute_rater}/sec"
+```
+
+### five_minute_rate()
+
+Returns the five-minute average rate.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "rate: #{meter.five_minute_rater}/sec"
+```
+
+### fifteen_minute_rate()
+
+Returns the fifteen-minute average rate.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "rate: #{meter.fifteen_minute_rater}/sec"
+```
+
+### mean_rate()
+
+Returns the mean (average) rate of the events since the start of the process.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "rate: #{meter.mean_rate}/sec"
+```
+
+### min()
+
+Returns the minimum amount of time spent in the operation.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "time: #{meter.min} seconds"
+```
+
+### max()
+
+Returns the maximum time spent in the operation.
- puts "average request time: #{timer.mean}"
- puts "rate: #{timer.five_minute_rate}/sec"
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "time: #{meter.max} seconds"
+```
+
+### mean()
+
+Returns the mean (average) time spent in the operation.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "time: #{meter.mean} seconds"
+```
+
+### stddev()
+
+Returns the standard deviation of the mean spent in the operation.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "time: #{meter.stddev} seconds"
```
## Utilization Timer
-A specialized timer that calculates the percentage (between 0 and 1) of
-wall-clock time that was spent.
+A specialized `Timer` that calculates the percentage (between 0 and 1) of
+wall-clock time that was spent. It includes all of the methods of `Timer`.
+
+
+### one_minute_utilization()
+
+Returns the one-minute average utilization as a percentage between 0.0 and 1.0.
``` ruby
- timer = Metriks.utilization_timer('requests')
- timer.time do
- work
- end
+ meter = Metriks.timer('requests')
+ puts "utilization: #{meter.one_minute_rater * 100}%"
+```
- t = timer.time
- work
- t.stop
+### five_minute_utilization()
+
+Returns the five-minute average utilization as a percentage between 0.0 and 1.0.
- puts "average request time: #{timer.mean}"
- puts "utilization: #{timer.one_minute_rate * 100.0}%"
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "utilization: #{meter.five_minute_rater * 100}%"
+```
+
+### fifteen_minute_utilization()
+
+Returns the fifteen-minute average utilization as a percentage between 0.0 and 1.0.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "utilization: #{meter.fifteen_minute_rater * 100}%"
```
+### fifteen_minute_utilization()
+
+Returns the mean (average) utilization as a percentage between 0.0 and 1.0
+since the process started.
+
+``` ruby
+ meter = Metriks.timer('requests')
+ puts "utilization: #{meter.mean_utilization * 100}%"
+```
+
+
# Reporter Overview
## Proc Title Reporter
@@ -2,23 +2,42 @@
module Metriks
class UtilizationTimer < Metriks::Timer
+ def initialize
+ super
+ @duration_meter = Metriks::Meter.new
+ end
+
+ def clear
+ super
+ @duration_meter.clear
+ end
+
def update(duration)
+ super
if duration >= 0
- @meter.mark(duration)
- @histogram.update(duration)
+ @duration_meter.mark(duration)
end
end
def one_minute_utilization
- one_minute_rate
+ @duration_meter.one_minute_rate
end
def five_minute_utilization
- five_minute_rate
+ @duration_meter.five_minute_rate
end
def fifteen_minute_utilization
- fifteen_minute_rate
+ @duration_meter.fifteen_minute_rate
+ end
+
+ def mean_utilization
+ @duration_meter.mean_rate
+ end
+
+ def stop
+ super
+ @duration_meter.stop
end
end
end
@@ -18,6 +18,7 @@ def test_timer
end
@timer.instance_variable_get(:@meter).tick
+ @timer.instance_variable_get(:@duration_meter).tick
assert_in_delta 0.25, @timer.one_minute_utilization, 0.1
end

0 comments on commit 81a80ba

Please sign in to comment.