2017-09-10 17:25:29 +05:30
|
|
|
require 'prometheus/client'
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
# Keep separate directories for separate processes
|
|
|
|
def prometheus_default_multiproc_dir
|
|
|
|
return unless Rails.env.development? || Rails.env.test?
|
|
|
|
|
|
|
|
if Sidekiq.server?
|
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir/sidekiq')
|
|
|
|
elsif defined?(Unicorn::Worker)
|
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir/unicorn')
|
|
|
|
elsif defined?(::Puma)
|
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir/puma')
|
|
|
|
else
|
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
Prometheus::Client.configure do |config|
|
2019-09-30 21:07:59 +05:30
|
|
|
config.logger = Rails.logger # rubocop:disable Gitlab/RailsLogger
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
config.initial_mmap_file_size = 4 * 1024
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
config.multiprocess_files_dir = ENV['prometheus_multiproc_dir'] || prometheus_default_multiproc_dir
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
config.pid_provider = Prometheus::PidProvider.method(:worker_id)
|
2017-09-10 17:25:29 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
Gitlab::Metrics::Samplers::RubySampler.initialize_instance(Settings.monitoring.ruby_sampler_interval).start
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
Gitlab::Cluster::LifecycleEvents.on_master_start do
|
|
|
|
if defined?(::Unicorn)
|
|
|
|
Gitlab::Metrics::Samplers::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_sampler_interval).start
|
|
|
|
elsif defined?(::Puma)
|
2019-09-04 21:01:54 +05:30
|
|
|
Gitlab::Metrics::Samplers::PumaSampler.initialize_instance(Settings.monitoring.puma_sampler_interval).start
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|