Class: Conductor::Worker::Telemetry::MetricsServer
- Inherits:
-
Object
- Object
- Conductor::Worker::Telemetry::MetricsServer
- Defined in:
- lib/conductor/worker/telemetry/prometheus_backend.rb
Overview
MetricsServer - HTTP server for exposing Prometheus metrics Serves metrics at /metrics endpoint
Constant Summary collapse
- DEFAULT_PORT =
9090
Instance Attribute Summary collapse
-
#port ⇒ Integer
readonly
Server port.
Instance Method Summary collapse
-
#initialize(port: DEFAULT_PORT, registry: nil) ⇒ MetricsServer
constructor
A new instance of MetricsServer.
-
#start ⇒ Thread
Start the metrics server in a background thread.
-
#stop ⇒ Object
Stop the metrics server.
Constructor Details
#initialize(port: DEFAULT_PORT, registry: nil) ⇒ MetricsServer
Returns a new instance of MetricsServer.
179 180 181 182 183 184 185 186 187 |
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 179 def initialize(port: DEFAULT_PORT, registry: nil) require 'prometheus/client' require 'prometheus/client/formats/text' require 'webrick' @port = port @registry = registry || Prometheus::Client.registry @server = nil end |
Instance Attribute Details
#port ⇒ Integer (readonly)
Returns Server port.
220 221 222 |
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 220 def port @port end |
Instance Method Details
#start ⇒ Thread
Start the metrics server in a background thread
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 191 def start @server = WEBrick::HTTPServer.new( Port: @port, Logger: WEBrick::Log.new('/dev/null'), AccessLog: [] ) @server.mount_proc '/metrics' do |_req, res| res.content_type = 'text/plain; version=0.0.4' res.body = Prometheus::Client::Formats::Text.marshal(@registry) end @server.mount_proc '/health' do |_req, res| res.content_type = 'application/json' res.body = '{"status":"healthy"}' end @thread = Thread.new { @server.start } @thread.name = 'prometheus-metrics-server' @thread end |
#stop ⇒ Object
Stop the metrics server
214 215 216 217 |
# File 'lib/conductor/worker/telemetry/prometheus_backend.rb', line 214 def stop @server&.shutdown @thread&.join(5) end |