gitlab-org--gitlab-foss/config/initializers/7_prometheus_metrics.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

require 'prometheus/client'
require 'prometheus/client/support/unicorn'
Prometheus::Client.configure do |config|
config.logger = Rails.logger
config.initial_mmap_file_size = 4 * 1024
config.multiprocess_files_dir = ENV['prometheus_multiproc_dir']
if Rails.env.development? || Rails.env.test?
config.multiprocess_files_dir ||= Rails.root.join('tmp/prometheus_multiproc_dir')
end
2017-09-05 19:26:31 -04:00
config.pid_provider = -> do
2017-11-23 17:10:38 -05:00
worker_id = Prometheus::Client::Support::Unicorn.worker_id
if worker_id.nil?
2017-09-05 19:26:31 -04:00
"process_pid_#{Process.pid}"
else
2017-11-23 17:10:38 -05:00
"worker_id_#{worker_id}"
2017-09-05 19:26:31 -04:00
end
end
end
Gitlab::Application.configure do |config|
# 0 should be Sentry to catch errors in this middleware
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
end
Sidekiq.configure_server do |config|
config.on(:startup) do
Gitlab::Metrics::SidekiqMetricsExporter.instance.start
end
end
2017-09-05 19:26:31 -04:00
if Gitlab::Metrics.prometheus_metrics_enabled?
unless Sidekiq.server?
Gitlab::Metrics::Samplers::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_sampler_interval).start
end
2017-09-05 19:26:31 -04:00
Gitlab::Metrics::Samplers::RubySampler.initialize_instance(Settings.monitoring.ruby_sampler_interval).start
end