ractogateway.telemetry.prometheus_exporter
PrometheusExporter — HTTP server exposing a /metrics endpoint.
Requires: pip install ractogateway[prometheus]
Example:
from ractogateway.telemetry import GatewayMetricsMiddleware, PrometheusExporter
metrics = GatewayMetricsMiddleware()
exporter = PrometheusExporter(port=8000)
exporter.start()
# Prometheus can now scrape http://localhost:8000/metrics
# ...
exporter.stop()
- class ractogateway.telemetry.prometheus_exporter.PrometheusExporter(port=8000, *, registry=None)[source]
Bases:
objectStart an HTTP server that exposes all registered Prometheus metrics.
The server listens on
http://0.0.0.0:<port>/metricsand responds with the standard Prometheus text exposition format. This is designed to be used alongsideGatewayMetricsMiddlewarebut works with any metrics registered in the global registry.- Parameters:
port (
int) – HTTP port to listen on. Defaults to8000.registry (
Any|None) – Customprometheus_client.CollectorRegistry. WhenNonethe globalREGISTRYis used.Example:: –
from ractogateway.telemetry import GatewayMetricsMiddleware, PrometheusExporter
metrics = GatewayMetricsMiddleware() exporter = PrometheusExporter(port=9090) exporter.start() # Prometheus can now scrape http://localhost:9090/metrics exporter.stop()
Requires (
pip install ractogateway[prometheus])
- start()[source]
Start the metrics HTTP server in a background daemon thread.
Calling
start()a second time on an already-running exporter is a no-op.- Return type:
- stop()[source]
Shut down the metrics HTTP server.
Safe to call even if the server was never started.
- Return type:
- property port: int
The configured HTTP port.
- property is_running: bool
Truewhen the HTTP server is active.
- generate_latest()[source]
Return current metrics in Prometheus text format.
No HTTP server required — useful for testing or embedding the metrics in a custom endpoint:
text = exporter.generate_latest() assert "process_resident_memory_bytes" in text
- Return type:
- Returns:
str – UTF-8 decoded Prometheus text exposition string.