korfuri / django-prometheus

Export Django monitoring metrics for Prometheus.io
Apache License 2.0
1.47k stars 245 forks source link

Incorrect number of CRUD operations in multiworker context #325

Open ramikhaldi opened 2 years ago

ramikhaldi commented 2 years ago

Hi,

After doing some experiments, I noticed, that the metric about the number of CRUD operations is only per process (This is also mentioned in the README):

This will export 3 metrics, django_model_inserts_total{model="dog"}, django_model_updates_total{model="dog"} and django_model_deletes_total{model="dog"}. Note that the exported metrics are counters of creations, modifications and deletions done in the current process. They are not gauges of the number of objects in the model.

Nevertheless it would be great if the metric index would be more fine-grained, so that the process and maybe also the thread dimension will be considered. Alternatively the sum of CRUD ops over all workers will be returned. Right now, you get a number from the catched worker like:

django_model_inserts_total{model="XYZ"} 14.0

The real django_model_inserts_total could be more than that (e.g 19).

From my point of view, the result should be:

Proposal 1:

django_model_inserts_total{model="XYZ/process/123/thread/21"} 14.0 django_model_inserts_total{model="XYZ/process/124/thread/21"} 5.0

Proposal 2:

django_model_inserts_total{model="XYZ"} 19.0 (Sum over all workers)

Thanks and KR, Rami

ramikhaldi commented 2 years ago

The env variable: PROMETHEUS_MULTIPROC_DIR seems to solve the issue. Maybe update the README ?