Module: Lepus::Prometheus
- Defined in:
- lib/lepus/prometheus.rb,
lib/lepus/prometheus/collector.rb,
lib/lepus/prometheus/instrumentation.rb
Overview
Optional integration with the prometheus_exporter gem. Require “lepus/prometheus” in your Lepus process to start shipping metrics to a running prometheus_exporter server via the default client.
On the prometheus_exporter server side, load the companion collector:
prometheus_exporter -a lepus/prometheus/collector
Defined Under Namespace
Modules: Instrumentation Classes: Collector
Constant Summary collapse
- DEFAULT_QUEUE_POLL_INTERVAL =
30
Class Attribute Summary collapse
Class Method Summary collapse
-
.emit(metric, **data) ⇒ Object
Emit an opaque metric payload to the exporter server.
- .stop_watching_queues ⇒ Object
-
.watch_queues(interval: DEFAULT_QUEUE_POLL_INTERVAL, api: nil) ⇒ Object
Start polling the RabbitMQ management API for queue-level gauges.
Class Attribute Details
.client ⇒ Object
21 22 23 |
# File 'lib/lepus/prometheus.rb', line 21 def client @client ||= ::PrometheusExporter::Client.default end |
Class Method Details
.emit(metric, **data) ⇒ Object
Emit an opaque metric payload to the exporter server. Silently swallows transport errors so instrumentation cannot break the caller; non-transport bugs surface as debug logs.
28 29 30 31 32 33 |
# File 'lib/lepus/prometheus.rb', line 28 def emit(metric, **data) client.send_json(type: "lepus", metric: metric.to_s, **data) rescue => e Lepus.logger.debug { "[Lepus::Prometheus] emit(#{metric}) failed: #{e.class}: #{e.}" } nil end |
.stop_watching_queues ⇒ Object
43 44 45 |
# File 'lib/lepus/prometheus.rb', line 43 def stop_watching_queues Instrumentation::QueuePoller.stop end |
.watch_queues(interval: DEFAULT_QUEUE_POLL_INTERVAL, api: nil) ⇒ Object
Start polling the RabbitMQ management API for queue-level gauges. Safe to call once per process. Requires “lepus/web/management_api”.
37 38 39 40 41 |
# File 'lib/lepus/prometheus.rb', line 37 def watch_queues(interval: DEFAULT_QUEUE_POLL_INTERVAL, api: nil) require "lepus/web/management_api" api ||= Lepus::Web::ManagementAPI.new Instrumentation::QueuePoller.start(interval: interval, api: api) end |