korfuri / django-prometheus

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

Unable to monitor a database | django_prometheus.db.backends is not an available backend #414

Closed JosueGauthier closed 6 months ago

JosueGauthier commented 1 year ago

Hello,

I try to monitor a Django app (Python 3.10, Postgresql and Django 4.0.4) with your package, however when I try to do :


DATABASES = {
    'default': {
        'ENGINE': 'django_prometheus.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
}

I get the error :

  File "/home/.local/lib/python3.10/site-packages/django/db/utils.py", line 126, in load_backend
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django_prometheus.db.backends.postgresql_psycopg2' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'

I see that indeed in python3.10/site-packages/django/db/utils.py, backend_name must be named django.db.backends

if backend_name not in ["django.db.backends.%s" % b for b in builtin_backends]:
            backend_reprs = map(repr, sorted(builtin_backends))
            raise ImproperlyConfigured(
                "%r isn't an available database backend or couldn't be "
                "imported. Check the above exception. To use one of the "
                "built-in backends, use 'django.db.backends.XXX', where XXX "
                "is one of:\n"
                "    %s" % (backend_name, ", ".join(backend_reprs))
            ) from e_user

Is there a fix ?

Thanks

eraserhead0705 commented 9 months ago

Worked for me Django 4.2.7.

@JosueGauthier django_prometheus.db.backends.postgresql is the correct engine and it looks like in the error message you are using django_prometheus.db.backends.postgresql_psycopg2?

dmwyatt commented 6 months ago

I think this can be closed since @JosueGauthier has an incorrect backend configured as @eraserhead0705 mentions.