A simple Rack application which shows how to use prometheus' Rack::Exporter
and Rack::Collector
rack middlwares.
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.
Start a Prometheus server with the provided config:
prometheus -config.file ./prometheus.yaml
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.
The example shown in config.ru
is a trivial rack application
using the default collector and exporter middlewares.
In order to use a custom label builder in the collector, change the line to something like this:
use Prometheus::Client::Rack::Collector do |env|
{
method: env['REQUEST_METHOD'].downcase,
host: env['HTTP_HOST'].to_s,
path: env['PATH_INFO'].to_s,
http_version: env['HTTP_VERSION'].to_s,
}
end