2017-09-10 17:25:29 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
config.pid_provider = Prometheus::Client::Support::Unicorn.method(:worker_pid_provider)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
Gitlab::Application.configure do |config|
|
|
|
|
# 0 should be Sentry to catch errors in this middleware
|
|
|
|
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
Sidekiq.configure_server do |config|
|
|
|
|
config.on(:startup) do
|
|
|
|
Gitlab::Metrics::SidekiqMetricsExporter.instance.start
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
|
2018-12-13 13:39:08 +05:30
|
|
|
Gitlab::Cluster::LifecycleEvents.on_worker_start do
|
|
|
|
defined?(::Prometheus::Client.reinitialize_on_pid_change) && Prometheus::Client.reinitialize_on_pid_change
|
|
|
|
|
|
|
|
unless Sidekiq.server?
|
|
|
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|