Retrospring/lib/retrospring/metrics.rb

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

90 lines
2.5 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,
2023-03-28 23:03:13 -07:00
},
2023-02-13 11:13:32 -08:00
).tap { _1.set 1 }
QUESTIONS_ASKED = counter(
:retrospring_questions_asked_total,
docstring: "How many questions got asked",
2023-03-28 23:03:13 -07:00
labels: %i[anonymous followers generated],
2023-02-13 11:13:32 -08:00
)
QUESTIONS_ANSWERED = counter(
:retrospring_questions_answered_total,
2023-03-28 23:03:13 -07:00
docstring: "How many questions got answered",
)
COMMENTS_CREATED = counter(
:retrospring_comments_created_total,
2023-03-28 23:03:13 -07:00
docstring: "How many comments got created",
)
2023-02-13 20:30:40 -08:00
USERS_CREATED = counter(
:retrospring_users_created_total,
2023-03-28 23:03:13 -07:00
docstring: "How many users got created",
)
USERS_DESTROYED = counter(
:retrospring_users_destroyed_total,
2023-03-28 23:03:13 -07:00
docstring: "How many users deleted their accounts",
)
2023-02-13 20:30:40 -08:00
# metrics from Sidekiq::Stats.new
SIDEKIQ = {
processed: gauge(
:sidekiq_processed,
2023-03-28 23:03:13 -07:00
docstring: "Number of jobs processed by Sidekiq",
2023-02-13 20:30:40 -08:00
),
failed: gauge(
:sidekiq_failed,
2023-03-28 23:03:13 -07:00
docstring: "Number of jobs that failed",
2023-02-13 20:30:40 -08:00
),
scheduled_size: gauge(
:sidekiq_scheduled_jobs,
2023-03-28 23:03:13 -07:00
docstring: "Number of jobs that are enqueued",
2023-02-13 20:30:40 -08:00
),
retry_size: gauge(
:sidekiq_retried_jobs,
2023-03-28 23:03:13 -07:00
docstring: "Number of jobs that are being retried",
2023-02-13 20:30:40 -08:00
),
dead_size: gauge(
:sidekiq_dead_jobs,
2023-03-28 23:03:13 -07:00
docstring: "Number of jobs that are dead",
2023-02-13 20:30:40 -08:00
),
processes_size: gauge(
:sidekiq_processes,
2023-03-28 23:03:13 -07:00
docstring: "Number of active Sidekiq processes",
2023-02-13 20:30:40 -08:00
),
queue_enqueued: gauge(
:sidekiq_queues_enqueued,
docstring: "Number of enqueued jobs per queue",
2023-03-28 23:03:13 -07:00
labels: %i[queue],
2023-02-13 20:30:40 -08:00
),
}.freeze
2023-02-13 11:13:32 -08:00
end
end