File: README.markdown

package info (click to toggle)
ruby-mtrc 0.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 88 kB
  • sloc: ruby: 104; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Mtrc (Metric, for short)
===

A small library to accumulate metrics and extract basic statistics from them.
Want a latency profile of your Rack app? Boom.

    gem install mtrc
 
Middleware all up in this bitch:

    class MyMetrics
      def initialize(app)
        @app = app
        @m = Mtrc::SortedSamples.new

        Thread.new do
          sleep 100
          puts <<EOF
    Min:      #{@m.min}
    Median:   #{@m.median}
    95th %:   #{@m % 95}
    99th %:   #{@m % 99}
    99.9th %: #{@m.at .999}
    Max:      #{@m.max}
    EOF
          @m = Mtrc::SortedSamples.new
        end
      end

      def call(env)
        t1 = Time.now
        r = @app.call env
        dt = Time.now - t1

        @m << dt
        r
      end        
    end

Which requests take the longest?

    @m << Mtrc::Sample.new dt, env[:PATH_INFO]
    (@m % 95).value # => "?bacon=strips&bacon=strips&bacon=strips"

It's MIT licensed, bro. Pull requests? Roll one up homie.

Rates
---

    r = Mtrc::Rate.new
    10.times do
      r.tick 2
    end
    sleep 1
    r.rate #=> 19.999...