Module: LcpRuby::Metrics::MetricDefinitions

Defined in:
lib/lcp_ruby/metrics/metric_definitions.rb

Constant Summary collapse

REQUEST_DURATION =

Request metrics

{
  name: :lcp_ruby_request_duration_seconds,
  type: :histogram,
  description: "HTTP request duration in seconds",
  labels: [ :presenter, :view_group, :model, :action, :method, :status ]
}.freeze
REQUEST_TOTAL =
{
  name: :lcp_ruby_requests_total,
  type: :counter,
  description: "Total HTTP requests",
  labels: [ :presenter, :view_group, :model, :action, :method, :status ]
}.freeze
ERROR_TOTAL =

Error metrics

{
  name: :lcp_ruby_errors_total,
  type: :counter,
  description: "Total errors recorded",
  labels: [ :subsystem, :error_class ]
}.freeze
CACHE_OPERATIONS_TOTAL =

Cache metrics

{
  name: :lcp_ruby_cache_operations_total,
  type: :counter,
  description: "Total cache operations",
  labels: [ :cache, :operation ]
}.freeze
WORKFLOW_TRANSITIONS_TOTAL =

Workflow metrics

{
  name: :lcp_ruby_workflow_transitions_total,
  type: :counter,
  description: "Total workflow transitions",
  labels: [ :model, :from_state, :to_state ]
}.freeze
PERMISSION_CHECKS_TOTAL =

Permission metrics

{
  name: :lcp_ruby_permission_checks_total,
  type: :counter,
  description: "Total permission checks",
  labels: [ :model, :result ]
}.freeze
BOOT_TIMESTAMP =

Boot metrics

{
  name: :lcp_ruby_boot_timestamp_seconds,
  type: :gauge,
  description: "Unix timestamp of last successful boot"
}.freeze
MODELS_LOADED =
{
  name: :lcp_ruby_models_loaded,
  type: :gauge,
  description: "Number of models loaded at boot"
}.freeze
PRESENTERS_LOADED =
{
  name: :lcp_ruby_presenters_loaded,
  type: :gauge,
  description: "Number of presenters loaded at boot"
}.freeze
PAGES_LOADED =
{
  name: :lcp_ruby_pages_loaded,
  type: :gauge,
  description: "Number of pages loaded at boot"
}.freeze
ALL =
[
  REQUEST_DURATION, REQUEST_TOTAL, ERROR_TOTAL,
  CACHE_OPERATIONS_TOTAL, PERMISSION_CHECKS_TOTAL,
  WORKFLOW_TRANSITIONS_TOTAL, BOOT_TIMESTAMP, MODELS_LOADED,
  PRESENTERS_LOADED, PAGES_LOADED
].freeze

Class Method Summary collapse

Class Method Details

.register_all!Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/lcp_ruby/metrics/metric_definitions.rb', line 83

def self.register_all!
  return unless PrometheusCheck.available?

  registry = ::Prometheus::Client.registry

  ALL.each do |definition|
    next if registry.exist?(definition[:name])

    labels = definition[:labels] || []
    case definition[:type]
    when :counter
      registry.counter(definition[:name], docstring: definition[:description], labels: labels)
    when :histogram
      buckets = LcpRuby.configuration.metrics_histogram_buckets
      registry.histogram(definition[:name], docstring: definition[:description], labels: labels, buckets: buckets)
    when :gauge
      registry.gauge(definition[:name], docstring: definition[:description], labels: labels)
    end
  end
end