1. django app run with
2. celery worker run with
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?