Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 2.24 KB

README.md

File metadata and controls

75 lines (55 loc) · 2.24 KB

Rack example

A simple Rack application which shows how to use the included Prometheus::Middleware::Exporter and Prometheus::Middleware::Collector middlwares.

Run the example

Standalone

Execute the provided run script:

bundle install
bundle exec ./run

This will start the rack app, run a few requests against it, print the output of /metrics and terminate.

With a Prometheus server

Start a Prometheus server with the provided config:

prometheus --config.file ./prometheus.yml

In another terminal, start the application server:

bundle install
bundle exec unicorn -c ./unicorn.conf

You can now open the example app and its metrics page to inspect the output. The running Prometheus server can be used to play around with the metrics.

Collector

The example shown in config.ru is a trivial rack application using the default collector and exporter middlewares.

Currently, the collector middleware doesn't offer any flexibility around label keys or values (see #111). If you have more sophisticated requirements, we recommend creating your own collector middleware.

If your requirements are minimal, one option is to subclass Prometheus::Middleware::Collector and override the methods you need to. For example, if you want to change the way IDs are stripped from the path you could override the appropriate method:

require 'prometheus/middleware/collector'
module Prometheus
  module Middleware
    class MyCollector < Collector
      def strip_ids_from_path(path)
        super(path)
          .gsub(/8675309/, ':jenny\\1')
      end
    end
  end
end

and use your class in config.ru instead.

Note: Prometheus::Middleware::Collector isn't explicitly designed to be subclassed, so the internals are liable to change at any time, including in patch releases. Overriding its methods is done at your own risk!