• Stars
    star
    479
  • Rank 91,752 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 13 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An experimental library to instrument ruby

Metriks Client

This is an experiment in making a threadsafe, low impact library to measure aspects of your ruby.

The library is very much a work-in-progress. It is being developed as I find needs while developing Papertrail.

Installing

The API is still in flux, but you can add this to your project by installing the gem.

To install, add this to your Gemfile:

gem 'metriks'

and re-run bundle.

Metric API Overview

Counters

Basic atomic counter. Used as an underlying metric for many of the other more advanced metrics.

increment(incr = 1)

Increment the counter. Without an argument it will increment by 1.

  counter = Metriks.counter('calls')
  counter.increment

decrement(decr = 1)

Decrement the counter. Without an argument it will decrement by 1.

  counter = Metriks.counter('calls')
  counter.decrement

count()

Return the current value of the counter.

  counter = Metriks.counter('calls')
  puts "counter: #{counter.count}"

Gauges

A gauge is an instantaneous measurement of a value.

It takes a callback to measure the value in form of a block or a callable object.

WARNING: The code in the callback is executed every time the #value method is called on the gauge. Most of the time this will be done by a metriks reporter that is running in a separate thread.

  # Callback as block
  gauge = Metriks.gauge('queue.size') { queue.size }

  # Callback as object responding to #call
  callable = proc { queue.size }
  gauge = Metriks.gauge('queue.size', callable)

set(val)

Set the current value.

  gauge = Metriks.gauge('queue_size')
  gauge.set(queue.size)

value()

Returns the value returned by the callback (if one is defined), returns the value set via #set (or the default of 0) otherwise.

  gauge = Metriks.gauge('queue_size')
  puts "queue size: #{gauge.value}"

Meters

A meter that measures the mean throughput and the one-, five-, and fifteen-minute exponentially-weighted moving average throughputs.

mark(val = 1)

Record an event with the meter. Without an argument it will record one event.

  meter = Metriks.meter('requests')
  meter.mark

count()

Returns the total number of events that have been recorded.

  meter = Metriks.meter('requests')
  puts "total: #{meter.count}"

one_minute_rate()

Returns the one-minute average rate.

  meter = Metriks.meter('requests')
  puts "rate: #{meter.one_minute_rate}/sec"

five_minute_rate()

Returns the five-minute average rate.

  meter = Metriks.meter('requests')
  puts "rate: #{meter.five_minute_rate}/sec"

fifteen_minute_rate()

Returns the fifteen-minute average rate.

  meter = Metriks.meter('requests')
  puts "rate: #{meter.fifteen_minute_rate}/sec"

mean_rate()

Returns the mean (average) rate of the events since the start of the process.

  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.

  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).

  timer = Metriks.timer('requests')
  work_result = 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.

  timer = Metriks.timer('requests')
  t = timer.time
  work
  t.stop

count()

Returns the number of measurements that have been made.

  timer = Metriks.timer('requests')
  puts "calls: #{timer.count}"

one_minute_rate()

Returns the one-minute average rate.

  meter = Metriks.timer('requests')
  puts "rate: #{meter.one_minute_rate}/sec"

five_minute_rate()

Returns the five-minute average rate.

  meter = Metriks.timer('requests')
  puts "rate: #{meter.five_minute_rate}/sec"

fifteen_minute_rate()

Returns the fifteen-minute average rate.

  meter = Metriks.timer('requests')
  puts "rate: #{meter.fifteen_minute_rate}/sec"

mean_rate()

Returns the mean (average) rate of the events since the start of the process.

  meter = Metriks.timer('requests')
  puts "rate: #{meter.mean_rate}/sec"

min()

Returns the minimum amount of time spent in the operation.

  meter = Metriks.timer('requests')
  puts "time: #{meter.min} seconds"

max()

Returns the maximum time spent in the operation.

  meter = Metriks.timer('requests')
  puts "time: #{meter.max} seconds"

mean()

Returns the mean (average) time spent in the operation.

  meter = Metriks.timer('requests')
  puts "time: #{meter.mean} seconds"

stddev()

Returns the standard deviation of the mean spent in the operation.

  meter = Metriks.timer('requests')
  puts "time: #{meter.stddev} seconds"

Utilization Timer

A specialized Timer that calculates the percentage (between 0.0 and 1.0) 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.

  meter = Metriks.utilization_timer('requests')
  puts "utilization: #{meter.one_minute_utilization * 100}%"

five_minute_utilization()

Returns the five-minute average utilization as a percentage between 0.0 and 1.0.

  meter = Metriks.utilization_timer('requests')
  puts "utilization: #{meter.five_minute_utilization * 100}%"

fifteen_minute_utilization()

Returns the fifteen-minute average utilization as a percentage between 0.0 and 1.0.

  meter = Metriks.utilization_timer('requests')
  puts "utilization: #{meter.fifteen_minute_utilization * 100}%"

mean_utilization()

Returns the mean (average) utilization as a percentage between 0.0 and 1.0 since the process started.

  meter = Metriks.utilization_timer('requests')
  puts "utilization: #{meter.mean_utilization * 100}%"

Reporter Overview

How to get metrics out of the process.

Graphite Reporter

Sends metrics to Graphite every 60 seconds.

  reporter = Metriks::Reporter::Graphite.new 'localhost', 3004
  reporter.start

Logger Reporter

Send metrics to a logger every 60 seconds.

  reporter = Metriks::Reporter::Logger.new(:logger => Logger.new('log/metrics.log'))
  reporter.start

Librato Metrics Reporter

The Librato Metrics reporter has been moved to eric/metriks-librato_metrics.

Proc Title Reporter

Provides a simple way to get up-to-date statistics from a process by updating the proctitle every 5 seconds (default).

  reporter = Metriks::Reporter::ProcTitle.new :interval => 5
  reporter.add 'reqs', 'sec' do
    Metriks.meter('rack.requests').one_minute_rate
  end
  reporter.start

will display:

501      17015 26.0  1.9 416976 246956 ?       Ss   18:54  11:43 thin reqs: 273.3/sec

Sematext Metrics Reporter

metriks-sematext gem provides reporter for sending metrics to SPM.

Application Server Configuration

Depending on how your application server operates, you may need to configure how reporters are created. Please look at Troubleshooting for more information.

Plans

An incomplete list of things I would like to see added:

  • Rack middleware to measure utilization, throughput and worker time
  • Basic reporters:
    • Rack endpoint returning JSON
    • Statsd reporter
  • Metaprogramming instrumentation hooks like Shopify's statsd-instrument

Credits

Most of the inspiration for this project comes from Coda Hale's amazing Metrics, Metrics Everywhere talk at CodeConf and his sweet Metrics Java Library.

License

Copyright (c) 2012 Eric Lindvall

Published under the MIT License, see LICENSE

More Repositories

1

pilfer

Profile Ruby code and find out exactly how slow it runs.
Ruby
258
star
2

gistr

A simple tool to post a Gist on tumblr
Ruby
70
star
3

metriksd

Server component to receive metrics from metriks
Ruby
23
star
4

pilfer-server

Collect and display Ruby line profiles reported from pilfer.
Ruby
21
star
5

metriks_log_webhook

An experimental webhook for an experimental metrics library
Ruby
17
star
6

syslog_protocol

syslog protocol for ruby
Ruby
15
star
7

whisper-rb

A ruby wrapper on the Whisper database from Graphite
Python
14
star
8

rubyrrdtool

RubyRRDtool provides ruby bindings for RRDtool functions (via librrd), with functionality comparable to the native RRDtool perl bindings.
C
14
star
9

p2met

Papertrail l2met-style webhook
Ruby
12
star
10

flickvimeo

A simple tool to use AirFlick to send Vimeo videos to your AppleTV
Ruby
8
star
11

click_to_call

A simple Adhearsion click-to-call example
Ruby
7
star
12

metriks-librato_metrics

Librato Metrics reporter for Metriks
Ruby
7
star
13

papertrail_prowl_webhook

Papertrail webhook to send alerts to Prowl for iOS push notification
Ruby
6
star
14

sevenscale-scout-plugins

A bunch of plugins for scout
Ruby
6
star
15

metriksd_reporter

A reporter to send metrics from metriks to metriks_server
Ruby
6
star
16

section_one

A multi-service metrics viewer inspired by FiveRuns Dash
Ruby
5
star
17

tender_summary

A simple tool to email your pending Tender discussions
Ruby
5
star
18

gemist

Capistrano recipes for gem installation
Ruby
5
star
19

librato_metrics_client

A purely experimental metrics client
Ruby
4
star
20

phoenix_status

A little AGI to speak the current MarsPhoenix Twitter status
Ruby
4
star
21

papertrail_librato_webhook

Basic webhook to send metrics to Silverline from Papertrail
Ruby
4
star
22

docker-srtla

Docker container for running srtla
Shell
3
star
23

app_swift

A mirror of the asterisk swift app written by Darren Sessions
C
3
star
24

signal

Signal bot for #jruby
Ruby
2
star
25

nested-layouts

Rails 2.1.1 broke nested-layouts, this is the "fixed" version
Ruby
2
star
26

dashup

Simple greasemonkey fun for dash.fiveruns.com
JavaScript
2
star
27

dharma

Ruby futures and promises library in the spirit of Scala
Ruby
2
star
28

nested_scenarios

FixtureScenarios, FixtureScenariosBuilder, Yaml and Ruby in one big mix for Rails.
Ruby
2
star
29

bunny-ext

Reliable socket timeouts for the Bunny amqp gem
Ruby
1
star
30

jetson-kernel-build

Make a custom kernel for the Jetson Nano
Dockerfile
1
star
31

activerecord-mysql2-adapter

An ActiveRecord 2.3 adapter for the mysql2 gem
1
star
32

appconference

Fork of http://sourceforge.net/projects/appconference
C
1
star
33

solar_power

Display solar power generation on a LaMetric
Ruby
1
star
34

syslog-ng-3.3

C
1
star
35

multi_field_group_by

Adds functionality from http://rails.lighthouseapp.com/projects/8994/tickets/120 as a plugin
Ruby
1
star
36

metriks-graphite

Graphite reporter for metriks
Ruby
1
star
37

github-flavored-markdown

JavaScript
1
star