Retrospring/app/controllers/metrics_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
797 B
Ruby
Raw Normal View History

2023-02-13 11:13:32 -08:00
# frozen_string_literal: true
require "prometheus/client/formats/text"
class MetricsController < ActionController::API
include ActionController::MimeResponds
def show
2023-02-13 20:30:40 -08:00
fetch_sidekiq_metrics
2023-02-13 11:13:32 -08:00
render plain: metrics
end
private
2023-02-13 20:30:40 -08:00
SIDEKIQ_STATS_METHODS = %i[
processed
failed
scheduled_size
retry_size
dead_size
processes_size
].freeze
def fetch_sidekiq_metrics
stats = Sidekiq::Stats.new
SIDEKIQ_STATS_METHODS.each do |key|
Retrospring::Metrics::SIDEKIQ[key].set stats.public_send(key)
end
stats.queues.each do |queue, value|
Retrospring::Metrics::SIDEKIQ[:queue_enqueued].set value, labels: { queue: }
end
end
2023-02-13 11:13:32 -08:00
def metrics
2023-02-13 20:30:40 -08:00
Prometheus::Client::Formats::Text.marshal(Retrospring::Metrics::PROMETHEUS)
2023-02-13 11:13:32 -08:00
end
end