Skip to content

Using Prometheus to collect metrics from multiple flask accplication replicas

License

Notifications You must be signed in to change notification settings

nie3e/python_api_with_metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collecting and presenting metrics from multiple application replicas

Using Prometheus to collect metrics from multiple flask accplication replicasand present them in Grafana.

Introduction

This is a "cheat sheet" for metrics collection and presentation. Based on what I've learnt from book "Learn Docker in a Month of Lunches" - especially chapter 9. See more: https://github.com/sixeyed/diamol/tree/master/ch09/exercises

Prerequisities

  • python3.10
  • docker
  • docker compose

app

Flask application with two endpoints and prometheus client library for providing metrics.

prometheus

We need only configuration file. Note we are using dns names tasks.api. api stands for application service name (see docker-compose.yml).

tasks:

"To resolve the virtual IP addresses of all service replicas running in my Docker swarm I have to lookup the tasks. domain name (see Docker overlay network documentation)"

See more: https://www.innoq.com/en/blog/scraping-docker-swarm-service-instances-with-prometheus/

grafana

Configuration files and sample dashboards attached in json and yaml files.

How to run

Create service stack

  1. Build docker images listed in docker-compose.yml:
docker compose build
  1. Run docker stack:
docker stack deploy -c .\docker-compose.yml my_api

Test is out!

docs/prometheus_targets.png

  • Go to prometheus graphs http://127.0.0.1:9090/graph
    • for /test endpoint metric name is test_page_total
    • for /endpoint metric name is main_page_total

docs/prometheus_metrics.png

About

Using Prometheus to collect metrics from multiple flask accplication replicas

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published