Skip to content

Prometheus Gunicorn multiple worker processes integration example with Flask

License

Notifications You must be signed in to change notification settings

jonashaag/prometheus-multiprocessing-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gunicorn multi-worker Prometheus example

FastAPI: See https://prometheus.github.io/client_python/exporting/http/fastapi-gunicorn/.

This example web application shows how you can use Prometheus to monitor Flask web applications that are deployed using multiple Gunicorn works. To be specific, it explains how you can emit, collect and expose Prometheus metrics from multiple Gunicorn worker processes.

The integration uses a special multi-processing feature in the Prometheus client, details of which you can find here: https://prometheus.github.io/client_python/multiprocess/

Setup

In a virtualenv, install Flask, Gunicorn and the Python Prometheus client:

pip install flask gunicorn prometheus-client

Deployment

Metrics emitted by each worker are stored in a shared directory that has to be specified upfront using the PROMETHEUS_MULTIPROC_DIR environment variable.

To deploy the example application with 4 Gunicorn worker processes:

rm -rf multiproc-tmp
mkdir multiproc-tmp
export PROMETHEUS_MULTIPROC_DIR=multiproc-tmp
gunicorn -c gunicorn_conf.py -w 4 yourapp:app

You are responsible for ensuring the temporary directory exists and is cleaned up before each deployment.

About

Prometheus Gunicorn multiple worker processes integration example with Flask

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages