remotivelabs.topology.metrics
class
Metric(builtins.str, enum.Enum):
Names of every metric the library can emit.
FRAMES_RECEIVED =
<Metric.FRAMES_RECEIVED: 'frames.received'>
HANDLER_DURATION =
<Metric.HANDLER_DURATION: 'handler.duration'>
class
Metrics(typing.Protocol):
Sink for metric observations. Backends implement this protocol.
def
timed( self, metric: Metric, tags: Mapping[str, str]) -> contextlib.AbstractContextManager[None]:
Context manager that records elapsed seconds on exit.
class
NoOpMetrics:
Default Metrics implementation — records nothing.
def
timed( self, metric: Metric, tags: Mapping[str, str]) -> contextlib.AbstractContextManager[None]:
Tags =
typing.Mapping[str, str]
Return the process-wide Metrics sink.
Without METRICS_PORT set, returns a no-op sink with zero overhead.
With METRICS_PORT set, lazily configures an OpenTelemetry MeterProvider
with a Prometheus exporter and serves /metrics on that port.
Raises:
- ImportError: If
METRICS_PORTis set but the metrics extras are not installed (opentelemetry/prometheus_client). - ValueError: If
METRICS_PORTis not a valid port number.
Note:
By default, enabling metrics unregisters
prometheus_client's defaultpython_*/process_*/GC collectors so scrapes contain only application metrics. SetMETRICS_KEEP_PROMETHEUS_DEFAULTS=1to keep them.