Class: A2A::Monitoring::PrometheusBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/a2a/monitoring.rb

Overview

Prometheus metrics backend

Instance Method Summary collapse

Constructor Details

#initializePrometheusBackend

Returns a new instance of PrometheusBackend.



323
324
325
326
327
# File 'lib/a2a/monitoring.rb', line 323

def initialize
  @registry = Prometheus::Client.registry
  @counters = {}
  @histograms = {}
end

Instance Method Details

#increment_counter(name, **labels) ⇒ Object (private)



346
347
348
349
350
351
352
353
# File 'lib/a2a/monitoring.rb', line 346

def increment_counter(name, **labels)
  counter = @counters[name] ||= @registry.counter(
    name.to_sym,
    docstring: "A2A counter: #{name}",
    labels: labels.keys
  )
  counter.increment(labels: labels)
end

#record(name, value, **labels) ⇒ Object

Record metric in Prometheus

Parameters:

  • name (String)

    Metric name

  • value (Numeric)

    Metric value

  • **labels (Hash)

    Metric labels



333
334
335
336
337
338
339
340
341
342
# File 'lib/a2a/monitoring.rb', line 333

def record(name, value, **labels)
  if name.end_with?("_total")
    increment_counter(name, **labels)
  elsif name.end_with?("_duration_seconds")
    record_histogram(name, value, **labels)
  else
    # Generic gauge
    record_gauge(name, value, **labels)
  end
end

#record_gauge(name, value, **labels) ⇒ Object (private)



364
365
366
367
# File 'lib/a2a/monitoring.rb', line 364

def record_gauge(name, value, **labels)
  # Prometheus gauge implementation would go here
  # For now, just log it
end

#record_histogram(name, value, **labels) ⇒ Object (private)



355
356
357
358
359
360
361
362
# File 'lib/a2a/monitoring.rb', line 355

def record_histogram(name, value, **labels)
  histogram = @histograms[name] ||= @registry.histogram(
    name.to_sym,
    docstring: "A2A histogram: #{name}",
    labels: labels.keys
  )
  histogram.observe(value, labels: labels)
end