module PrometheusMetrics
The application runs several processes (web + three Solid Queue workers) and only the web pod is scraped, so anything a worker would increment in-process would be invisible. Application metrics are therefore DERIVED FROM THE DATABASE at scrape time (a gauge refreshed on every request), which stays correct regardless of which pod does the work. Service metrics (HTTP, SQL, process) only make sense on the web pod and are enabled explicitly with PROMETHEUS_SERVICE_METRICS=1.
Constants
- APP_METRICS
- ERROR_EVENTS
- EXECUTION_STATUS
-
— Application metrics (always on, DB-derived) —
- HTTP_REQUESTS_TOTAL
-
— Service metrics (opt-in, web pod only) —
- HTTP_REQUEST_DURATION
- PROCESS_CPU_SECONDS
- PROCESS_RESIDENT_MEMORY
- REGISTRY
- SERVICE_METRICS
- SOLID_QUEUE_JOBS
- SQL_QUERIES_TOTAL
- SQL_QUERY_DURATION
- TRINO_ENGINE_STATUS
Public Class Methods
Source
# File config/initializers/prometheus.rb, line 102 def refresh! refresh_execution_status! refresh_trino_engine_status! refresh_error_events! refresh_solid_queue! refresh_process_metrics! rescue StandardError => e Rails.logger.warn("PrometheusMetrics.refresh! failed: #{e.message}") end
Refreshes every DB-derived gauge from the current database state. Called by MetricsController on each scrape so values never drift. Never raises: a metrics scrape must not take down the app.
Source
# File config/initializers/prometheus.rb, line 87 def service_metrics_enabled? = ENV["PROMETHEUS_SERVICE_METRICS"] == "1"
Whether service metrics (HTTP/SQL/process) are enabled. App metrics are always on.
Source
# File config/initializers/prometheus.rb, line 91 def setup! APP_METRICS.each { |metric| REGISTRY.register(metric) } return unless service_metrics_enabled? SERVICE_METRICS.each { |metric| REGISTRY.register(metric) } subscribe_to_instrumentation! end
Registers the always-on metrics and, when enabled, the service metrics and their ActiveSupport::Notifications subscriptions. Called once at boot.
Source
# File config/initializers/prometheus.rb, line 113 def to_text = Prometheus::Client::Formats::Text.marshal(REGISTRY)
Renders the registry in the Prometheus text exposition format.