Skip to main content

Self-hosted analytics dashboard and API monitoring for Django: discover your URLs and DRF endpoints, and see traffic, performance, error, and database metrics for each of them.

Project description

django-prometric

Status: Beta Python 3.9–3.14 Django 4.2–6.0 Documentation License: MIT

Self-hosted analytics dashboard and API monitoring for Django.

django-prometric is an open-source Django app that discovers the URLs and Django REST Framework endpoints in your project, then connects traffic, performance, audience, error, and database metrics to the routes that produced them—per-endpoint monitoring inside a protected, self-hosted Django dashboard.

Documentation · Quick start · Providers · Configuration · Security · Development

Beta: Test the dashboard in a non-critical environment before rolling it out broadly.

Why django-prometric?

Capability What it gives you
Route discovery Django and DRF endpoints without manual registration
Unified analytics Edge, application, and database metrics in one dashboard
Per-route insight Traffic and performance connected to the relevant URL pattern
Provider composition Cloudflare, Sentry, PostgreSQL, and custom providers in priority order
Historical comparison Snapshots and repeated runs compared over time
Private by default Django authentication, permissions, and superuser-only default access
No frontend toolchain Packaged templates, CSS, and JavaScript ready for collectstatic

Providers

Provider Contributes Install Setup
Cloudflare Traffic, audience, cache, bandwidth, bots, security, SEO, and network data django-prometric[cloudflare] API token + zone ID
ArvanCloud Edge traffic, cache, countries, status, and attack/security data django-prometric[arvancloud] API key + domain
Sentry Application performance, slow routes, issues, queries, and backend operations django-prometric[sentry] Auth token + organization
PostgreSQL Database health, tables, indexes, slow queries, and derived insights django-prometric[postgres] Existing Django PostgreSQL connection

Providers are evaluated in list order. The first configured provider capable of supplying a dashboard component is used for that component. Unconfigured providers stay visible with setup instructions instead of breaking the dashboard.

Compatibility

Supported versions
Python 3.9–3.14
Django 4.2, 5.0, 5.1, 5.2, 6.0

The only required runtime dependency is Django 4.2 or newer. DRF integration activates automatically when Django REST Framework is installed.

Quick start

1. Install

Install the core package with the extras for the providers you plan to use:

python -m pip install "django-prometric[full]"
Command What it installs
pip install django-prometric Core dashboard; Cloudflare and Sentry already work (standard library only)
pip install "django-prometric[postgres]" Core + the psycopg driver for the PostgreSQL provider
pip install "django-prometric[full]" Core + every provider dependency

[cloudflare] and [sentry] are currently empty extras — they exist so the per-provider install commands stay stable if those providers ever need a dependency of their own.

2. Register the application

INSTALLED_APPS = [
    # ...
    "django_prometric",
]

3. Mount the dashboard

from django.urls import include, path

urlpatterns = [
    # ...
    path("prometric/", include("django_prometric.urls")),
]

4. Apply migrations

python manage.py migrate

5. Open the dashboard

Sign in as a superuser and visit /prometric/. Providers without credentials will show their setup requirements on the Providers page.

For production deployments, include django-prometric in your normal static files workflow:

python manage.py collectstatic

Provider setup

Enable providers in the order you want them considered:

DJANGO_PROMETRIC = {
    "PROVIDERS": ["cloudflare", "sentry", "postgres"],
}

Cloudflare and Sentry are listed by default. PostgreSQL is opt-in.

Cloudflare

Create an API token with Analytics Read permission, then expose the token and zone ID to the Django process:

export CLOUDFLARE_API_TOKEN="..."
export CLOUDFLARE_ZONE_ID="..."

If one zone serves several applications, limit analytics to this project's hostnames:

DJANGO_PROMETRIC = {
    "PROVIDERS": ["cloudflare"],
    "CLOUDFLARE": {
        "HOSTS": ["example.com", "www.example.com"],
    },
}

Some route-level and performance metrics depend on the Cloudflare plan. The provider detects unavailable features and reports plan limits in the UI.

Read the Cloudflare provider guide for host scoping, the two analytics datasets, and plan limits.

ArvanCloud

For sites behind ArvanCloud CDN. Create an API key with report read access, then expose it and your domain:

export ARVANCLOUD_API_KEY="..."
export ARVANCLOUD_DOMAIN="example.com"

The provider is opt-in while it is validated across plans; add it to your list:

DJANGO_PROMETRIC = {
    "PROVIDERS": ["arvancloud"],
    "ARVANCLOUD": {
        "SUBDOMAIN": "blog",   # optional; "@" for the root domain
    },
}

This release reads the ArvanCloud Reports API (overview, traffic, countries, cache, status, and security) over the dashboard's presets up to 90 days and custom ranges, with time-window boundaries converted to real UTC. Route-level, HTTP-method, and performance cards are not included — a live probe confirmed ArvanCloud Metric Exporters return only a reset-on-fetch Top(10) snapshot (no history), so they cannot back those cards.

Read the ArvanCloud provider guide for scope limits, time-window handling, and permissions.

Sentry

Create an auth token with org:read and event:read scopes:

export SENTRY_API_TOKEN="..."
export SENTRY_ORG="your-organization-slug"
export SENTRY_PROJECT="your-project-slug"  # optional

When SENTRY_PROJECT is omitted, the first project returned by Sentry is used. The default performance lookback is 14 days; change it with DJANGO_PROMETRIC["SENTRY"]["MAX_DAYS"].

Read the Sentry provider guide for project pinning, self-hosted Sentry, and metric semantics.

PostgreSQL

Install the provider's driver, then point it at a database:

python -m pip install "django-prometric[postgres]"

If your Django project already talks to PostgreSQL, the driver is already installed and the extra adds nothing new. The provider reads the selected Django database connection and requires no external API or token:

DJANGO_PROMETRIC = {
    "PROVIDERS": ["postgres"],
    "POSTGRES": {
        "DB_ALIAS": "default",
    },
}

Database, table, and index metrics use standard PostgreSQL statistics views. Query-level metrics additionally require pg_stat_statements.

Read the PostgreSQL provider guide for extension setup, permissions, and metric semantics.

Custom providers

Any data source can feed the dashboard. Subclass AnalyticsProvider, declare the capabilities you can answer, and implement the matching get_* methods:

from django_prometric.providers import base
from django_prometric.providers.base import AnalyticsProvider, OverviewStats

class MyProvider(AnalyticsProvider):
    slug = "mysource"
    verbose_name = "My source"

    def capabilities(self):
        return {base.OVERVIEW}

    def get_overview(self, period):
        return OverviewStats(requests=...)

List it by dotted path, mixed freely with the built-in aliases:

DJANGO_PROMETRIC = {
    "PROVIDERS": ["cloudflare", "myproject.analytics.MyProvider"],
}

The full contract — capabilities, time windows, and the result dataclasses — lives in django_prometric.providers.base.

Configuration

All settings are optional and live under one DJANGO_PROMETRIC dictionary:

DJANGO_PROMETRIC = {
    "PROVIDERS": ["cloudflare", "sentry"],
    "ACCESS": "superuser",
    "STEALTH_404": False,
    "CACHE_ALIAS": "default",
    "CACHE_TTL": 300,
    "SITE_NAME": None,
}

Built-in provider aliases may be mixed with dotted paths to custom AnalyticsProvider subclasses.

Route filtering

Administrative routes are excluded by default. Additional routes can be selected with regular expressions matched against their display paths:

DJANGO_PROMETRIC = {
    "ROUTES": {
        "MODE": "exclude",  # all | include | exclude
        "EXCLUDE": [r"^/health/$", r"^/internal/"],
        "EXCLUDE_ADMIN": True,
    },
}

For application-specific rules, set ROUTES.FILTER to a dotted callable. It receives a display path and returns True when the route should be kept.

Security

The dashboard exposes operational information. Do not make it anonymously accessible.

Access is restricted to superusers by default:

DJANGO_PROMETRIC = {
    "ACCESS": "superuser",  # superuser | staff | permission | dotted callable
    "STEALTH_404": True,
}

Users granted django_prometric.view_dashboard can access the dashboard regardless of the baseline policy. Set ACCESS to permission to allow only explicitly granted users and groups.

A custom policy must accept the current user and return a boolean:

DJANGO_PROMETRIC = {
    "ACCESS": "myproject.permissions.can_view_metrics",
}

With STEALTH_404 enabled, unauthorized requests receive a 404 response instead of a login redirect or permission error.

Development

git clone https://github.com/mohsensalare/DjangoProMetric.git
cd DjangoProMetric
python -m pip install -e ".[dev]"

python -m pytest
ruff check .
ruff format --check .

These are the same checks CI runs on every push and pull request. The build and release process — versioning, tags, and Trusted Publishing to PyPI — is documented in RELEASING.md.

Links

License

django-prometric is released under the MIT License.

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_prometric-0.3.0.tar.gz (215.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_prometric-0.3.0-py3-none-any.whl (222.5 kB view details)

Uploaded Python 3

File details

Details for the file django_prometric-0.3.0.tar.gz.

File metadata

  • Download URL: django_prometric-0.3.0.tar.gz
  • Upload date:
  • Size: 215.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_prometric-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a6affb40bc091bad99f040b33afff30581822534fdc401b5ed50197d9c09da59
MD5 c558d070e49bf064e31edc3d4c611f54
BLAKE2b-256 552bb9d4c650986c8b8915264c08132332af83b2d8ed0ed28d2413525f35a430

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_prometric-0.3.0.tar.gz:

Publisher: release.yml on mohsensalare/DjangoProMetric

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_prometric-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_prometric-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 011eede2d0db4a1f405831bea6934a31c5084449455b4f8020b6f54bfecfdd9f
MD5 02b5b7f7bfab4f5ce77b0537d63367b6
BLAKE2b-256 445084c7102d2393ff8aec7c442285babf912a645afa3d2ec95c9003625736ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_prometric-0.3.0-py3-none-any.whl:

Publisher: release.yml on mohsensalare/DjangoProMetric

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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