1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
from django.apps import AppConfig
from django.conf import settings
import django_prometheus
from django_prometheus.exports import SetupPrometheusExportsFromConfig
from django_prometheus.migrations import ExportMigrations
class DjangoPrometheusConfig(AppConfig):
name = django_prometheus.__name__
verbose_name = "Django-Prometheus"
def ready(self):
"""Initializes the Prometheus exports if they are enabled in the config.
Note that this is called even for other management commands
than `runserver`. As such, it is possible to scrape the
metrics of a running `manage.py test` or of another command,
which shouldn't be done for real monitoring (since these jobs
are usually short-lived), but can be useful for debugging.
"""
SetupPrometheusExportsFromConfig()
if getattr(settings, "PROMETHEUS_EXPORT_MIGRATIONS", False):
ExportMigrations()
|