debian-mirror-gitlab/lib/api/sidekiq_metrics.rb

69 lines
1.8 KiB
Ruby
Raw Normal View History

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