Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.97 KB

File metadata and controls

54 lines (42 loc) · 1.97 KB

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