Coder Social home page Coder Social logo

iq-scm / ruby-metrics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnewart/ruby-metrics

0.0 0.0 0.0 494 KB

Metrics for ruby - a Ruby implementation of metrics inspired by @coda's JVM metrics for those of us in Ruby land

License: MIT License

Ruby 100.00%

ruby-metrics's Introduction

Build Status

What is this?

This is a Ruby version of performance metrics inspired by metrics developed by Coda Hale at Yammer. Currently this is under heavy development -- it needs Gem packaging, more features, validation of metrics, more functional testing, and a little better test coverage. Pull requests happily accepted, please include docs and tests where possible!

What needs to be done?

Among other important things, this needs to be made more thread-safe. I'm currently looking at Mr. Nutter's ruby-atomic gem for making this less tedious but any suggestions are welcome!

What's in this?

Right now, I have:

  • Counters
  • Meters
  • Gauges
  • Histograms w/ uniform sampling
  • Histograms w/ exponentially decaying sampling
  • Timers

Getting Started

The goal of ruby-metrics is to get up and running quickly. You start an agent, register some instruments, and they're exported over HTTP via JSON. For example, getting started with a counter would look like this:

@metrics = Metrics::Agent.new

counter = @metrics.counter :my_counter
counter.incr
counter.incr

puts @metrics.to_json
#=> {"my_counter":"2"}

Integration

Integrating ruby-metrics into existing applications is entirely up to your needs. Provided options include:

  • Embedded WEBrick listener:

    This runs a background thread and enables HTTP access to a local port (8001 by default) for a JSON representation of the current metrics.

require 'ruby-metrics/integration/webrick'
@agent = Metrics::Agent.new
@agent.start(:port => 8081)
  • Rack Middleware:

    This will add metrics such as requests (a timer) as well as counters for each class of HTTP status code (1xx, 2xx, etc). Also counts uncaught exceptions before reraising. Provides a configurable path option (:show) to trigger the return of the metrics (as JSON) when the request path matches exactly (a string), as a regular expression, or as any object that responds to call for custom logic (passed the whole env).

require 'ruby-metrics'
@agent = Metrics::Agent.new

use Metrics::Integration::Rack::Middleware, :agent => @agent, :show => '/stats'

run app
  • Rack Endpoint:

    Use this to expose an endpoint for external consumption for your metrics. Works best when used with a URLMap or mounted in addition to other routes, like Rails' mount route matcher.

require 'ruby-metrics'
@agent = Metrics::Agent.new

run Metrics::Integration::Rack::Endpoint.new(:agent => @agent)

or

# in config/router.rb
mount Metrics::Integration::Rack::Endpoint.new(:agent => @agent)

License

Copyright 2011-2014 John Ewart [email protected]. Released under the MIT license. See the file LICENSE for further details.

ruby-metrics's People

Contributors

alindeman avatar colindkelley avatar dj2 avatar eric avatar garethr avatar johnewart avatar mtodd avatar richardiux avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.