Class: Emrb::Instruments::State

Inherits:
Object
  • Object
show all
Defined in:
lib/emrb/instruments/state.rb

Overview

Internal: State is responsible for interacting with the Prometheus client.

Constant Summary collapse

INSTRUMENTS =

Internal: All supported Prometheus metrics.

{
  c: Prometheus::Client::Counter,
  g: Prometheus::Client::Gauge,
  h: Prometheus::Client::Histogram,
  s: Prometheus::Client::Summary
}.freeze

Class Method Summary collapse

Class Method Details

.counter(identifier, docstring) ⇒ Object

Internal: creates, registers, and returns a new Prometheus::Client::Counter. Requires an instrument identifier and a docstring as mandatory arguments, with optional keyword arguments supported by the Prometheus Counter. Prom docs: github.com/prometheus/client_ruby?tab=readme-ov-file#counter



20
21
22
# File 'lib/emrb/instruments/state.rb', line 20

def counter(identifier, docstring, **)
  INSTRUMENTS[:c].new(identifier, docstring:, **).tap { reg.register _1 }
end

.gauge(identifier, docstring) ⇒ Object

Internal: creates, registers, and returns a new Prometheus::Client::Gauge. Requires an instrument identifier and a docstring as mandatory arguments, with optional keyword arguments supported by the Prometheus Gauge. Prom docs: github.com/prometheus/client_ruby?tab=readme-ov-file#gauge



28
29
30
# File 'lib/emrb/instruments/state.rb', line 28

def gauge(identifier, docstring, **)
  INSTRUMENTS[:g].new(identifier, docstring:, **).tap { reg.register _1 }
end

.histogram(identifier, docstring) ⇒ Object

Internal: creates, registers, and returns a new Prometheus::Client::Histogram. Requires an instrument identifier and a docstring as mandatory arguments, with optional keyword arguments supported by the Prometheus Histogram. Prom docs: github.com/prometheus/client_ruby?tab=readme-ov-file#histogram



36
37
38
# File 'lib/emrb/instruments/state.rb', line 36

def histogram(identifier, docstring, **)
  INSTRUMENTS[:h].new(identifier, docstring:, **).tap { reg.register _1 }
end

.push(job) ⇒ Object

Internal: pushes the current registry state to a Pushgateway. It receives an obligatory job identifier, and optionally all supported keyword arguments of a new push. Prom docs: github.com/prometheus/client_ruby?tab=readme-ov-file#pushgateway



52
# File 'lib/emrb/instruments/state.rb', line 52

def push(job, **) = Prometheus::Client::Push.new(job:, **).add(reg)

.regObject

Internal: returns the current client registry.



55
# File 'lib/emrb/instruments/state.rb', line 55

def reg = Prometheus::Client.registry

.summary(identifier, docstring) ⇒ Object

Internal: creates, registers, and returns a new Prometheus::Client::Summary. Requires an instrument identifier and a docstring as mandatory arguments, with optional keyword arguments supported by the Prometheus Summary. Prom docs: github.com/prometheus/client_ruby?tab=readme-ov-file#summary



44
45
46
# File 'lib/emrb/instruments/state.rb', line 44

def summary(identifier, docstring, **)
  INSTRUMENTS[:s].new(identifier, docstring:, **).tap { reg.register _1 }
end