Interview Prep/Python for DevOps/Concurrency, async, tests, services & containers

Prometheus shows counters from your gunicorn app jumping up and down between scrapes.

AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer

Likely causes → Multiple gunicorn workers each keep their own metrics; each scrape hits a different worker.

Diagnose → Compare /metrics output from repeated curls; values differ per request.

Fix → Enable prometheus_client multiprocess mode: set PROMETHEUS_MULTIPROC_DIR (empty, writable) before startup, serve metrics through MultiProcessCollector, call multiprocess.mark_process_dead(worker.pid) in gunicorn's child_exit hook.

Prevent → Use the multiprocess setup in your service template whenever workers > 1.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency, async, tests, services & containers