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.
Install the client library
Section titled “Install the client library”gem install prometheus-clientOr add it to your Gemfile:
gem "prometheus-client"Minimal example
Section titled “Minimal example”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.registryrequests_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)Scrape with Glouton
Section titled “Scrape with Glouton”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.