2017-07-19 08:54:39 +00:00
|
|
|
require 'prometheus/client'
|
2017-08-29 13:45:19 +00:00
|
|
|
require 'prometheus/client/support/unicorn'
|
2017-07-19 08:54:39 +00:00
|
|
|
|
|
|
|
Prometheus::Client.configure do |config|
|
|
|
|
config.logger = Rails.logger
|
|
|
|
|
|
|
|
config.initial_mmap_file_size = 4 * 1024
|
|
|
|
config.multiprocess_files_dir = ENV['prometheus_multiproc_dir']
|
|
|
|
|
2017-07-25 12:19:09 +00:00
|
|
|
if Rails.env.development? || Rails.env.test?
|
2017-07-19 08:54:39 +00:00
|
|
|
config.multiprocess_files_dir ||= Rails.root.join('tmp/prometheus_multiproc_dir')
|
|
|
|
end
|
2017-08-29 13:45:19 +00:00
|
|
|
|
2017-12-07 16:47:23 +00:00
|
|
|
config.pid_provider = Prometheus::Client::Support::Unicorn.method(:worker_pid_provider)
|
2017-07-19 08:54:39 +00:00
|
|
|
end
|
2017-08-07 17:13:02 +00:00
|
|
|
|
2017-11-22 23:26:50 +00:00
|
|
|
Gitlab::Application.configure do |config|
|
|
|
|
# 0 should be Sentry to catch errors in this middleware
|
|
|
|
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
|
|
|
|
end
|
|
|
|
|
2017-08-07 17:13:02 +00:00
|
|
|
Sidekiq.configure_server do |config|
|
|
|
|
config.on(:startup) do
|
|
|
|
Gitlab::Metrics::SidekiqMetricsExporter.instance.start
|
|
|
|
end
|
|
|
|
end
|
2017-08-10 14:18:37 +00:00
|
|
|
|
2018-05-24 13:02:39 +00:00
|
|
|
if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
|
2018-10-20 18:00:19 +00:00
|
|
|
Gitlab::Cluster::LifecycleEvents.on_worker_start do
|
|
|
|
defined?(::Prometheus::Client.reinitialize_on_pid_change) && Prometheus::Client.reinitialize_on_pid_change
|
|
|
|
|
2019-05-29 12:27:44 +00:00
|
|
|
if defined?(::Unicorn)
|
2018-10-20 18:00:19 +00:00
|
|
|
Gitlab::Metrics::Samplers::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_sampler_interval).start
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Metrics::Samplers::RubySampler.initialize_instance(Settings.monitoring.ruby_sampler_interval).start
|
2017-11-02 20:23:23 +00:00
|
|
|
end
|
2019-05-29 12:27:44 +00:00
|
|
|
|
|
|
|
if defined?(::Puma)
|
|
|
|
Gitlab::Cluster::LifecycleEvents.on_master_start do
|
|
|
|
Gitlab::Metrics::Samplers::PumaSampler.initialize_instance(Settings.monitoring.puma_sampler_interval).start
|
|
|
|
end
|
|
|
|
end
|
2018-10-20 18:00:19 +00:00
|
|
|
end
|
2017-11-02 20:23:23 +00:00
|
|
|
|
2018-10-20 18:00:19 +00:00
|
|
|
Gitlab::Cluster::LifecycleEvents.on_master_restart do
|
|
|
|
# The following is necessary to ensure stale Prometheus metrics don't
|
|
|
|
# accumulate over time. It needs to be done in this hook as opposed to
|
|
|
|
# inside an init script to ensure metrics files aren't deleted after new
|
|
|
|
# unicorn workers start after a SIGUSR2 is received.
|
|
|
|
prometheus_multiproc_dir = ENV['prometheus_multiproc_dir']
|
|
|
|
if prometheus_multiproc_dir
|
|
|
|
old_metrics = Dir[File.join(prometheus_multiproc_dir, '*.db')]
|
|
|
|
FileUtils.rm_rf(old_metrics)
|
|
|
|
end
|
2017-09-05 23:26:31 +00:00
|
|
|
end
|