The code looks true, However,the query in your response command is wrong . the true formate is :
response =requests.get(PROMETHEUS + '/api/v1/query', params={'query': 'container_cpu_user_seconds_total'})
you can change "container_cpu_user_seconds_total" to any query that you want to read. .. good luck
Answer from MOBT on Stack OverflowMedium
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.
Top answer 1 of 3
9
The code looks true, However,the query in your response command is wrong . the true formate is :
response =requests.get(PROMETHEUS + '/api/v1/query', params={'query': 'container_cpu_user_seconds_total'})
you can change "container_cpu_user_seconds_total" to any query that you want to read. .. good luck
2 of 3
4
Performing a GET request at <prom-server-ip>:9090/metrics returns the Prometheus metrics (not in JSON format) of the Prometheus server itself.
Since you're trying to perform query, you need to use the HTTP API endpoints like /api/v1/query or /api/v1/query_range instead of using /metrics.
$ curl 'http://localhost:9090/api/v1/query?query=up&time=2015-07-01T20:10:51.781Z'
{
"status" : "success",
"data" : {
"resultType" : "vector",
"result" : [
{
"metric" : {
"__name__" : "up",
"job" : "prometheus",
"instance" : "localhost:9090"
},
"value": [ 1435781451.781, "1" ]
},
{
"metric" : {
"__name__" : "up",
"job" : "node",
"instance" : "localhost:9100"
},
"value" : [ 1435781451.781, "0" ]
}
]
}
}
For more detailed information visit Prometheus official docs.
python - Expose package metrics to Prometheus with prometheus_client - Stack Overflow
Expose the metrics from your client using an HTTP server|endpoint ยท 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_g... More on stackoverflow.com
python , how to import prometheus endpoint metrics for processing by another system
Hopefully someone has already done this as I can't much in the way of examples or information. I just want to validate I am on the right track andโฆ More on reddit.com
Get data from influxdb to my Prometheus
Influxdb is generally used as storage solution for Prometheus. Prometheus can save it's data in Influxdb and is probably the better option than saving it in Prometheus itself / on disk. Is there a specific reason why you'd want it in both? More on reddit.com
Avoid reading zero values after a restart
There's no way to make Prometheus wait. Even if you could, if 0 is a valid value as you say then how would Prometheus know if a 0 reading was a "real" one or not? You should ideally handle this in your system being scraped, either by having it set the gauge on startup or by having it retrieve the current value in real-time whenever it is scraped. If for whatever reason neither of those is possible then you should avoid using 0 as the default value if it can also be a "real" value. Use NaN, -1, or something else that's more explicitly invalid, then set your rules up accordingly. More on reddit.com
12:35
Add custom metrics to FastAPI Server with prometheus_client | Python ...
34:47
Monitoring Python applications using Prometheus, Rafaล Kondziela ...
55:19
Monitoring Couchbase Using Python, Prometheus, and Grafana - YouTube
11:47
Introduction to Python monitoring with Prometheus - YouTube
47:59
Webinar: Collecting Docker metrics with Python and Prometheus - ...
ยป pip install prometheus-api-client
Published: Apr 13, 2026
Version: 0.7.2
Readthedocs
prometheus-api-client-python.readthedocs.io โบ en โบ latest โบ source โบ prometheus_api_client.html
prometheus_api_client package โ Prometheus Client API Python 0.0.1 documentation
(RequestException) Raises an exception in case of a connection error (PrometheusApiClientException) Raises in case of non 200 response status code ยท get_metric_aggregation(query: str, operations: list, start_time: datetime = None, end_time: datetime = None, step: str = '15', params: dict = None)[source]๏ ยท Get aggregations on metric values received from PromQL query.
Linux Hint
linuxhint.com โบ monitor-python-applications-prometheus
Monitoring Python Applications using Prometheus โ Linux Hint
To access the Prometheus metrics, visit the URL http://192.168.20.131:8000/metrics from your favorite web browser. Now, you have to add your Python app to Prometheus.
Sam Malekpour
s4m.ca โบ blog โบ decoding-observability-extracting-and-processing-prometheus-metrics-with-python
Decoding Observability: Extracting and Processing Prometheus Metrics with Python - Sam Malekpour
October 9, 2025 - Get metrics data from Prometheus API prometheus_data = query_prometheus_range( PROMETHEUS_QUERY, start_api, end_api, step ) # 2.
DBI Services
dbi-services.com โบ accueil โบ instrument your python application with prometheus (part1)
Instrument your python application with Prometheus (Part1)
July 10, 2023 - Then, in our code, we will define a variable called REQUESTS to initialize the Counter object by providing the metric name (http_request_total) and its description (Total number of requests). REQUESTS = Counter('http_request_total', 'Total number of requests') ... from flask import Flask, jsonify, request, render_template, redirect, url_for from prometheus_client import Counter REQUESTS = Counter('http_request_total', 'Total number of requests') app = Flask(__name__) (...)
Blog
asserts.ai โบ home โบ monitoring python using prometheus
Monitoring Python Using Prometheus - Asserts
June 20, 2023 - Prometheus is the ideal way to capture and store these metrics along with additional Python runtime metrics. To collect metrics for each endpoint and the Python runtime requires just a few simple modifications. from prometheus_flask_exporter import PrometheusMetrics def path(req): return '/' + req.path[1:].split('/')[0] app = Flask('my-app') metrics = PrometheusMetrics(app, group_by=path)
Pluralsight
pluralsight.com โบ cloud-guru โบ labs โบ aws โบ using-python-to-extract-prometheus-metrics
Using Python to Extract Prometheus Metrics
April 5, 2019 - The program will use PromQL examples to pull CPU and memory metrics and output them in a Comma Separated Value (CSV) file that may then be used for a Machine Learning program. This lab only covers the extract step and the Machine Learning part ...
Robust Perception
robustperception.io โบ productive-prometheus-python-parsing
Productive Prometheus Python Parsing โ Robust Perception | Prometheus Monitoring Experts
May 8, 2017 - First install the python client and requests, if you don't already have them: $ pip install prometheus_client requests ยท Then we can fetch the data we need, and print it: from prometheus_client.parser import text_string_to_metric_families import requests metrics = requests.get("http://dem...
PyPI
pypi.org โบ project โบ prometheus-client โบ 0.14.1
prometheus-client ยท PyPI
The official Python 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.
Prometheus
prometheus.io โบ docs โบ instrumenting โบ clientlibs
Client libraries | Prometheus
When Prometheus scrapes your instance's HTTP endpoint, the client library sends the current state of all tracked metrics to the server.

