Retrospring/lib/retrospring/metrics.rb

80 lines
2.2 KiB
Ruby
Raw Normal View History

2023-02-13 11:13:32 -08:00
# frozen_string_literal: true
module Retrospring
module Metrics
PROMETHEUS = Prometheus::Client.registry
# avoid re-registering metrics to make autoreloader happy during dev:
2023-02-13 11:13:32 -08:00
class << self
%i[counter gauge histogram summary].each do |meth|
define_method meth do |name, *args, **kwargs|
PROMETHEUS.public_send(meth, name, *args, **kwargs)
rescue Prometheus::Client::Registry::AlreadyRegisteredError
raise unless Rails.env.development?
PROMETHEUS.unregister name
retry
end
end
end
VERSION_INFO = gauge(
:retrospring_version_info,
docstring: "Information about the currently running version",
labels: [:version],
preset_labels: {
version: Retrospring::Version.to_s,
}
).tap { _1.set 1 }
QUESTIONS_ASKED = counter(
:retrospring_questions_asked_total,
docstring: "How many questions got asked",
labels: %i[anonymous followers generated]
)
QUESTIONS_ANSWERED = counter(
:retrospring_questions_answered_total,
docstring: "How many questions got answered"
)
COMMENTS_CREATED = counter(
:retrospring_comments_created_total,
docstring: "How many comments got created"
)
2023-02-13 20:30:40 -08:00
# metrics from Sidekiq::Stats.new
SIDEKIQ = {
processed: gauge(
:sidekiq_processed,
docstring: "Number of jobs processed by Sidekiq"
),
failed: gauge(
:sidekiq_failed,
docstring: "Number of jobs that failed"
),
scheduled_size: gauge(
:sidekiq_scheduled_jobs,
docstring: "Number of jobs that are enqueued"
),
retry_size: gauge(
:sidekiq_retried_jobs,
docstring: "Number of jobs that are being retried"
),
dead_size: gauge(
:sidekiq_dead_jobs,
docstring: "Number of jobs that are dead"
),
processes_size: gauge(
:sidekiq_processes,
docstring: "Number of active Sidekiq processes"
),
queue_enqueued: gauge(
:sidekiq_queues_enqueued,
docstring: "Number of enqueued jobs per queue",
labels: %i[queue]
),
}.freeze
2023-02-13 11:13:32 -08:00
end
end