prometheus_client library.
See the overview for the general approach.
1. Add the dependency
requirements.txt:
2. Register custom metrics and expose /metrics
start_http_server spins up a dedicated HTTP server on the given port that serves /metrics. The default registry
already includes process metrics (CPU, memory, open FDs) and Python runtime metrics (GC stats, threads).
3. Declare the metrics endpoint in ops.json
4. Visualize with a community dashboard
Python doesn’t have a single canonical community dashboard like JVM or Node.js, but the metrics exposed by the default registry (process_* and python_*) are well-supported by generic process dashboards.
For a Python-app-specific dashboard with panels for requests/sec, latency percentiles, error rates, app uptime, and
interpreter version, see pilosus/prometheus-client-python-app-grafana-dashboard
on GitHub — it’s a JSON dashboard you can import directly.
You can also browse grafana.com/grafana/dashboards for more
Python-related community dashboards.
To import: in Grafana, go to Dashboards → New → Import, enter the dashboard ID (or upload the JSON), and select
your LocalOps Prometheus data source.