Add an optional metric exporter (#33734)
This commit is contained in:
parent
b868e30fdf
commit
59384282ed
6 changed files with 119 additions and 0 deletions
|
@ -22,6 +22,48 @@ Sidekiq.configure_server do |config|
|
|||
end
|
||||
end
|
||||
|
||||
if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
|
||||
require 'prometheus_exporter'
|
||||
require 'prometheus_exporter/instrumentation'
|
||||
|
||||
config.on :startup do
|
||||
# Ruby process metrics (memory, GC, etc)
|
||||
PrometheusExporter::Instrumentation::Process.start type: 'sidekiq'
|
||||
|
||||
# Sidekiq process metrics (concurrency, busy, etc)
|
||||
PrometheusExporter::Instrumentation::SidekiqProcess.start
|
||||
|
||||
# ActiveRecord metrics (connection pool usage)
|
||||
PrometheusExporter::Instrumentation::ActiveRecord.start(
|
||||
custom_labels: { type: 'sidekiq' },
|
||||
config_labels: [:database, :host]
|
||||
)
|
||||
|
||||
if ENV['MASTODON_PROMETHEUS_EXPORTER_SIDEKIQ_DETAILED_METRICS'] == 'true'
|
||||
# Optional, as those metrics might generate extra overhead and be redundant with what OTEL provides
|
||||
|
||||
# Per-job metrics
|
||||
config.server_middleware do |chain|
|
||||
chain.add PrometheusExporter::Instrumentation::Sidekiq
|
||||
end
|
||||
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
|
||||
|
||||
# Per-queue metrics for queues handled by this process (size, latency, etc)
|
||||
# They will be reported by every process handling those queues, so do not sum them up
|
||||
PrometheusExporter::Instrumentation::SidekiqQueue.start
|
||||
|
||||
# Global Sidekiq metrics (size of the global queues, number of jobs, etc)
|
||||
# Will be the same for every Sidekiq process
|
||||
PrometheusExporter::Instrumentation::SidekiqStats.start
|
||||
end
|
||||
end
|
||||
|
||||
at_exit do
|
||||
# Wait for the latest metrics to be reported before shutting down
|
||||
PrometheusExporter::Client.default.stop(wait_timeout_seconds: 10)
|
||||
end
|
||||
end
|
||||
|
||||
config.server_middleware do |chain|
|
||||
chain.add Mastodon::SidekiqMiddleware
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue