0
0
Fork 0

Add an optional metric exporter (#33734)

This commit is contained in:
Renaud Chaput 2025-01-27 13:52:30 +01:00 committed by GitHub
parent b868e30fdf
commit 59384282ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 119 additions and 0 deletions

View file

@ -17,6 +17,27 @@ workers ENV.fetch('WEB_CONCURRENCY') { 2 }.to_i
preload_app!
if ENV['MASTODON_PROMETHEUS_EXPORTER_ENABLED'] == 'true'
require 'prometheus_exporter'
require 'prometheus_exporter/instrumentation'
on_worker_boot do
# Ruby process metrics (memory, GC, etc)
PrometheusExporter::Instrumentation::Process.start(type: 'puma')
# ActiveRecord metrics (connection pool usage)
PrometheusExporter::Instrumentation::ActiveRecord.start(
custom_labels: { type: 'puma' }, # optional params
config_labels: [:database, :host] # optional params
)
end
after_worker_boot do
# Puma metrics
PrometheusExporter::Instrumentation::Puma.start unless PrometheusExporter::Instrumentation::Puma.started?
end
end
on_worker_boot do
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.establish_connection