Metrics Developer Guide
This guide explains how to create and use custom metrics in Dynamo components using the Dynamo metrics API.
Metrics Exposure
All metrics created via the Dynamo metrics API are automatically exposed on the /metrics HTTP endpoint in Prometheus Exposition Format text when the following environment variable is set:
DYN_SYSTEM_PORT=<port>- Port for the metrics endpoint (set to positive value to enable, default:-1disabled)
Example:
Prometheus Exposition Format text metrics will be available at: http://localhost:8081/metrics
Metric Name Constants
The prometheus_names.rs module provides centralized metric name constants and sanitization functions to ensure consistency across all Dynamo components.
Metrics API in Rust
The metrics API is accessible through the .metrics() method on runtime, namespace, component, and endpoint objects. See Runtime Hierarchy for details on the hierarchical structure.
Available Methods
.metrics().create_counter(): Create a counter metric.metrics().create_gauge(): Create a gauge metric.metrics().create_histogram(): Create a histogram metric.metrics().create_countervec(): Create a counter with labels.metrics().create_gaugevec(): Create a gauge with labels.metrics().create_histogramvec(): Create a histogram with labels
Creating Metrics
Using Metrics
Vector Metrics with Labels
Advanced Features
Custom histogram buckets:
Constant labels:
Metrics API in Python
Python components can create and manage Prometheus metrics using the same metrics API through Python bindings.
Available Methods
endpoint.metrics.create_counter()/create_intcounter(): Create a counter metricendpoint.metrics.create_gauge()/create_intgauge(): Create a gauge metricendpoint.metrics.create_histogram(): Create a histogram metricendpoint.metrics.create_countervec()/create_intcountervec(): Create a counter with labelsendpoint.metrics.create_gaugevec()/create_intgaugevec(): Create a gauge with labelsendpoint.metrics.create_histogramvec(): Create a histogram with labels
All metrics are imported from dynamo.prometheus_metrics.
Creating Metrics
Using Metrics
Vector Metrics with Labels
Advanced Features
Constant labels:
Metric introspection:
Update patterns:
Background thread updates:
Callback-based updates (called before each /metrics scrape):
Examples
Example scripts: lib/bindings/python/examples/metrics/