The main objective of this project is to create a simple Python service example that exports metrics to Prometheus which is a standalone open source project that monitors and alerts systems and Grafana.
- Docker Install
- Prometheus
- Grafana
- Windows Subsystem for Linux (WSL) if you are using windows Install Note: If on Windows also need to configure your docker to talk with your WSL distro Instructions
You will need Docker installed: https://docs.docker.com/get-docker/
To follow the next steps and build and run the image locally you just need to use the following command:
docker-compose build --no-cache
docker-compose up
At first, make some reqeust several times using the following link http://localhost:5000
, then you be able to see changes in the metrics http://localhost:5000/metrics
.
After that, you can navigate to grafana's Dashboard via the link http//localhost:3000
and upload the datasource and dashboard configuration using the JSO files. Or you can use Grafana's Dashboard API to create a new dashboard and datasource using the following requests:
-
Enable datasource:
- Change directory to
grafana-configuration
cd grafana-configuration
- Hit the grafana
/api/datasources
endpoint with ourdatasources.json
payload to configure grafana to pick up our prometheus metricscurl --request POST http://localhost:3000/api/datasources --header "Content-Type: application/json" -d @datasources.json
- Change directory to
-
Create Dashboard:
- Change directory to
grafana-configuration
cd grafana-configuration
- Hit the grafana
/api/dashboards/db
endpoint with ourdashboard.json
payload to configure grafana to pick up our prometheus metricscurl --request POST http://localhost:3000/api/dashboards/db --header "Content-Type: application/json" -d @dashboard.json
- Change directory to
For more information you can access the Grafana Dashboard API.
After all these actions, you should be able to access the Grafana Dashboard that display some graphs and metrics related to the Flask Web Application that was created.
You can read more on: