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: object

Start an HTTP server that exposes all registered Prometheus metrics.

The server listens on http://0.0.0.0:<port>/metrics and responds with the standard Prometheus text exposition format. This is designed to be used alongside GatewayMetricsMiddleware but works with any metrics registered in the global registry.

Parameters:
  • port (int) – HTTP port to listen on. Defaults to 8000.

  • registry (Any | None) – Custom prometheus_client.CollectorRegistry. When None the global REGISTRY is 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:

None

stop()[source]

Shut down the metrics HTTP server.

Safe to call even if the server was never started.

Return type:

None

property port: int

The configured HTTP port.

property is_running: bool

True when 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:

str

Returns:

str – UTF-8 decoded Prometheus text exposition string.