🌐
Medium
medium.com › @letathenasleep › exposing-python-metrics-with-prometheus-c5c837c21e4d
Exposing Python Metrics with Prometheus | by Adso | Medium | Medium
July 6, 2023 - Once the containers are running, you can access the API at http://localhost:5000 and the Prometheus dashboard at http://localhost:9090. The /metrics endpoint of the API will expose the metrics that Prometheus can scrape.
🌐
Blog
asserts.ai › home › monitoring python using prometheus
Monitoring Python Using Prometheus - Asserts
June 20, 2023 - The path function is used to prevent ... for grouping. That's all there is to it, the standard Prometheus /metrics endpoint will be exposed along with any endpoints of the application....
Discussions

python - Expose package metrics to Prometheus with prometheus_client - Stack Overflow
I've had a look at https://github.com/prometheus/client_python, but I'm not too sure how how to call the metrics from sandbox1.py and sandbox2.py into the file that actually exposes the metrics to Prometheus. Do the metrics always have to be part of the same file? ... Prometheus server scrapes HTTP endpoints ... More on stackoverflow.com
🌐 stackoverflow.com
python , how to import prometheus endpoint metrics for processing by another system
It looks like the prometheus REST API is useful to discover targets, but not pull the metrics themselves. Rather you would use the scrapeURL to go directly to the endpoint and pull the metrics. Looking at the prometheus client python, there is an example at the bottom of the page. More on reddit.com
🌐 r/PrometheusMonitoring
1
0
September 12, 2020
FastAPI and Prometheus endpoint
You won't be able to start 2 servers/processes listening on the same port. First one to start, wins. The other will fail to bind as the port is already in use. What you could do though is start both on different ports, say 8080 and 8081 or something, then put nginx in front of it all and proxy through to which ever backend based on the requested path. As a bonus you can terminate TLS at the nginx level using a single cert etc etc too. More on reddit.com
🌐 r/FastAPI
5
1
December 16, 2022
Unable to get API data metrics into Prometheus
First went digg, then went reddit. RIP -- mass edited with https://redact.dev/ More on reddit.com
🌐 r/PrometheusMonitoring
10
0
December 18, 2019
🌐
CloudBees
cloudbees.com › blog › monitoring-your-synchronous-python-web-applications-using-prometheus
Monitoring Your Synchronous Python Web Applications Using Prometheus
June 5, 2026 - Instead of the application pushing metrics to the monitoring system, Prometheus scrapes the application via HTTP usually on the /metrics/ endpoint.
🌐
Better Stack
betterstack.com › community › guides › monitoring › prometheus-python-metrics
Python Monitoring with Prometheus (Beginner's Guide) | Better Stack Community
February 17, 2025 - This app exposes two endpoints: / returns a simple with "Hello world!" message, and /metrics endpoint that will eventually expose the instrumented metrics. This project also includes a compose.yaml file, which defines two services: ... services: ...
🌐
Prometheus
prometheus.io › docs › instrumenting › clientlibs
Client libraries | Prometheus
Choose a Prometheus client library that matches the language in which your application is written. This lets you define and expose internal metrics via an HTTP endpoint on your application’s instance: Go · Java or Scala · Node.js · Python · Ruby · Rust ·
🌐
SigNoz
signoz.io › guides › how to set up and secure prometheus metrics endpoints
How to Set Up and Secure Prometheus Metrics Endpoints | SigNoz
August 1, 2024 - Choose a Prometheus client library: ... Expose the metrics endpoint: Configure your application to serve metrics at the /metrics endpoint....
🌐
Better Stack
betterstack.com › community › questions › set-up-and-secure-prometheus-metrics-endpoints
How To Set Up And Secure Prometheus Metrics Endpoints | Better Stack Community
November 29, 2024 - Explore more · To expose metrics, integrate a Prometheus client library into your application. For example, in Python with Flask, you can install the prometheus-client library, define a /metrics endpoint, and increment counters for tracking events.
🌐
Last9
last9.io › blog › getting-started-with-prometheus-metrics-endpoints
Getting Started with Prometheus Metrics Endpoints | Last9
April 14, 2025 - Grasping how this endpoint works ... performance. A Prometheus metrics endpoint is an HTTP endpoint (usually /metrics) that exposes monitoring data in a format Prometheus can scrape....
Find elsewhere
🌐
Chariot Solutions
chariotsolutions.com › home › how to create a custom prometheus scrapeable endpoint
How to Create a Custom Prometheus Scrapeable Endpoint — Chariot Solutions
November 13, 2023 - Fetch metrics and create custom endpoints for a Prometheus ServiceMonitor to scrape using the prometheus_client library in Python.
🌐
OneUptime
oneuptime.com › home › blog › how to add custom metrics to python applications with prometheus
How to Add Custom Metrics to Python Applications with Prometheus
January 6, 2025 - from prometheus_client import Counter # Create a counter with labels for dimensional data # Labels allow filtering and grouping in Prometheus queries http_requests_total = Counter( 'http_requests_total', # Metric name (must be unique) 'Total HTTP requests', # Description shown in docs ['method', 'endpoint', 'status'] # Label names for dimensions ) # Increment the counter - use labels() to specify dimension values def handle_request(method, endpoint, status_code): http_requests_total.labels( method=method, # e.g., 'GET', 'POST' endpoint=endpoint, # e.g., '/api/users' status=str(status_code) # e.g., '200', '500' ).inc() # Increment by 1 # Usage examples - each combination creates a separate time series handle_request('GET', '/api/users', 200) # Successful GET handle_request('POST', '/api/orders', 201) # Successful POST handle_request('GET', '/api/users', 500) # Error case
🌐
PyPI
pypi.org › project › prometheus-api-client
prometheus-api-client · PyPI
A Python wrapper for the Prometheus http api and some tools for metrics processing.
      » pip install prometheus-api-client
    
Published: Apr 13, 2026
Version: 0.7.2
Top answer
1 of 1
7

Prometheus server scrapes HTTP endpoints that provide metrics. This differs from some other metric systems where the metrics are pushed to the metric system. Because Prometheus scrapes metric endpoints, you need to do two things:

  1. Expose the metrics from your client using an HTTP server|endpoint
  2. Configure the Prometheus server to target this metric server|endpoint

If you run the Three Step Demo example on the page that you reference, and then browse http://localhost:8000, you should see something like:

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 357.0
python_gc_objects_collected_total{generation="1"} 0.0
python_gc_objects_collected_total{generation="2"} 0.0
...
...
# HELP request_processing_seconds Time spent processing request
# TYPE request_processing_seconds summary
request_processing_seconds_count 4.0
request_processing_seconds_sum 2.0374009040533565
# HELP request_processing_seconds_created Time spent processing request
# TYPE request_processing_seconds_created gauge
request_processing_seconds_created 1.6004497426536365e+09

This is the page that your Prometheus server would be configured to scrape. You can see, e.g. python_gc_objects_collected_total counter is provided. Prometheus metrics are human readable which is useful.

If you combine, your sandbox1.py into this example:

from prometheus_client import start_http_server, Counter, Summary
import random
import time

# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds',
                       'Time spent processing request')


# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
    """A dummy function that takes some time."""
    time.sleep(t)


if __name__ == '__main__':
    my_counter1 = Counter('my_counter1', 'My counter')
    # Start up the server to expose the metrics.
    start_http_server(8000)
    # Generate some requests.
    while True:
        my_counter1.inc()
        process_request(random.random())

And run the code again, you should now see:

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 357.0
python_gc_objects_collected_total{generation="1"} 0.0
python_gc_objects_collected_total{generation="2"} 0.0
...
...
# HELP my_counter1_total My counter
# TYPE my_counter1_total counter
my_counter1_total 13.0
# HELP my_counter1_created My counter
# TYPE my_counter1_created gauge
my_counter1_created 1.6004498408280134e+09

NOTE At the bottom of the page is my_counter1_total and my_counter1_created which correspond to your my_counter1 = Counter("my_counter1","My counter")

If you point a Prometheus server at this target (localhost:8000), you should be able to e.g. graph the my_counter1_total counter and the my_counter1_created gauge.

Create a file called prometheus.yml:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  # Self
  - job_name: "prometheus-server"
    static_configs:
      - targets:
          - "localhost:9090"

  # Python example
  - job_name: "63957470"
    static_configs:
      - targets:
          - "localhost:8000"

And then run Prometheus:

docker run \
--interactive --tty \
--net=host \
--volume=${PWD}/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus@sha256:f3ada803723ccbc443ebea19f7ab24d3323def496e222134bf9ed54ae5b787bd

NOTE This assumes that prometheus.yml is in the working directory

The, you can browse Prometheus on http://localhost:9090

You can see your code configured as a target: http://localhost:9090/targets

And you can query|graph your metrics. Type e.g. my_counter1_ to see both and then my_counter1_total for the Counter:

🌐
Reddit
reddit.com › r/prometheusmonitoring › python , how to import prometheus endpoint metrics for processing by another system
r/PrometheusMonitoring on Reddit: python , how to import prometheus endpoint metrics for processing by another system
September 12, 2020 - It looks like the prometheus REST API is useful to discover targets, but not pull the metrics themselves. Rather you would use the scrapeURL to go directly to the endpoint and pull the metrics. Looking at the prometheus client python, there is an example at the bottom of the page.
🌐
DEV Community
dev.to › camptocamp-ops › implement-prometheus-metrics-in-a-flask-application-p18
Implement Prometheus Metrics in a Flask Application - DEV Community
April 1, 2021 - Sometimes, the cost of maintaining these kinds of variables is higher than computing the values on-the-fly when the metrics() function is called. With the default configuration, Prometheus queries the /metrics endpoint once every 30 seconds.
🌐
PyPI
pypi.org › project › prometheus-flask-exporter
prometheus-flask-exporter · PyPI
The group_by constructor argument controls what the default request duration metric is tracked by: endpoint (function) instead of URI path (the default). This parameter also accepts a function to extract the value from the request, or a name of a property of the request object. Examples: PrometheusMetrics(app, group_by='path') # the default PrometheusMetrics(app, group_by='endpoint') # by endpoint PrometheusMetrics(app, group_by='url_rule') # by URL rule def custom_rule(req): # the Flask request object """ The name of the function becomes the label name.
🌐
GitHub
github.com › valohai › prometheus-client-python
GitHub - valohai/prometheus-client-python: Prometheus instrumentation library for Python applications · GitHub
The official Python 2 and 3 client for Prometheus. ... from prometheus_client import start_http_server, Summary import random import time # Create a metric to track time spent and requests made.
Author: valohai
🌐
Netdata
learn.netdata.cloud › collecting metrics › collectors › applications › prometheus endpoint
Prometheus endpoint | Applications | Learn Netdata
July 8, 2026 - Curated collection, uncollectable-object, and collection-run metrics for each Python garbage-collector generation. Important: Debug mode is not supported for data collection jobs created via the UI using the Dyncfg feature. To troubleshoot issues with the prometheus collector, run the go.d.plugin ...
🌐
The Neural Base
theneuralbase.com › home › triton › beginner course › metrics endpoint (prometheus)
Metrics endpoint (Prometheus) | Triton Beginner Course | The Neural Base
# WRONG: Assuming metrics are not exposed and trying to add a custom logging layer # This wastes time reimplementing what Triton already provides services: triton: image: nvcr.io/nvidia/tritonserver:24.01-py3 # No metrics port exposed # No Prometheus configured # Later, you write custom Python code to parse Triton logs for latency # This is fragile and slow ... # RIGHT: Expose metrics port and configure Prometheus to scrape services: triton: image: nvcr.io/nvidia/tritonserver:24.01-py3 ports: - "8002:8002" # Metrics endpoint command: tritonserver --model-repository=/models prometheus: image: prom/prometheus:latest volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml # prometheus.yml contains: # scrape_configs: # - job_name: 'triton' # static_configs: # - targets: ['triton:8002']
🌐
Viktor Adam's blog
blog.viktoradam.net › 2020 › 05 › 11 › prometheus-flask-exporter
Monitoring Python Flask microservices with Prometheus · Viktor Adam's blog
May 11, 2020 - By adding an import and a line to initialize PrometheusMetrics you’ll get request duration metrics and request counters exposed on the /metrics endpoint of the Flask application it’s registered on, along with all the default metrics you get from the underlying Prometheus client library.