Project

mtrc

0.15
No commit activity in last 3 years
No release in over 3 years
Minimal metric aggregation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Mtrc (Metric, for short)

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

gem install mtrc

Middleware!:

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"

Rates

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

License

MIT.