Flask metrics with Prometheus

You can find the library to expose metrics from Python at https://github.com/prometheus/client_python and can install it using pip with this command:

pip install prometheus_client
Depending on your setup, you may need to use sudo pip install prometheus_client to install the client with pip.

For our flask example, you can download the full sample code from https://github.com/kubernetes-for-developers/kfd-flask from branch 0.5.0. The commands to get this updated sample are:

git clone https://github.com/kubernetes-for-developers/kfd-flask -b 0.5.0

If you look within exampleapp.py, you can see the code where we use two metrics, a histogram and a counter, and use the flask framework to add in callbacks at the beginning ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.