Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonashaag/prometheus-multiprocessing-example

Prometheus Gunicorn multiple worker processes integration example with Flask
https://github.com/jonashaag/prometheus-multiprocessing-example

Last synced: 10 days ago
JSON representation

Prometheus Gunicorn multiple worker processes integration example with Flask

Awesome Lists containing this project

README

        

# 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.