Flask

Setup

Flask is a python module that can be enabled for Prometheus metrics using flask Exporter for Prometheus.

You can enable your flask code to emit default metrics using the following export code in the python module

from prometheus_flask_exporter import PrometheusMetrics

In case you want to enable any custom metrics you can follow the steps given in the Exporter

After the flask python module is enabled you can verify by looking at the following default metrics in Prometheus.

  • flask_http_request_duration_seconds

  • flask_http_request_total

Metrics

Metric

Key Performance Indicator(KPI)

Requests

flask_http_request_duration_seconds_count

Request Rate

rate(flask_http_request_duration_seconds_count[5m])

Errors

flask_http_request_duration_seconds_count

Error Ratio

rate(flask_http_request_duration_seconds_count{status=~"5.."}[5m])/ rate(flask_http_request_duration_seconds_count[5m])

Latency

flask_http_request_duration_seconds_bucket

flask_http_request_duration_seconds_count

Latency Average

rate(flask_http_request_duration_seconds_count[5m])/ rate(flask_http_request_duration_seconds_count[5m])

Latency P99

histogram_quantile (

0.99,

sum(rate(flask_http_request_duration_seconds_bucket[1m])) by (le)

)

Alerts

KPI

Alerts

Request Rate

RequestRateAnomaly

Error Rate

ErrorRatioBreach

ErrorBuildup based on a 99.9 SLO

Latency Average

Latency P99

LatencyAverageBreach

LatencyAverageAnomaly

LatencyP99ErrorBuildup

Dashboards

Service KPI Dashboard

This dashboard has the following KPIs that include resource and requests metrics:

  • Request Rate

  • Latency Average

  • Latency P99

  • Error Rate

  • CPU %

  • CPU Cores Used

  • CPU Throttle

  • Memory %

  • Memory Bytes

  • Disk Usage

  • Network Usage

You can include any custom dashboard from the community for example this which shows flask specific metrics directly as a custom dashboard for your service.

Last updated