Retrospring/lib/retrospring/metrics.rb

37 lines
1018 B
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:
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]
)
end
end