Module: Rubino::Metrics
- Defined in:
- lib/rubino/metrics.rb
Overview
In-process Prometheus-style metrics registry.
Counters and histograms only — no gauges (process state is queried lazily by the /v1/health operation). The registry is a process-wide singleton; tests can call Metrics.reset! between examples to start clean.
Metrics.counter(:http_requests_total, method: "GET", status: 200).increment
Metrics.histogram(:http_request_duration_seconds, path: "/v1/runs").observe(0.034)
Output is the Prometheus text exposition format (see Renderer), served by API::Operations::MetricsOperation.
Defined Under Namespace
Modules: Renderer Classes: Counter, Histogram, Proxy
Constant Summary collapse
- DEFAULT_BUCKETS =
Default histogram bucket boundaries (seconds). Tuned for sub-second HTTP request latencies — fine granularity below 100ms, coarser past 1s.
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10].freeze
Class Method Summary collapse
-
.counter(name, **labels) ⇒ Object
Fetch (or lazily create) the named Counter and bind ‘labels` for use via Proxy.
-
.describe(name, help) ⇒ Object
Set the HELP text for ‘name`; applied when the metric is first created.
-
.each ⇒ Object
Yield each registered metric (Counter or Histogram).
-
.histogram(name, **labels) ⇒ Object
Fetch (or lazily create) the named Histogram and bind ‘labels` for use via Proxy.
-
.render ⇒ Object
Serialize the full registry to Prometheus text exposition format.
-
.reset! ⇒ Object
Drop all registered metrics.
Class Method Details
.counter(name, **labels) ⇒ Object
Fetch (or lazily create) the named Counter and bind ‘labels` for use via Proxy.
78 79 80 81 |
# File 'lib/rubino/metrics.rb', line 78 def counter(name, **labels) registry[name] ||= Counter.new(name, descriptions.fetch(name, name.to_s)) Proxy.new(registry[name], labels) end |
.describe(name, help) ⇒ Object
Set the HELP text for ‘name`; applied when the metric is first created.
90 91 92 |
# File 'lib/rubino/metrics.rb', line 90 def describe(name, help) descriptions[name] = help end |
.each ⇒ Object
Yield each registered metric (Counter or Histogram).
95 |
# File 'lib/rubino/metrics.rb', line 95 def each(&) = registry.each_value(&) |
.histogram(name, **labels) ⇒ Object
Fetch (or lazily create) the named Histogram and bind ‘labels` for use via Proxy.
84 85 86 87 |
# File 'lib/rubino/metrics.rb', line 84 def histogram(name, **labels) registry[name] ||= Histogram.new(name, descriptions.fetch(name, name.to_s)) Proxy.new(registry[name], labels) end |
.render ⇒ Object
Serialize the full registry to Prometheus text exposition format.
103 104 105 |
# File 'lib/rubino/metrics.rb', line 103 def render Renderer.call(registry.values) end |
.reset! ⇒ Object
Drop all registered metrics. Intended for tests.
98 99 100 |
# File 'lib/rubino/metrics.rb', line 98 def reset! @registry = nil end |