Prometheus is a powerful monitoring and alerting system that collects and stores time-series data. In this step-by-step guide, we will demonstrate how to expose metrics for a simple Python API app and monitor them using Prometheus. We will also instrument the app to track request metrics. To make it easier for you to try it out, we will provide all the necessary code blocks and a Docker Compose file. This is the way.
Prerequisites
Before getting started, ensure that you have the following tools installed on your system:
- Docker
- Docker Compose
Step 1: Set Up the Python API App
First, let’s create a Python API app using Flask. Create a new directory for your project and navigate to it. Then, create a file named app.py with the following code: