2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-14 19:38:54 -04:00
|
|
|
require 'sidekiq/api'
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class SidekiqMetrics < ::API::Base
|
2016-06-14 19:38:54 -04:00
|
|
|
before { authenticated_as_admin! }
|
|
|
|
|
2022-04-05 08:10:23 -04:00
|
|
|
feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
|
2020-10-30 14:08:56 -04:00
|
|
|
|
2016-06-14 19:38:54 -04:00
|
|
|
helpers do
|
|
|
|
def queue_metrics
|
2022-05-13 11:07:43 -04:00
|
|
|
::Gitlab::SidekiqConfig.routing_queues.each_with_object({}) do |queue_name, hash|
|
|
|
|
queue = Sidekiq::Queue.new(queue_name)
|
2016-06-14 19:38:54 -04:00
|
|
|
hash[queue.name] = {
|
|
|
|
backlog: queue.size,
|
|
|
|
latency: queue.latency.to_i
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def process_metrics
|
2020-09-16 11:09:32 -04:00
|
|
|
Sidekiq::ProcessSet.new(false).map do |process|
|
2016-06-14 19:38:54 -04:00
|
|
|
{
|
2022-08-12 11:11:42 -04:00
|
|
|
hostname: process['hostname'],
|
|
|
|
pid: process['pid'],
|
|
|
|
tag: process['tag'],
|
|
|
|
started_at: Time.at(process['started_at']),
|
|
|
|
queues: process['queues'],
|
|
|
|
labels: process['labels'],
|
2016-06-14 19:38:54 -04:00
|
|
|
concurrency: process['concurrency'],
|
2022-08-12 11:11:42 -04:00
|
|
|
busy: process['busy']
|
2016-06-14 19:38:54 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def job_stats
|
|
|
|
stats = Sidekiq::Stats.new
|
|
|
|
{
|
|
|
|
processed: stats.processed,
|
|
|
|
failed: stats.failed,
|
2019-11-18 07:06:03 -05:00
|
|
|
enqueued: stats.enqueued,
|
|
|
|
dead: stats.dead_size
|
2016-06-14 19:38:54 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-23 07:34:08 -05:00
|
|
|
desc 'Get the Sidekiq queue metrics'
|
2016-06-14 19:38:54 -04:00
|
|
|
get 'sidekiq/queue_metrics' do
|
|
|
|
{ queues: queue_metrics }
|
|
|
|
end
|
|
|
|
|
2016-11-23 07:34:08 -05:00
|
|
|
desc 'Get the Sidekiq process metrics'
|
2016-06-14 19:38:54 -04:00
|
|
|
get 'sidekiq/process_metrics' do
|
|
|
|
{ processes: process_metrics }
|
|
|
|
end
|
|
|
|
|
2016-11-23 07:34:08 -05:00
|
|
|
desc 'Get the Sidekiq job statistics'
|
2016-06-14 19:38:54 -04:00
|
|
|
get 'sidekiq/job_stats' do
|
|
|
|
{ jobs: job_stats }
|
|
|
|
end
|
|
|
|
|
2016-11-23 07:34:08 -05:00
|
|
|
desc 'Get the Sidekiq Compound metrics. Includes queue, process, and job statistics'
|
2016-06-14 19:38:54 -04:00
|
|
|
get 'sidekiq/compound_metrics' do
|
|
|
|
{ queues: queue_metrics, processes: process_metrics, jobs: job_stats }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|