Skip to content

Monitoring Ruby Applications with Prometheus

Professional

You can instrument your Ruby application with the official Prometheus Ruby client library and let the Glouton agent scrape its /metrics endpoint.

Terminal window
gem install prometheus-client

Or add it to your Gemfile:

gem "prometheus-client"

The snippet below defines a counter and exposes it on http://localhost:8080/metrics using the Rack middleware shipped with the client:

require "rack"
require "prometheus/client"
require "prometheus/middleware/exporter"
registry = Prometheus::Client.registry
requests_total = registry.counter(
:myapp_requests_total,
docstring: "Total number of processed requests.",
)
app = Rack::Builder.new do
use Prometheus::Middleware::Exporter
run ->(env) {
requests_total.increment
[200, { "Content-Type" => "text/plain" }, ["Hello"]]
}
end
Rack::Handler::WEBrick.run(app, Port: 8080)

Configure Glouton to scrape your application by adding the following to /etc/glouton/conf.d/50-prometheus-metrics.conf:

metric:
prometheus:
targets:
- url: "http://localhost:8080/metrics"
name: "my_ruby_application"
allow_metrics:
- "myapp_requests_total"

Restart the agent to apply the configuration. See Prometheus Monitoring for the full list of options, including Docker label auto-discovery and Kubernetes annotations.