samhaque / python-prometheus-grafana-chaos

Example project showcasing how to enable prometheus and grafana stack for Python while causing Chaos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python-Prometheus-Grafana-Chaos

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.

Mains Tools

  • 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

Technical Overview

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

How it Works

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:

    1. Change directory to grafana-configuration
      cd grafana-configuration
      
    2. Hit the grafana /api/datasources endpoint with our datasources.json payload to configure grafana to pick up our prometheus metrics
      curl --request POST http://localhost:3000/api/datasources --header "Content-Type: application/json" -d @datasources.json
      
  • Create Dashboard:

    1. Change directory to grafana-configuration
      cd grafana-configuration
      
    2. Hit the grafana /api/dashboards/db endpoint with our dashboard.json payload to configure grafana to pick up our prometheus metrics
      curl --request POST http://localhost:3000/api/dashboards/db --header "Content-Type: application/json" -d @dashboard.json
      

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.

Help and Resources

You can read more on:

Authors

About

Example project showcasing how to enable prometheus and grafana stack for Python while causing Chaos


Languages

Language:Python 79.7%Language:Dockerfile 11.2%Language:Shell 9.1%