
- It provides metric types (counters, gauges, histograms, summaries) and APIs to record values from your code.
- It exposes those metrics in the Prometheus exposition format via an HTTP endpoint (commonly
GET /metrics) so Prometheus can scrape them.

Focus on what metrics you capture and how you expose them, not the specifics of the language. The concepts (counters, gauges, histograms/summaries, and the
/metrics endpoint) apply across languages and frameworks.Key Prometheus metric types
Quick Python instrumentation example
Below is a compact example showing common patterns when instrumenting a Python web API with theprometheus_client library:
- Define metrics (counter, gauge, histogram)
- Increment/observe metrics in your request handlers
- Expose metrics via an HTTP endpoint (e.g.,
GET /metrics) so Prometheus can scrape them
- In web frameworks (Flask, FastAPI, Django), you typically attach middleware or decorators that update metrics around each request.
- For production, use an appropriate host/port and avoid exposing
/metricsto the public internet; use network policies or authentication as needed.
Best practices for application instrumentation
- Name metrics clearly and consistently: use lowercase, underscores, and include units where applicable (e.g.,
_seconds,_bytes). - Use labels sparingly to avoid high cardinality (many unique label combinations). Labels are great for dimensions like
methodorstatus_codebut not for unbounded values (e.g., user IDs). - Prefer histograms for latency distributions and calculating percentiles in Prometheus queries. Use summaries when you need client-side quantiles.
- Expose
/metricson a dedicated port or path, and secure access if it includes sensitive information. - Document what each metric means and how it should be used in dashboards and alerts.
Official client libraries (examples)
Links and references
- Prometheus: Instrumenting Applications
- prometheus_client (Python) GitHub repository
- Prometheus documentation: Exposition formats
- Prometheus best practices for naming metrics