Skip to main content
Prometheus is commonly used to monitor infrastructure components — Linux or Windows servers, Docker containers, the Docker Engine, and similar systems. To get visibility into the behaviour of the software running on that infrastructure, you instrument the application itself and expose metrics that Prometheus can scrape.
A diagram titled "Instrumentation" showing the Prometheus flame icon at the top with dashed arrows to three groups of server stacks. Each server group includes a Python logo, indicating instrumented Python applications being monitored.
A Prometheus client library makes it straightforward to add instrumentation to your application so Prometheus can collect application-level metrics. Client libraries typically perform two responsibilities:
  • Record metrics in the Prometheus exposition format using metric primitives such as Counter, Gauge, Histogram, and Summary.
  • Expose those metrics at an HTTP endpoint (commonly /metrics) so Prometheus can scrape them.
Prometheus maintains official client libraries for Go, Java, Python, and Ruby. Many community-maintained libraries exist for other languages (for example, Rust and Node.js). If needed, you can also implement a minimal custom client to support an unsupported language or to reduce dependencies.
If you’re not familiar with Python, focus on what metrics are being added and what they measure. The instrumentation concepts — metric types, labels, and the /metrics endpoint — apply across languages and frameworks.

Prometheus metric primitives

Understanding the main metric types helps you choose the right primitive for each signal you want to record.

Common client libraries

Example: instrumenting a Python API

Below is a minimal example showing how to instrument a Python Flask API using the official prometheus_client library. It demonstrates:
  • Defining a Counter and Histogram
  • Incrementing the counter and observing latency
  • Exposing metrics at /metrics for Prometheus to scrape
Install the library:
Python instrumentation example:
Prometheus can then scrape http://<host>:5000/metrics to collect these application-level metrics.
Avoid exposing sensitive information via metrics and be mindful of cardinality when using labels (high-cardinality labels can cause high memory use in Prometheus). Prefer a limited set of stable label values.

Next steps and references

  • Instrument critical endpoints and business transactions first (requests, errors, latency, queue depth).
  • Keep label cardinality low and stable.
  • Combine application metrics with infrastructure metrics for full-stack observability.
Links and references:

Watch Video