Class: Attio::Observability::Metrics::Prometheus

Inherits:
Object
  • Object
show all
Defined in:
lib/attio/observability.rb

Overview

Prometheus metrics

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initializePrometheus

Returns a new instance of Prometheus.

Since:

  • 1.0.0



274
275
276
277
278
279
280
281
282
# File 'lib/attio/observability.rb', line 274

def initialize
  require "prometheus/client"
  @registry = ::Prometheus::Client.registry
  @counters = {}
  @gauges = {}
  @histograms = {}
rescue LoadError
  raise "Please add 'prometheus-client' to your Gemfile"
end

Instance Method Details

#gauge(metric, value, tags: {}) ⇒ Object

Since:

  • 1.0.0



293
294
295
296
297
298
299
300
# File 'lib/attio/observability.rb', line 293

def gauge(metric, value, tags: {})
  gauge = @gauges[metric] ||= @registry.gauge(
    metric.to_sym,
    docstring: "Gauge for #{metric}",
    labels: tags.keys
  )
  gauge.set(value, labels: tags)
end

#histogram(metric, value, tags: {}) ⇒ Object

Since:

  • 1.0.0



302
303
304
305
306
307
308
309
# File 'lib/attio/observability.rb', line 302

def histogram(metric, value, tags: {})
  histogram = @histograms[metric] ||= @registry.histogram(
    metric.to_sym,
    docstring: "Histogram for #{metric}",
    labels: tags.keys
  )
  histogram.observe(value, labels: tags)
end

#increment(metric, tags: {}) ⇒ Object

Since:

  • 1.0.0



284
285
286
287
288
289
290
291
# File 'lib/attio/observability.rb', line 284

def increment(metric, tags: {})
  counter = @counters[metric] ||= @registry.counter(
    metric.to_sym,
    docstring: "Counter for #{metric}",
    labels: tags.keys
  )
  counter.increment(labels: tags)
end