Skip to main content

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 or psycopg 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

The same output but using the pgm_show_metric management command

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 test -v 2 --settings=tests.settings

Metadata

Release files for django-postgres-metrics 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-postgres-metrics 0.15.0
File Size Uploaded Provenance
django-postgres-metrics-0.15.0.tar.gz 116.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-postgres-metrics 0.15.0
File Interpreter ABI Platform
django_postgres_metrics-0.15.0-py3-none-any.whl Python 3 none any Details

Total release size: 136.2 kB

Release files / django-postgres-metrics-0.15.0.tar.gz

Download URL django-postgres-metrics-0.15.0.tar.gz
Size 116.7 kB
Tags Source
SHA-256 checksum
How to use checksums
98127ef55cf9d435b4dd0fdf1d160ea5b97690197d4d8e6148fc2cc2bb57ae12
BLAKE2b-256 checksum
How to use checksums
3ef6045c7c38069683cdaeb2358b931e6442300dd623f1edb6bb7e2003947d02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / django_postgres_metrics-0.15.0-py3-none-any.whl

Download URL django_postgres_metrics-0.15.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1710d44e910b230e3b7c7ce77304d68a40b1fa3711b18418387455b8e114d97a
BLAKE2b-256 checksum
How to use checksums
858b74a6185646f6982448433188f29b9c07e037128fe4882296e4a762f2c21d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for django-postgres-metrics 0.15.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page