korfuri / django-prometheus

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

django_migrations_unapplied_total = 1 but no migrations are unapplied #405

Open discordianfish opened 1 year ago

discordianfish commented 1 year ago

Hi,

django_migrations_unapplied_total is 1 even after we applied the migration:

Running migrations: No migrations to apply.

discordianfish commented 1 year ago

Restarting the app helped, so maybe it only detects the unapplied migrations once and doesn't reset the value when you run the migrations?

discordianfish commented 1 year ago

I'd suggest turning

into a custom collector as documented here: https://github.com/prometheus/client_python#custom-collectors In collect it would execute the same as in ExportMigrationsForDatabase and return a GaugeMetricFamily directly. That would cause it to get the unapplied migrations on every scrape. I'm not entirely sure about the costs associated but this is what you'd do in general for such use cases. Alternatively maybe this could be implemented as a mixin but dunno if there is a way to hook that up to the django in a way similar like you do with the models..