Right way to implement prometheus_client.multiprocess.MultiProcessCollector

664 views
Skip to first unread message

Albert Aleksandrov

unread,
May 11, 2020, 5:39:52 AM5/11/20
to Prometheus Users
Hi all!

I have:

1. django app run with
python manage.py runserver

2. celery worker run with 
celery -A project worker -l info

3. celery beat run with
celery -A project beat -l info

They will be deployed in their own pods in kubernetes.

/metrics endpoint is exposed in Django app but metrics are being gathered in Celery tasks. 
And because these two apps and run in two different process (pods) they have two different registries.
That's why from Django I can't get metrics from registry in Celery process.

If there is any way to handle this? It seems that prometheus_client.multiprocess.MultiProcessCollector can help.
I tried this but it didn't work:

settings.py

registry
= CollectorRegistry()
multiprocess
.MultiProcessCollector(registry, path='/home/aleksandrovalbert/Work/blackbox_exporter/exporter/multiproc-tmp')


views.py

from project.settings import registry

def export(request):
    metrics_page
= prometheus_client.generate_latest(registry)
   
return HttpResponse(metrics_page, content_type=prometheus_client.CONTENT_TYPE_LATEST)

tasks.py

registry
= CollectorRegistry()
multiprocess
.MultiProcessCollector(registry, path='/home/aleksandrovalbert/Work/blackbox_exporter/exporter/multiproc-tmp')


class TestBeatPeriodicTask(PeriodicTask):
    run_every
= timedelta(minutes=1)

    metric
= Gauge(
       name
='test_beat',
       documentation
='Работоспособность процесса обработки загрузки.',
       registry
=registry
   
)

   
def run(self):
        metric
.set(888)
Or this can be handled with pushgateway only?

utkarsh yadav

unread,
Aug 2, 2020, 12:01:04 PM8/2/20
to Prometheus Users
Hey, I am facing the same issue. Were you able to find a fix to this problem yet?
Reply all
Reply to author
Forward
0 new messages