Skip to main content

A Django app that exposes a bunch of PostgreSQL database metrics.

Project description

django-postgres-metrics

GitHub Build Status Codecov coverage Read the Docs Version License: BSD Python Versions: see setup.py Django Versions: see setup.py

A Django application that exposes a bunch of PostgreSQL database metrics.

Background

At PyCon Canada 2017 Craig Kerstiens gave a talk "Postgres at any scale". In his talk Craig pointed out a bunch of metrics one should look at to understand why a PostgreSQL database could be "slow" or not perform as expected.

This project adds a Django Admin view exposing these metrics to Django users with the is_superusers flag turned on.

Installation

Start by installing django-postgres-metrics from PyPI:

(env)$ python -m pip install django-postgres-metrics

You will also need to make sure to have psycopg2 installed which is already a requirement by Django for PostgreSQL support anyway.

Then you need to add postgres_metrics to your INSTALLED_APPS list. Due to the way django-postgres-metrics works, you need to include it _before* the admin app:

INSTALLED_APPS = [
    'postgres_metrics.apps.PostgresMetrics',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

You also need to make sure that the request context processor is included in the TEMPLATES setting. It is included by default for projects that were started on Django 1.8 or later:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'context_processors': [
                ...,
                'django.template.context_processors.request',
                ...,
            ],
        },
    },
]

Lastly, you need to add a URL path to your global urls.py before the admin URL patterns.

from django.urls import include, path

urlpatterns = [
    path('admin/postgres-metrics/', include('postgres_metrics.urls')),
    path('admin/', admin.site.urls),
]

This is what a metric could look like: Screenshot of the Detailed Index Usage metric, with help text, and a table with rows for each index

Security

If you found or if you think you found a security issue please get in touch via info+django-postgres-metrics *at* markusholtermann *dot* eu.

I'm working about this in my free time. I don't have time to monitor the email 24/7. But you should normally receive a response within a week. If I haven't got back to you within 2 weeks, please reach out again.

Contributing

The project black and isort for formatting its code. flake8 is used for linting. All these are combined into pre-commit to run before each commit and push. To set it up:

(env)$ python -m pip install '.[dev,test]'
(env)$ pre-commit install -t pre-commit -t pre-push --install-hooks

To run the unit tests:

(env)$ django-admin.py test -v 2 --settings=tests.settings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-postgres-metrics-0.13.0.tar.gz (113.6 kB view details)

Uploaded Source

Built Distribution

django_postgres_metrics-0.13.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file django-postgres-metrics-0.13.0.tar.gz.

File metadata

  • Download URL: django-postgres-metrics-0.13.0.tar.gz
  • Upload date:
  • Size: 113.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for django-postgres-metrics-0.13.0.tar.gz
Algorithm Hash digest
SHA256 debdf56a29c3b776abc8222ecbbb31fedd254aef2a6d8f59f3bfd7f81e8bcabd
MD5 6a3e57fa475c9db449fb70955421ebf4
BLAKE2b-256 6b77b1bfa8b597334d02fc80a7b4c059c467fffae3c14d68e9d63decd20ce2aa

See more details on using hashes here.

File details

Details for the file django_postgres_metrics-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: django_postgres_metrics-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for django_postgres_metrics-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2ebf21a59e3a10b7640f369645825a1429bb1a46672ee25865b53ded37a1b1b
MD5 ba64e38656906c8adb3710b65cdd819d
BLAKE2b-256 3cb30e42960c2709b9273926d0187ea64e0ed45b96d4eaa59e3660c3520023e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page