django-prometric 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_prometric-0.2.0/.gitignore +43 -0
- django_prometric-0.2.0/CHANGELOG.md +43 -0
- django_prometric-0.2.0/LICENSE +21 -0
- django_prometric-0.2.0/PKG-INFO +368 -0
- django_prometric-0.2.0/README.md +315 -0
- django_prometric-0.2.0/RELEASING.md +215 -0
- django_prometric-0.2.0/django_prometric/__init__.py +3 -0
- django_prometric-0.2.0/django_prometric/admin.py +41 -0
- django_prometric-0.2.0/django_prometric/apps.py +8 -0
- django_prometric-0.2.0/django_prometric/components.py +490 -0
- django_prometric-0.2.0/django_prometric/conf.py +134 -0
- django_prometric-0.2.0/django_prometric/locale/fa/LC_MESSAGES/django.mo +0 -0
- django_prometric-0.2.0/django_prometric/locale/fa/LC_MESSAGES/django.po +1577 -0
- django_prometric-0.2.0/django_prometric/migrations/0001_initial.py +62 -0
- django_prometric-0.2.0/django_prometric/migrations/0002_snapshot_windows.py +27 -0
- django_prometric-0.2.0/django_prometric/migrations/0003_preferences.py +40 -0
- django_prometric-0.2.0/django_prometric/migrations/__init__.py +0 -0
- django_prometric-0.2.0/django_prometric/models.py +138 -0
- django_prometric-0.2.0/django_prometric/permissions.py +62 -0
- django_prometric-0.2.0/django_prometric/providers/__init__.py +65 -0
- django_prometric-0.2.0/django_prometric/providers/base.py +252 -0
- django_prometric-0.2.0/django_prometric/providers/capabilities.py +39 -0
- django_prometric-0.2.0/django_prometric/providers/cloudflare.py +947 -0
- django_prometric-0.2.0/django_prometric/providers/periods.py +94 -0
- django_prometric-0.2.0/django_prometric/providers/postgres.py +573 -0
- django_prometric-0.2.0/django_prometric/providers/report.py +57 -0
- django_prometric-0.2.0/django_prometric/providers/sentry.py +478 -0
- django_prometric-0.2.0/django_prometric/providers/types.py +251 -0
- django_prometric-0.2.0/django_prometric/routes.py +474 -0
- django_prometric-0.2.0/django_prometric/snapshots.py +263 -0
- django_prometric-0.2.0/django_prometric/static/django_prometric/prometric.css +1084 -0
- django_prometric-0.2.0/django_prometric/static/django_prometric/prometric.js +582 -0
- django_prometric-0.2.0/django_prometric/static/django_prometric/vendor/chart.umd.js +14 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/_comparison.html +45 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/_load_error.html +5 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/_period.html +20 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/base.html +86 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/_bars.html +18 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/_cumulative.html +9 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/_stat_delta.html +7 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/audience.html +21 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/backend.html +19 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/bots.html +23 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/cache.html +5 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/card.html +9 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/country.html +22 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/database.html +57 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/error.html +5 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/indexes.html +59 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/insights.html +24 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/issues.html +36 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/loading.html +12 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/network.html +17 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/overview.html +62 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/performance.html +28 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/queries.html +30 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/security.html +54 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/seo.html +33 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/slowest.html +41 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/status.html +5 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/tables.html +34 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/top_routes.html +38 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/components/traffic.html +11 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/dashboard.html +61 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/provider_detail.html +45 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/providers.html +41 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/route/performance.html +40 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/route/traffic.html +91 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/route_detail.html +46 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/routes.html +100 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/snapshot_compare.html +68 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/snapshot_detail.html +144 -0
- django_prometric-0.2.0/django_prometric/templates/django_prometric/snapshots.html +110 -0
- django_prometric-0.2.0/django_prometric/templatetags/__init__.py +0 -0
- django_prometric-0.2.0/django_prometric/templatetags/prometric_extras.py +89 -0
- django_prometric-0.2.0/django_prometric/urls.py +28 -0
- django_prometric-0.2.0/django_prometric/views.py +452 -0
- django_prometric-0.2.0/docs/postgres.md +142 -0
- django_prometric-0.2.0/pyproject.toml +112 -0
- django_prometric-0.2.0/tests/__init__.py +0 -0
- django_prometric-0.2.0/tests/settings.py +31 -0
- django_prometric-0.2.0/tests/test_postgres_provider.py +227 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Byte-compiled / optimized
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
.eggs/
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# IDE
|
|
18
|
+
.idea/
|
|
19
|
+
.vscode/
|
|
20
|
+
|
|
21
|
+
# Testing / coverage
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
coverage.xml
|
|
25
|
+
htmlcov/
|
|
26
|
+
.tox/
|
|
27
|
+
|
|
28
|
+
# Django
|
|
29
|
+
*.sqlite3
|
|
30
|
+
*.log
|
|
31
|
+
example/staticfiles/
|
|
32
|
+
example/media/
|
|
33
|
+
|
|
34
|
+
# Environment
|
|
35
|
+
.env
|
|
36
|
+
.env.*
|
|
37
|
+
|
|
38
|
+
# OS
|
|
39
|
+
.DS_Store
|
|
40
|
+
|
|
41
|
+
# Internal notes and planning — not part of the published package
|
|
42
|
+
/provides api guaid/
|
|
43
|
+
/POSTGRES_PROVIDER_PLAN.md
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to django-prometric will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The project follows [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.2.0] - 2026-07-06
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Per-provider install extras: `pip install "django-prometric[postgres]"`
|
|
14
|
+
brings the `psycopg` driver, `[cloudflare]` and `[sentry]` are stable no-op
|
|
15
|
+
extras (both providers run on the standard library), and `[full]` installs
|
|
16
|
+
everything.
|
|
17
|
+
- A provider listed in `DJANGO_PROMETRIC["PROVIDERS"]` that fails to import
|
|
18
|
+
now raises `ImproperlyConfigured` with the matching `pip install` hint
|
|
19
|
+
instead of a bare `ImportError`.
|
|
20
|
+
- Continuous-integration and release automation: a test matrix across the
|
|
21
|
+
supported Python and Django versions, and a tag-gated release workflow that
|
|
22
|
+
publishes to PyPI through Trusted Publishing (OIDC).
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- `django_prometric.providers.base` was split into focused modules —
|
|
27
|
+
`capabilities` (the capability vocabulary), `periods` (time windows),
|
|
28
|
+
`types` (result dataclasses), and `report` (the stored snapshot schema).
|
|
29
|
+
Every name is still importable from `providers.base`, so existing imports
|
|
30
|
+
and custom providers keep working unchanged.
|
|
31
|
+
|
|
32
|
+
## [0.1.0] - 2026-07-05
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- Initial beta release.
|
|
37
|
+
- Route-aware analytics dashboard for Django and Django REST Framework.
|
|
38
|
+
- Pluggable Cloudflare, Sentry, and PostgreSQL analytics providers.
|
|
39
|
+
- Traffic, audience, performance, database, and snapshot views.
|
|
40
|
+
|
|
41
|
+
[Unreleased]: https://github.com/mohsensalare/DjangoProMetric/compare/v0.2.0...HEAD
|
|
42
|
+
[0.2.0]: https://github.com/mohsensalare/DjangoProMetric/compare/v0.1.0...v0.2.0
|
|
43
|
+
[0.1.0]: https://github.com/mohsensalare/DjangoProMetric/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohsen Salare
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-prometric
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Route-aware analytics dashboard for Django: discover your URLs and DRF APIs, and see traffic, performance, and audience metrics for each of them.
|
|
5
|
+
Project-URL: Homepage, https://github.com/mohsensalare/DjangoProMetric
|
|
6
|
+
Project-URL: Documentation, https://github.com/mohsensalare/DjangoProMetric/tree/main/docs
|
|
7
|
+
Project-URL: Changelog, https://github.com/mohsensalare/DjangoProMetric/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Source, https://github.com/mohsensalare/DjangoProMetric
|
|
9
|
+
Project-URL: Issues, https://github.com/mohsensalare/DjangoProMetric/issues
|
|
10
|
+
Project-URL: Author, https://mohsensalare.ir
|
|
11
|
+
Author-email: Mohsen Salare <mohsensalare@gmail.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: analytics,cloudflare,dashboard,django,drf,metrics,monitoring,rest-framework
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Environment :: Web Environment
|
|
17
|
+
Classifier: Framework :: Django
|
|
18
|
+
Classifier: Framework :: Django :: 4.2
|
|
19
|
+
Classifier: Framework :: Django :: 5.0
|
|
20
|
+
Classifier: Framework :: Django :: 5.1
|
|
21
|
+
Classifier: Framework :: Django :: 5.2
|
|
22
|
+
Classifier: Framework :: Django :: 6.0
|
|
23
|
+
Classifier: Intended Audience :: Developers
|
|
24
|
+
Classifier: Operating System :: OS Independent
|
|
25
|
+
Classifier: Programming Language :: Python
|
|
26
|
+
Classifier: Programming Language :: Python :: 3
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
33
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
|
|
34
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
35
|
+
Classifier: Topic :: System :: Monitoring
|
|
36
|
+
Requires-Python: >=3.9
|
|
37
|
+
Requires-Dist: django>=4.2
|
|
38
|
+
Provides-Extra: cloudflare
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: build; extra == 'dev'
|
|
41
|
+
Requires-Dist: djangorestframework; extra == 'dev'
|
|
42
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == 'dev'
|
|
43
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
44
|
+
Requires-Dist: pytest-django; extra == 'dev'
|
|
45
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
46
|
+
Requires-Dist: twine; extra == 'dev'
|
|
47
|
+
Provides-Extra: full
|
|
48
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == 'full'
|
|
49
|
+
Provides-Extra: postgres
|
|
50
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
|
|
51
|
+
Provides-Extra: sentry
|
|
52
|
+
Description-Content-Type: text/markdown
|
|
53
|
+
|
|
54
|
+
# django-prometric
|
|
55
|
+
|
|
56
|
+
[](https://github.com/mohsensalare/DjangoProMetric/releases)
|
|
57
|
+
[](https://www.python.org/)
|
|
58
|
+
[](https://www.djangoproject.com/)
|
|
59
|
+
[](https://github.com/mohsensalare/DjangoProMetric/blob/main/LICENSE)
|
|
60
|
+
|
|
61
|
+
**Route-aware analytics and operational insight for Django.**
|
|
62
|
+
|
|
63
|
+
django-prometric discovers the URLs and Django REST Framework endpoints in
|
|
64
|
+
your project, then connects traffic, performance, audience, error, and database
|
|
65
|
+
metrics to the routes that produced them—all inside a protected Django
|
|
66
|
+
dashboard.
|
|
67
|
+
|
|
68
|
+
[Quick start](#quick-start) · [Providers](#providers) ·
|
|
69
|
+
[Configuration](#configuration) · [Security](#security) ·
|
|
70
|
+
[Development](#development)
|
|
71
|
+
|
|
72
|
+
> **Beta:** Test the dashboard in a non-critical environment before rolling it
|
|
73
|
+
> out broadly.
|
|
74
|
+
|
|
75
|
+
## Why django-prometric?
|
|
76
|
+
|
|
77
|
+
| Capability | What it gives you |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| Route discovery | Django and DRF endpoints without manual registration |
|
|
80
|
+
| Unified analytics | Edge, application, and database metrics in one dashboard |
|
|
81
|
+
| Per-route insight | Traffic and performance connected to the relevant URL pattern |
|
|
82
|
+
| Provider composition | Cloudflare, Sentry, PostgreSQL, and custom providers in priority order |
|
|
83
|
+
| Historical comparison | Snapshots and repeated runs compared over time |
|
|
84
|
+
| Private by default | Django authentication, permissions, and superuser-only default access |
|
|
85
|
+
| No frontend toolchain | Packaged templates, CSS, and JavaScript ready for `collectstatic` |
|
|
86
|
+
|
|
87
|
+
## Providers
|
|
88
|
+
|
|
89
|
+
| Provider | Contributes | Install | Setup |
|
|
90
|
+
| --- | --- | --- | --- |
|
|
91
|
+
| **Cloudflare** | Traffic, audience, cache, bandwidth, bots, security, SEO, and network data | `django-prometric[cloudflare]` | API token + zone ID |
|
|
92
|
+
| **Sentry** | Application performance, slow routes, issues, queries, and backend operations | `django-prometric[sentry]` | Auth token + organization |
|
|
93
|
+
| **PostgreSQL** | Database health, tables, indexes, slow queries, and derived insights | `django-prometric[postgres]` | Existing Django PostgreSQL connection |
|
|
94
|
+
|
|
95
|
+
Providers are evaluated in list order. The first configured provider capable
|
|
96
|
+
of supplying a dashboard component is used for that component. Unconfigured
|
|
97
|
+
providers stay visible with setup instructions instead of breaking the
|
|
98
|
+
dashboard.
|
|
99
|
+
|
|
100
|
+
## Compatibility
|
|
101
|
+
|
|
102
|
+
| | Supported versions |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| Python | 3.9–3.14 |
|
|
105
|
+
| Django | 4.2, 5.0, 5.1, 5.2, 6.0 |
|
|
106
|
+
|
|
107
|
+
The only required runtime dependency is Django 4.2 or newer. DRF integration
|
|
108
|
+
activates automatically when Django REST Framework is installed.
|
|
109
|
+
|
|
110
|
+
## Quick start
|
|
111
|
+
|
|
112
|
+
### 1. Install
|
|
113
|
+
|
|
114
|
+
Install the core package with the extras for the providers you plan to use:
|
|
115
|
+
|
|
116
|
+
```console
|
|
117
|
+
python -m pip install "django-prometric[full]"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
| Command | What it installs |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| `pip install django-prometric` | Core dashboard; Cloudflare and Sentry already work (standard library only) |
|
|
123
|
+
| `pip install "django-prometric[postgres]"` | Core + the `psycopg` driver for the PostgreSQL provider |
|
|
124
|
+
| `pip install "django-prometric[full]"` | Core + every provider dependency |
|
|
125
|
+
|
|
126
|
+
`[cloudflare]` and `[sentry]` are currently empty extras — they exist so the
|
|
127
|
+
per-provider install commands stay stable if those providers ever need a
|
|
128
|
+
dependency of their own.
|
|
129
|
+
|
|
130
|
+
### 2. Register the application
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
INSTALLED_APPS = [
|
|
134
|
+
# ...
|
|
135
|
+
"django_prometric",
|
|
136
|
+
]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 3. Mount the dashboard
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from django.urls import include, path
|
|
143
|
+
|
|
144
|
+
urlpatterns = [
|
|
145
|
+
# ...
|
|
146
|
+
path("prometric/", include("django_prometric.urls")),
|
|
147
|
+
]
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 4. Apply migrations
|
|
151
|
+
|
|
152
|
+
```console
|
|
153
|
+
python manage.py migrate
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 5. Open the dashboard
|
|
157
|
+
|
|
158
|
+
Sign in as a superuser and visit `/prometric/`. Providers without credentials
|
|
159
|
+
will show their setup requirements on the Providers page.
|
|
160
|
+
|
|
161
|
+
For production deployments, include django-prometric in your normal static
|
|
162
|
+
files workflow:
|
|
163
|
+
|
|
164
|
+
```console
|
|
165
|
+
python manage.py collectstatic
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Provider setup
|
|
169
|
+
|
|
170
|
+
Enable providers in the order you want them considered:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
DJANGO_PROMETRIC = {
|
|
174
|
+
"PROVIDERS": ["cloudflare", "sentry", "postgres"],
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Cloudflare and Sentry are listed by default. PostgreSQL is opt-in.
|
|
179
|
+
|
|
180
|
+
### Cloudflare
|
|
181
|
+
|
|
182
|
+
Create an API token with **Analytics Read** permission, then expose the token
|
|
183
|
+
and zone ID to the Django process:
|
|
184
|
+
|
|
185
|
+
```console
|
|
186
|
+
export CLOUDFLARE_API_TOKEN="..."
|
|
187
|
+
export CLOUDFLARE_ZONE_ID="..."
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
If one zone serves several applications, limit analytics to this project's
|
|
191
|
+
hostnames:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
DJANGO_PROMETRIC = {
|
|
195
|
+
"PROVIDERS": ["cloudflare"],
|
|
196
|
+
"CLOUDFLARE": {
|
|
197
|
+
"HOSTS": ["example.com", "www.example.com"],
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Some route-level and performance metrics depend on the Cloudflare plan. The
|
|
203
|
+
provider detects unavailable features and reports plan limits in the UI.
|
|
204
|
+
|
|
205
|
+
### Sentry
|
|
206
|
+
|
|
207
|
+
Create an auth token with `org:read` and `event:read` scopes:
|
|
208
|
+
|
|
209
|
+
```console
|
|
210
|
+
export SENTRY_API_TOKEN="..."
|
|
211
|
+
export SENTRY_ORG="your-organization-slug"
|
|
212
|
+
export SENTRY_PROJECT="your-project-slug" # optional
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
When `SENTRY_PROJECT` is omitted, the first project returned by Sentry is used.
|
|
216
|
+
The default performance lookback is 14 days; change it with
|
|
217
|
+
`DJANGO_PROMETRIC["SENTRY"]["MAX_DAYS"]`.
|
|
218
|
+
|
|
219
|
+
### PostgreSQL
|
|
220
|
+
|
|
221
|
+
Install the provider's driver, then point it at a database:
|
|
222
|
+
|
|
223
|
+
```console
|
|
224
|
+
python -m pip install "django-prometric[postgres]"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
If your Django project already talks to PostgreSQL, the driver is already
|
|
228
|
+
installed and the extra adds nothing new. The provider reads the selected
|
|
229
|
+
Django database connection and requires no external API or token:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
DJANGO_PROMETRIC = {
|
|
233
|
+
"PROVIDERS": ["postgres"],
|
|
234
|
+
"POSTGRES": {
|
|
235
|
+
"DB_ALIAS": "default",
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Database, table, and index metrics use standard PostgreSQL statistics views.
|
|
241
|
+
Query-level metrics additionally require `pg_stat_statements`.
|
|
242
|
+
|
|
243
|
+
Read the [PostgreSQL provider guide](https://github.com/mohsensalare/DjangoProMetric/blob/main/docs/postgres.md)
|
|
244
|
+
for extension setup, permissions, and metric semantics.
|
|
245
|
+
|
|
246
|
+
### Custom providers
|
|
247
|
+
|
|
248
|
+
Any data source can feed the dashboard. Subclass `AnalyticsProvider`, declare
|
|
249
|
+
the capabilities you can answer, and implement the matching `get_*` methods:
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from django_prometric.providers import base
|
|
253
|
+
from django_prometric.providers.base import AnalyticsProvider, OverviewStats
|
|
254
|
+
|
|
255
|
+
class MyProvider(AnalyticsProvider):
|
|
256
|
+
slug = "mysource"
|
|
257
|
+
verbose_name = "My source"
|
|
258
|
+
|
|
259
|
+
def capabilities(self):
|
|
260
|
+
return {base.OVERVIEW}
|
|
261
|
+
|
|
262
|
+
def get_overview(self, period):
|
|
263
|
+
return OverviewStats(requests=...)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
List it by dotted path, mixed freely with the built-in aliases:
|
|
267
|
+
|
|
268
|
+
```python
|
|
269
|
+
DJANGO_PROMETRIC = {
|
|
270
|
+
"PROVIDERS": ["cloudflare", "myproject.analytics.MyProvider"],
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The full contract — capabilities, time windows, and the result dataclasses —
|
|
275
|
+
lives in `django_prometric.providers.base`.
|
|
276
|
+
|
|
277
|
+
## Configuration
|
|
278
|
+
|
|
279
|
+
All settings are optional and live under one `DJANGO_PROMETRIC` dictionary:
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
DJANGO_PROMETRIC = {
|
|
283
|
+
"PROVIDERS": ["cloudflare", "sentry"],
|
|
284
|
+
"ACCESS": "superuser",
|
|
285
|
+
"STEALTH_404": False,
|
|
286
|
+
"CACHE_ALIAS": "default",
|
|
287
|
+
"CACHE_TTL": 300,
|
|
288
|
+
"SITE_NAME": None,
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Built-in provider aliases may be mixed with dotted paths to custom
|
|
293
|
+
`AnalyticsProvider` subclasses.
|
|
294
|
+
|
|
295
|
+
### Route filtering
|
|
296
|
+
|
|
297
|
+
Administrative routes are excluded by default. Additional routes can be
|
|
298
|
+
selected with regular expressions matched against their display paths:
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
DJANGO_PROMETRIC = {
|
|
302
|
+
"ROUTES": {
|
|
303
|
+
"MODE": "exclude", # all | include | exclude
|
|
304
|
+
"EXCLUDE": [r"^/health/$", r"^/internal/"],
|
|
305
|
+
"EXCLUDE_ADMIN": True,
|
|
306
|
+
},
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
For application-specific rules, set `ROUTES.FILTER` to a dotted callable. It
|
|
311
|
+
receives a display path and returns `True` when the route should be kept.
|
|
312
|
+
|
|
313
|
+
## Security
|
|
314
|
+
|
|
315
|
+
> The dashboard exposes operational information. Do not make it anonymously
|
|
316
|
+
> accessible.
|
|
317
|
+
|
|
318
|
+
Access is restricted to superusers by default:
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
DJANGO_PROMETRIC = {
|
|
322
|
+
"ACCESS": "superuser", # superuser | staff | permission | dotted callable
|
|
323
|
+
"STEALTH_404": True,
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Users granted `django_prometric.view_dashboard` can access the dashboard
|
|
328
|
+
regardless of the baseline policy. Set `ACCESS` to `permission` to allow only
|
|
329
|
+
explicitly granted users and groups.
|
|
330
|
+
|
|
331
|
+
A custom policy must accept the current user and return a boolean:
|
|
332
|
+
|
|
333
|
+
```python
|
|
334
|
+
DJANGO_PROMETRIC = {
|
|
335
|
+
"ACCESS": "myproject.permissions.can_view_metrics",
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
With `STEALTH_404` enabled, unauthorized requests receive a 404 response
|
|
340
|
+
instead of a login redirect or permission error.
|
|
341
|
+
|
|
342
|
+
## Development
|
|
343
|
+
|
|
344
|
+
```console
|
|
345
|
+
git clone https://github.com/mohsensalare/DjangoProMetric.git
|
|
346
|
+
cd DjangoProMetric
|
|
347
|
+
python -m pip install -e ".[dev]"
|
|
348
|
+
|
|
349
|
+
python -m pytest
|
|
350
|
+
ruff check .
|
|
351
|
+
ruff format --check .
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
These are the same checks CI runs on every push and pull request. The build
|
|
355
|
+
and release process — versioning, tags, and Trusted Publishing to PyPI — is
|
|
356
|
+
documented in [RELEASING.md](https://github.com/mohsensalare/DjangoProMetric/blob/main/RELEASING.md).
|
|
357
|
+
|
|
358
|
+
## Links
|
|
359
|
+
|
|
360
|
+
- [Documentation](https://github.com/mohsensalare/DjangoProMetric/tree/main/docs)
|
|
361
|
+
- [Development and release process](https://github.com/mohsensalare/DjangoProMetric/blob/main/RELEASING.md)
|
|
362
|
+
- [Changelog](https://github.com/mohsensalare/DjangoProMetric/blob/main/CHANGELOG.md)
|
|
363
|
+
- [Issue tracker](https://github.com/mohsensalare/DjangoProMetric/issues)
|
|
364
|
+
- [Source code](https://github.com/mohsensalare/DjangoProMetric)
|
|
365
|
+
|
|
366
|
+
## License
|
|
367
|
+
|
|
368
|
+
django-prometric is released under the [MIT License](https://github.com/mohsensalare/DjangoProMetric/blob/main/LICENSE).
|