File: metrics.rb

package info (click to toggle)
ruby-cabin 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: ruby: 1,306; makefile: 12
file content (41 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "rubygems"
require "cabin"
require "logger"

# Logging::... is something I'm implemented and experimenting with.
@logger = Cabin::Channel.new

# Metrics can be subscribed-to as well.
@logger.subscribe(Logger.new(STDOUT))

counter = @logger.metrics.counter("mycounter")
counter.incr
counter.incr
counter.incr
counter.decr

meter = @logger.metrics.meter("something", "hello-world")
meter.mark
meter.mark
meter.mark

# If nil is passed as the 'instance' then the metric class name will be
# used instead.
timer = @logger.metrics.timer("ticktock")
5.times do
  timer.time do
    sleep rand * 2
  end
end

3.times do
  # Another way to do timing.
  clock = timer.time
  sleep rand * 2
  clock.stop
end

# Loop through all metrics:
@logger.metrics.each do |metric|
  @logger.info(metric.inspect)
end