prometheus / prometheus/client_python

Duplicated timeseries in CollectorRegistry with Multiprocess Gunicorn

Ouverte
#815 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
4.4k
Forks
876
Merge moyen
8 j 4 h
PR mergées (30 j)
1

Description

I know this is a subject that comes up somewhat frequently but for the love of me I can't figure out what I'm doing wrong.

  1. I have a service in Amazon ECS thats running a single task with multiple workers (actually the problem happens in my other service that just has one worker also).

  2. I've created the directory and set the PROMETHEUS_MULTIPROC_DIR in the Dockerfile:

RUN mkdir -p /tmp/prom-metrics
ENV PROMETHEUS_MULTIPROC_DIR /tmp/prom-metrics
  1. I'm using the sample code in the README to create the registry in the /metrics request and return it:
registry = CollectorRegistry()
if getenv('PROMETHEUS_MULTIPROC_DIR'):
  multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)
status = '200 OK'
response_headers = [
    ('Content-type', CONTENT_TYPE_LATEST),
    ('Content-Length', str(len(data))),
]
return Response(data, status, response_headers)
  1. I've created the gunicorn.conf.py file with the sample from the README and passed it into my gunicorn startup script via -c:
from prometheus_client import multiprocess

def child_exit(server, worker):
    multiprocess.mark_process_dead(worker.pid)

In my two services, gunicorn starts them as follows:

# app 1 with workers
gunicorn -c /app/utils/gunicorn.conf.py -b :5000 -t 3600 --keep-alive 60 --threads 8 --workers 3 app:app

# app 2 without workers
gunicorn -c /app/utils/gunicorn.conf.py -b :5000 -t 3600 --keep-alive 60 --threads 8 app:app

The service boots successfully and accepts some metrics which are definitely collected in multiprocess mode, seeing as the HELP line simply displays Multiprocess metric.

This works for a few calls but eventually I get the dreaded Duplicated timeseries in CollectorRegistry error and no additional metrics are populated.

What might I be doing wrong?

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’exemple de métriques multiprocess du README et par la configuration gunicorn.conf.py référencée, puis reproduisez l’échec en utilisant les paramètres du Dockerfile et les commandes Gunicorn indiqués. Le travail est terminé lorsque la cause de l’erreur de timeseries dupliquées est identifiée et que la configuration est documentée ou corrigée afin que /metrics continue de renvoyer des métriques.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
docker, prometheus, python
Domaine
observability
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.