Class: Attio::Observability::Metrics::Prometheus
- Inherits:
-
Object
- Object
- Attio::Observability::Metrics::Prometheus
- Defined in:
- lib/attio/observability.rb
Overview
Prometheus metrics
Instance Method Summary collapse
- #gauge(metric, value, tags: {}) ⇒ Object
- #histogram(metric, value, tags: {}) ⇒ Object
- #increment(metric, tags: {}) ⇒ Object
-
#initialize ⇒ Prometheus
constructor
A new instance of Prometheus.
Constructor Details
#initialize ⇒ Prometheus
Returns a new instance of Prometheus.
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
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: .keys ) gauge.set(value, labels: ) end |
#histogram(metric, value, tags: {}) ⇒ Object
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: .keys ) histogram.observe(value, labels: ) end |
#increment(metric, tags: {}) ⇒ Object
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: .keys ) counter.increment(labels: ) end |