The project is in a healthy, maintained state
The statsd-rack-instrument gem enables a quick implementation of StatsD metrics. It adds metrics such as: rack_server_request_duration_seconds (histogram) and rack_server_exceptions_total (counter).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

statsd-rack-instrument

A Rack middleware to send HTTP metrics via StatsD. A building block toward achieving Grafana Dashboard like below for a Ruby web server.

Grafana dashboard for Ruby web server

What's included

The middleware exports two metrics:

  • rack_server_request_duration_seconds - a histogram representing the latency of an HTTP request with the following labels:

    • code - the response code
    • method - the request method
    • path - the request path; stripped from any identifiers, for eg. /resource/45646 becomes /resource/:id
  • rack_server_exceptions_total - a counter of unhandled exceptions with the following label:

    • exception - the class name of the error (error.class.name)

Installation

  1. Add this gem to your application:
bundle add statsd-rack-instrument
  1. Add to your config.ru
if ENV["STATSD_ADDR"].present?
  require "statsd_rack_instrument"
  use StatsDRackInstrument
end

run Rails.application # or other command for starting the app
  1. Provide necessary env vars
  • STATSD_ADDR - the address of the StatsD collector
  • STATSD_ENV - should be set to production; if not provided, then StatsD will fallback to RAILS_ENV or ENV

Check Configuration section from the statsd-instrument gem for more info.

Using with Prometheus

When combined with statsd_exporter it is possible to get exported metrics into Prometheus. Check out "Collecting Prometheus metrics from multi-process web servers, the Ruby case" blog post discussing the idea and how to achieve it.