django-nocturne 0.1.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_nocturne-0.1.0/CHANGELOG.md +30 -0
- django_nocturne-0.1.0/LICENSE +21 -0
- django_nocturne-0.1.0/MANIFEST.in +9 -0
- django_nocturne-0.1.0/PKG-INFO +314 -0
- django_nocturne-0.1.0/README.md +257 -0
- django_nocturne-0.1.0/django_nocturne.egg-info/PKG-INFO +314 -0
- django_nocturne-0.1.0/django_nocturne.egg-info/SOURCES.txt +42 -0
- django_nocturne-0.1.0/django_nocturne.egg-info/dependency_links.txt +1 -0
- django_nocturne-0.1.0/django_nocturne.egg-info/requires.txt +29 -0
- django_nocturne-0.1.0/django_nocturne.egg-info/top_level.txt +1 -0
- django_nocturne-0.1.0/nocturne/__init__.py +1 -0
- django_nocturne-0.1.0/nocturne/admin.py +113 -0
- django_nocturne-0.1.0/nocturne/ai_diagnosis.py +192 -0
- django_nocturne-0.1.0/nocturne/apps.py +39 -0
- django_nocturne-0.1.0/nocturne/detection.py +338 -0
- django_nocturne-0.1.0/nocturne/management/__init__.py +0 -0
- django_nocturne-0.1.0/nocturne/management/commands/__init__.py +0 -0
- django_nocturne-0.1.0/nocturne/management/commands/create_nocturne_user.py +55 -0
- django_nocturne-0.1.0/nocturne/management/commands/nocturne_config.py +75 -0
- django_nocturne-0.1.0/nocturne/management/commands/snapshot_health.py +69 -0
- django_nocturne-0.1.0/nocturne/management/commands/test_ai_diagnosis.py +128 -0
- django_nocturne-0.1.0/nocturne/middleware.py +89 -0
- django_nocturne-0.1.0/nocturne/migrations/0001_initial.py +127 -0
- django_nocturne-0.1.0/nocturne/migrations/0002_alter_logentry_options.py +22 -0
- django_nocturne-0.1.0/nocturne/migrations/0003_logentry_ai_analysis.py +18 -0
- django_nocturne-0.1.0/nocturne/migrations/0004_logentry_ai_analysed_at_logentry_exception_message_and_more.py +33 -0
- django_nocturne-0.1.0/nocturne/migrations/0005_healthsnapshot_webhookevent.py +96 -0
- django_nocturne-0.1.0/nocturne/migrations/0006_alter_logentry_options_and_more.py +27 -0
- django_nocturne-0.1.0/nocturne/migrations/__init__.py +0 -0
- django_nocturne-0.1.0/nocturne/models.py +124 -0
- django_nocturne-0.1.0/nocturne/permissions.py +28 -0
- django_nocturne-0.1.0/nocturne/serializers.py +76 -0
- django_nocturne-0.1.0/nocturne/static/nocturne/dashboard.js +1115 -0
- django_nocturne-0.1.0/nocturne/templates/nocturne/403.html +65 -0
- django_nocturne-0.1.0/nocturne/templates/nocturne/admin_dashboard.html +603 -0
- django_nocturne-0.1.0/nocturne/templates/nocturne/dashboard.html +381 -0
- django_nocturne-0.1.0/nocturne/urls.py +37 -0
- django_nocturne-0.1.0/nocturne/views.py +592 -0
- django_nocturne-0.1.0/pyproject.toml +90 -0
- django_nocturne-0.1.0/setup.cfg +4 -0
- django_nocturne-0.1.0/tests/test_api.py +121 -0
- django_nocturne-0.1.0/tests/test_detection.py +77 -0
- django_nocturne-0.1.0/tests/test_middleware.py +69 -0
- django_nocturne-0.1.0/tests/test_models.py +67 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to django-nocturne will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] — 2026-06-19
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `NocturneMiddleware` — zero-code request/response logging with exception capture and stacktrace recording
|
|
14
|
+
- Statistical anomaly detection via Z-score across 5-minute error-rate buckets (MEDIUM / HIGH / CRITICAL severity tiers)
|
|
15
|
+
- Multi-signal health scoring (0–100) combining error rate, response time, and volume signals
|
|
16
|
+
- AI-powered root-cause analysis via LangChain: supports Anthropic Claude, OpenAI GPT-4o, Google Gemini, and local Ollama models
|
|
17
|
+
- Webhook alerting — HMAC-SHA256 signed payloads with `WebhookEvent` delivery history
|
|
18
|
+
- Health trend tracking — per-service `HealthSnapshot` model; `snapshot_health` management command
|
|
19
|
+
- Real-time browser dashboard with Chart.js: error rate timeline, health bar chart with trend arrows, log level distribution, slowest endpoints, request volume sparkline, service status board
|
|
20
|
+
- Global timeframe filter (15M / 30M / 1H / 3H / 6H / 12H / 24H / 7D) controlling all charts simultaneously
|
|
21
|
+
- Log Explorer with expandable rows, syntax-highlighted stacktraces, and in-place AI analysis (4-state UX: idle → loading → result → cached)
|
|
22
|
+
- Anomaly detail modal with Z-score visualiser, AI diagnosis, and webhook delivery status
|
|
23
|
+
- Webhook Activity panel with live delivery feed and test webhook button
|
|
24
|
+
- Health Trends panel with per-service cards (colour-coded by trend direction)
|
|
25
|
+
- Full DRF REST API: health, logs, anomalies, webhooks, dashboard data
|
|
26
|
+
- Two-tier permission model: `nocturne.view_nocturne` (read) vs superuser (write/admin)
|
|
27
|
+
- `generate_demo_logs` management command: 975 entries, 3 realistic error spikes with stacktraces, seeded WebhookEvents and HealthSnapshots
|
|
28
|
+
- `nocturne_config` and `test_ai_diagnosis` management commands
|
|
29
|
+
- Django admin integration for all models
|
|
30
|
+
- Support for Django 4.0–5.0, Python 3.9–3.12
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rishav
|
|
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,9 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include CHANGELOG.md
|
|
4
|
+
recursive-include nocturne/templates *
|
|
5
|
+
recursive-include nocturne/static *
|
|
6
|
+
recursive-include nocturne/migrations *.py
|
|
7
|
+
global-exclude __pycache__
|
|
8
|
+
global-exclude *.py[co]
|
|
9
|
+
global-exclude .DS_Store
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-nocturne
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Intelligent observability for Django. Detect anomalies, diagnose with AI, alert via webhooks — plug in, migrate, done.
|
|
5
|
+
Author-email: Rishav <rishav00a@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rishav00a/django-nocturne
|
|
8
|
+
Project-URL: Documentation, https://django-nocturne.readthedocs.io
|
|
9
|
+
Project-URL: Repository, https://github.com/rishav00a/django-nocturne
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/rishav00a/django-nocturne/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/rishav00a/django-nocturne/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: django,observability,apm,monitoring,anomaly-detection,logging,webhook,ai
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Framework :: Django
|
|
15
|
+
Classifier: Framework :: Django :: 4.0
|
|
16
|
+
Classifier: Framework :: Django :: 4.1
|
|
17
|
+
Classifier: Framework :: Django :: 4.2
|
|
18
|
+
Classifier: Framework :: Django :: 5.0
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
28
|
+
Classifier: Topic :: System :: Monitoring
|
|
29
|
+
Classifier: Topic :: System :: Logging
|
|
30
|
+
Requires-Python: >=3.9
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Requires-Dist: django>=4.0
|
|
34
|
+
Requires-Dist: djangorestframework>=3.14
|
|
35
|
+
Requires-Dist: numpy>=1.24
|
|
36
|
+
Requires-Dist: requests>=2.28
|
|
37
|
+
Requires-Dist: langchain-core>=0.2
|
|
38
|
+
Provides-Extra: ollama
|
|
39
|
+
Requires-Dist: langchain-ollama>=0.1; extra == "ollama"
|
|
40
|
+
Provides-Extra: anthropic
|
|
41
|
+
Requires-Dist: langchain-anthropic>=0.1; extra == "anthropic"
|
|
42
|
+
Provides-Extra: openai
|
|
43
|
+
Requires-Dist: langchain-openai>=0.1; extra == "openai"
|
|
44
|
+
Provides-Extra: gemini
|
|
45
|
+
Requires-Dist: langchain-google-genai>=0.1; extra == "gemini"
|
|
46
|
+
Provides-Extra: all
|
|
47
|
+
Requires-Dist: langchain-ollama>=0.1; extra == "all"
|
|
48
|
+
Requires-Dist: langchain-anthropic>=0.1; extra == "all"
|
|
49
|
+
Requires-Dist: langchain-openai>=0.1; extra == "all"
|
|
50
|
+
Requires-Dist: langchain-google-genai>=0.1; extra == "all"
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest-django>=4.5; extra == "dev"
|
|
54
|
+
Requires-Dist: factory-boy>=3.2; extra == "dev"
|
|
55
|
+
Requires-Dist: coverage>=7.0; extra == "dev"
|
|
56
|
+
Dynamic: license-file
|
|
57
|
+
|
|
58
|
+
# django-nocturne
|
|
59
|
+
|
|
60
|
+
> Intelligent observability for Django. Detect anomalies, diagnose with AI, alert via webhooks — plug in, migrate, done.
|
|
61
|
+
|
|
62
|
+
[](https://badge.fury.io/py/django-nocturne)
|
|
63
|
+
[](https://pypi.org/project/django-nocturne/)
|
|
64
|
+
[](https://pypi.org/project/django-nocturne/)
|
|
65
|
+
[](https://opensource.org/licenses/MIT)
|
|
66
|
+
[](https://github.com/rishav00a/django-nocturne/actions/workflows/ci.yml)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## What is django-nocturne?
|
|
71
|
+
|
|
72
|
+
**django-nocturne** is a plug-and-play APM (Application Performance Monitoring) library for Django. It silently observes every HTTP request, statistically detects error spikes, asks an AI to diagnose them, fires webhook alerts, and renders a real-time dashboard — all with zero instrumentation changes to your application code.
|
|
73
|
+
|
|
74
|
+
### Features
|
|
75
|
+
|
|
76
|
+
- **Zero-code observability** — one middleware entry records every request automatically
|
|
77
|
+
- **Statistical anomaly detection** — Z-score analysis across 5-minute buckets; three severity tiers (MEDIUM / HIGH / CRITICAL)
|
|
78
|
+
- **Multi-signal health scoring** — composite 0–100 score from error rate, response time, and volume signals
|
|
79
|
+
- **AI-powered root-cause analysis** — LangChain interface supports Anthropic Claude, OpenAI GPT, Google Gemini, and local Ollama models
|
|
80
|
+
- **Webhook alerting** — HMAC-SHA256 signed payloads delivered to any HTTP endpoint when thresholds are breached
|
|
81
|
+
- **Health trend tracking** — per-service snapshots over time; dashboard shows improving/degrading/stable trends
|
|
82
|
+
- **Real-time dashboard** — Chart.js visualisations, log explorer with syntax-highlighted stacktraces, anomaly detail modals
|
|
83
|
+
- **Timeframe filter** — global 15M / 30M / 1H / 3H / 6H / 12H / 24H / 7D filter controlling all charts simultaneously
|
|
84
|
+
- **REST API** — full DRF API for health, logs, anomalies, webhooks, and dashboard data
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
### 1. Install
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Core (no AI)
|
|
94
|
+
pip install django-nocturne
|
|
95
|
+
|
|
96
|
+
# With your preferred AI backend
|
|
97
|
+
pip install "django-nocturne[anthropic]" # Claude
|
|
98
|
+
pip install "django-nocturne[openai]" # GPT-4o
|
|
99
|
+
pip install "django-nocturne[ollama]" # Local Llama via Ollama
|
|
100
|
+
pip install "django-nocturne[gemini]" # Google Gemini
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 2. Configure (`settings.py`)
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
INSTALLED_APPS = [
|
|
107
|
+
# ... your apps ...
|
|
108
|
+
"nocturne",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
MIDDLEWARE = [
|
|
112
|
+
# ... other middleware ...
|
|
113
|
+
"nocturne.middleware.NocturneMiddleware", # add last
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
NOCTURNE = {
|
|
117
|
+
"SERVICE_NAME": "my-api",
|
|
118
|
+
"ANOMALY_THRESHOLD": 2.0, # Z-score cutoff
|
|
119
|
+
"AI_BACKEND": "anthropic", # 'anthropic' | 'openai' | 'ollama' | 'gemini'
|
|
120
|
+
"AI_DIAGNOSIS_ENABLED": True,
|
|
121
|
+
"ANTHROPIC_API_KEY": env("ANTHROPIC_API_KEY"),
|
|
122
|
+
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. Wire up URLs (`urls.py`)
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from django.urls import include, path
|
|
130
|
+
|
|
131
|
+
urlpatterns = [
|
|
132
|
+
path("nocturne/", include("nocturne.urls")),
|
|
133
|
+
# ...
|
|
134
|
+
]
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 4. Migrate and run
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
python manage.py migrate
|
|
141
|
+
python manage.py runserver
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Open **http://localhost:8000/nocturne/dashboard/** — log in as a superuser.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Configuration Reference
|
|
149
|
+
|
|
150
|
+
All settings live inside the `NOCTURNE` dict in `settings.py`.
|
|
151
|
+
|
|
152
|
+
| Key | Default | Description |
|
|
153
|
+
|-----|---------|-------------|
|
|
154
|
+
| `SERVICE_NAME` | `"default"` | Tag applied to all log entries by the middleware |
|
|
155
|
+
| `ANOMALY_THRESHOLD` | `2.0` | Z-score threshold to trigger anomaly detection |
|
|
156
|
+
| `RETENTION_DAYS` | `30` | Auto-purge log entries older than N days |
|
|
157
|
+
| `EXCLUDE_PATHS` | `["/health", "/static", "/favicon.ico"]` | Paths skipped by middleware |
|
|
158
|
+
| `LOGIN_URL` | `"/admin/login/"` | Redirect for unauthenticated dashboard access |
|
|
159
|
+
| `AI_BACKEND` | `"ollama"` | Active LLM backend: `anthropic` / `openai` / `ollama` / `gemini` |
|
|
160
|
+
| `AI_DIAGNOSIS_ENABLED` | `True` | Master toggle for all AI calls |
|
|
161
|
+
| `ANTHROPIC_API_KEY` | `""` | Claude API key |
|
|
162
|
+
| `ANTHROPIC_MODEL` | `"claude-sonnet-4-6"` | Claude model ID |
|
|
163
|
+
| `OLLAMA_BASE_URL` | `"http://localhost:11434"` | Ollama server URL |
|
|
164
|
+
| `OLLAMA_MODEL` | `"llama3.2"` | Ollama model name |
|
|
165
|
+
| `OPENAI_API_KEY` | `""` | OpenAI API key |
|
|
166
|
+
| `OPENAI_MODEL` | `"gpt-4o"` | OpenAI model ID |
|
|
167
|
+
| `OPENAI_BASE_URL` | `"https://api.openai.com/v1"` | Override for Azure / Groq / vLLM |
|
|
168
|
+
| `GEMINI_API_KEY` | `""` | Google Gemini API key |
|
|
169
|
+
| `GEMINI_MODEL` | `"gemini-1.5-flash"` | Gemini model ID |
|
|
170
|
+
| `WEBHOOK_SECRET` | `""` | HMAC-SHA256 secret for webhook signature validation |
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## API Reference
|
|
175
|
+
|
|
176
|
+
All endpoints are prefixed with `/nocturne/` (or wherever you mounted the URLs).
|
|
177
|
+
|
|
178
|
+
| Method | Path | Auth | Description |
|
|
179
|
+
|--------|------|------|-------------|
|
|
180
|
+
| `GET` | `api/health/` | view | Health scores, error rate, anomaly counts |
|
|
181
|
+
| `GET` | `api/logs/` | view | Paginated log entries (no stacktrace) |
|
|
182
|
+
| `POST` | `api/logs/ingest/` | view | Ingest a log entry externally |
|
|
183
|
+
| `GET` | `api/logs/<id>/` | view | Full log entry including stacktrace |
|
|
184
|
+
| `POST` | `api/logs/<id>/analyse/` | view | AI root-cause analysis for a log |
|
|
185
|
+
| `GET` | `api/anomalies/` | view | List anomaly events |
|
|
186
|
+
| `PATCH` | `api/anomalies/<id>/` | admin | Resolve an anomaly |
|
|
187
|
+
| `POST` | `api/detect/` | admin | Trigger anomaly detection scan |
|
|
188
|
+
| `GET` | `api/dashboard/data/` | view | All chart data in one response |
|
|
189
|
+
| `GET` | `api/webhooks/` | admin | List webhook configurations |
|
|
190
|
+
| `POST` | `api/webhooks/` | admin | Create webhook configuration |
|
|
191
|
+
| `PUT` | `api/webhooks/<id>/` | admin | Update webhook configuration |
|
|
192
|
+
| `DELETE` | `api/webhooks/<id>/` | admin | Delete webhook configuration |
|
|
193
|
+
| `GET` | `api/webhooks/events/` | view | Webhook delivery history |
|
|
194
|
+
| `POST` | `api/webhooks/test/` | admin | Send test webhook to all active configs |
|
|
195
|
+
| `POST` | `api/webhook/receive/` | admin | Simulated receiver endpoint |
|
|
196
|
+
| `GET` | `dashboard/` | view | Browser dashboard (HTML) |
|
|
197
|
+
|
|
198
|
+
**Auth tiers:**
|
|
199
|
+
- `view` — superuser **or** user with `nocturne.view_nocturne` permission
|
|
200
|
+
- `admin` — superuser only
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Webhook Payload
|
|
205
|
+
|
|
206
|
+
When an anomaly is detected, Nocturne fires this payload to every active webhook config:
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"event": "anomaly.detected",
|
|
211
|
+
"timestamp": "2026-06-19T03:22:27Z",
|
|
212
|
+
"watchdog_version": "0.1.0",
|
|
213
|
+
"anomaly": {
|
|
214
|
+
"id": 42,
|
|
215
|
+
"service": "auth-service",
|
|
216
|
+
"severity": "CRITICAL",
|
|
217
|
+
"z_score": 4.7,
|
|
218
|
+
"error_count": 50,
|
|
219
|
+
"window_start": "...",
|
|
220
|
+
"window_end": "...",
|
|
221
|
+
"ai_diagnosis": "..."
|
|
222
|
+
},
|
|
223
|
+
"health": {
|
|
224
|
+
"score_before": 85.0,
|
|
225
|
+
"score_after": 20.0,
|
|
226
|
+
"trend": "degrading"
|
|
227
|
+
},
|
|
228
|
+
"action_required": true,
|
|
229
|
+
"dashboard_url": "/nocturne/dashboard/"
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Headers sent:
|
|
234
|
+
- `Content-Type: application/json`
|
|
235
|
+
- `X-Watchdog-Event: anomaly.detected`
|
|
236
|
+
- `X-Watchdog-Severity: CRITICAL`
|
|
237
|
+
- `X-Watchdog-Signature: sha256=<hmac>` (when `WEBHOOK_SECRET` is set)
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Management Commands
|
|
242
|
+
|
|
243
|
+
Commands included with the package (available after `pip install django-nocturne`):
|
|
244
|
+
|
|
245
|
+
| Command | Description |
|
|
246
|
+
|---------|-------------|
|
|
247
|
+
| `nocturne_config` | Print resolved NOCTURNE settings + DB stats |
|
|
248
|
+
| `test_ai_diagnosis` | Verify AI backend is working |
|
|
249
|
+
| `create_nocturne_user` | Create a viewer user with correct permissions |
|
|
250
|
+
| `snapshot_health` | Take a health snapshot for all active services |
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
python manage.py nocturne_config
|
|
254
|
+
python manage.py test_ai_diagnosis
|
|
255
|
+
python manage.py test_ai_diagnosis --backend openai
|
|
256
|
+
python manage.py create_nocturne_user
|
|
257
|
+
python manage.py create_nocturne_user --username viewer1 --password secret
|
|
258
|
+
python manage.py snapshot_health
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Commands available in the example project only:
|
|
262
|
+
|
|
263
|
+
| Command | Description |
|
|
264
|
+
|---------|-------------|
|
|
265
|
+
| `generate_demo_logs` | Seed 975 demo logs with 3 anomaly spikes, WebhookEvents, and HealthSnapshots |
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
python manage.py generate_demo_logs
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Running the Example Project
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
git clone https://github.com/rishav00a/django-nocturne
|
|
277
|
+
cd django-nocturne
|
|
278
|
+
python -m venv .venv && source .venv/bin/activate
|
|
279
|
+
pip install -e ".[anthropic]" # or [ollama], [openai], [gemini]
|
|
280
|
+
cd example_project
|
|
281
|
+
python manage.py migrate
|
|
282
|
+
python manage.py createsuperuser
|
|
283
|
+
python manage.py generate_demo_logs
|
|
284
|
+
python manage.py runserver
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Visit **http://localhost:8000/nocturne/dashboard/** and log in.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Running Tests
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
pip install -e ".[dev]"
|
|
295
|
+
pytest tests/ -v
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Changelog
|
|
307
|
+
|
|
308
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# django-nocturne
|
|
2
|
+
|
|
3
|
+
> Intelligent observability for Django. Detect anomalies, diagnose with AI, alert via webhooks — plug in, migrate, done.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/py/django-nocturne)
|
|
6
|
+
[](https://pypi.org/project/django-nocturne/)
|
|
7
|
+
[](https://pypi.org/project/django-nocturne/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://github.com/rishav00a/django-nocturne/actions/workflows/ci.yml)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What is django-nocturne?
|
|
14
|
+
|
|
15
|
+
**django-nocturne** is a plug-and-play APM (Application Performance Monitoring) library for Django. It silently observes every HTTP request, statistically detects error spikes, asks an AI to diagnose them, fires webhook alerts, and renders a real-time dashboard — all with zero instrumentation changes to your application code.
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
- **Zero-code observability** — one middleware entry records every request automatically
|
|
20
|
+
- **Statistical anomaly detection** — Z-score analysis across 5-minute buckets; three severity tiers (MEDIUM / HIGH / CRITICAL)
|
|
21
|
+
- **Multi-signal health scoring** — composite 0–100 score from error rate, response time, and volume signals
|
|
22
|
+
- **AI-powered root-cause analysis** — LangChain interface supports Anthropic Claude, OpenAI GPT, Google Gemini, and local Ollama models
|
|
23
|
+
- **Webhook alerting** — HMAC-SHA256 signed payloads delivered to any HTTP endpoint when thresholds are breached
|
|
24
|
+
- **Health trend tracking** — per-service snapshots over time; dashboard shows improving/degrading/stable trends
|
|
25
|
+
- **Real-time dashboard** — Chart.js visualisations, log explorer with syntax-highlighted stacktraces, anomaly detail modals
|
|
26
|
+
- **Timeframe filter** — global 15M / 30M / 1H / 3H / 6H / 12H / 24H / 7D filter controlling all charts simultaneously
|
|
27
|
+
- **REST API** — full DRF API for health, logs, anomalies, webhooks, and dashboard data
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### 1. Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Core (no AI)
|
|
37
|
+
pip install django-nocturne
|
|
38
|
+
|
|
39
|
+
# With your preferred AI backend
|
|
40
|
+
pip install "django-nocturne[anthropic]" # Claude
|
|
41
|
+
pip install "django-nocturne[openai]" # GPT-4o
|
|
42
|
+
pip install "django-nocturne[ollama]" # Local Llama via Ollama
|
|
43
|
+
pip install "django-nocturne[gemini]" # Google Gemini
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Configure (`settings.py`)
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
INSTALLED_APPS = [
|
|
50
|
+
# ... your apps ...
|
|
51
|
+
"nocturne",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
MIDDLEWARE = [
|
|
55
|
+
# ... other middleware ...
|
|
56
|
+
"nocturne.middleware.NocturneMiddleware", # add last
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
NOCTURNE = {
|
|
60
|
+
"SERVICE_NAME": "my-api",
|
|
61
|
+
"ANOMALY_THRESHOLD": 2.0, # Z-score cutoff
|
|
62
|
+
"AI_BACKEND": "anthropic", # 'anthropic' | 'openai' | 'ollama' | 'gemini'
|
|
63
|
+
"AI_DIAGNOSIS_ENABLED": True,
|
|
64
|
+
"ANTHROPIC_API_KEY": env("ANTHROPIC_API_KEY"),
|
|
65
|
+
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 3. Wire up URLs (`urls.py`)
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from django.urls import include, path
|
|
73
|
+
|
|
74
|
+
urlpatterns = [
|
|
75
|
+
path("nocturne/", include("nocturne.urls")),
|
|
76
|
+
# ...
|
|
77
|
+
]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 4. Migrate and run
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python manage.py migrate
|
|
84
|
+
python manage.py runserver
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Open **http://localhost:8000/nocturne/dashboard/** — log in as a superuser.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Configuration Reference
|
|
92
|
+
|
|
93
|
+
All settings live inside the `NOCTURNE` dict in `settings.py`.
|
|
94
|
+
|
|
95
|
+
| Key | Default | Description |
|
|
96
|
+
|-----|---------|-------------|
|
|
97
|
+
| `SERVICE_NAME` | `"default"` | Tag applied to all log entries by the middleware |
|
|
98
|
+
| `ANOMALY_THRESHOLD` | `2.0` | Z-score threshold to trigger anomaly detection |
|
|
99
|
+
| `RETENTION_DAYS` | `30` | Auto-purge log entries older than N days |
|
|
100
|
+
| `EXCLUDE_PATHS` | `["/health", "/static", "/favicon.ico"]` | Paths skipped by middleware |
|
|
101
|
+
| `LOGIN_URL` | `"/admin/login/"` | Redirect for unauthenticated dashboard access |
|
|
102
|
+
| `AI_BACKEND` | `"ollama"` | Active LLM backend: `anthropic` / `openai` / `ollama` / `gemini` |
|
|
103
|
+
| `AI_DIAGNOSIS_ENABLED` | `True` | Master toggle for all AI calls |
|
|
104
|
+
| `ANTHROPIC_API_KEY` | `""` | Claude API key |
|
|
105
|
+
| `ANTHROPIC_MODEL` | `"claude-sonnet-4-6"` | Claude model ID |
|
|
106
|
+
| `OLLAMA_BASE_URL` | `"http://localhost:11434"` | Ollama server URL |
|
|
107
|
+
| `OLLAMA_MODEL` | `"llama3.2"` | Ollama model name |
|
|
108
|
+
| `OPENAI_API_KEY` | `""` | OpenAI API key |
|
|
109
|
+
| `OPENAI_MODEL` | `"gpt-4o"` | OpenAI model ID |
|
|
110
|
+
| `OPENAI_BASE_URL` | `"https://api.openai.com/v1"` | Override for Azure / Groq / vLLM |
|
|
111
|
+
| `GEMINI_API_KEY` | `""` | Google Gemini API key |
|
|
112
|
+
| `GEMINI_MODEL` | `"gemini-1.5-flash"` | Gemini model ID |
|
|
113
|
+
| `WEBHOOK_SECRET` | `""` | HMAC-SHA256 secret for webhook signature validation |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## API Reference
|
|
118
|
+
|
|
119
|
+
All endpoints are prefixed with `/nocturne/` (or wherever you mounted the URLs).
|
|
120
|
+
|
|
121
|
+
| Method | Path | Auth | Description |
|
|
122
|
+
|--------|------|------|-------------|
|
|
123
|
+
| `GET` | `api/health/` | view | Health scores, error rate, anomaly counts |
|
|
124
|
+
| `GET` | `api/logs/` | view | Paginated log entries (no stacktrace) |
|
|
125
|
+
| `POST` | `api/logs/ingest/` | view | Ingest a log entry externally |
|
|
126
|
+
| `GET` | `api/logs/<id>/` | view | Full log entry including stacktrace |
|
|
127
|
+
| `POST` | `api/logs/<id>/analyse/` | view | AI root-cause analysis for a log |
|
|
128
|
+
| `GET` | `api/anomalies/` | view | List anomaly events |
|
|
129
|
+
| `PATCH` | `api/anomalies/<id>/` | admin | Resolve an anomaly |
|
|
130
|
+
| `POST` | `api/detect/` | admin | Trigger anomaly detection scan |
|
|
131
|
+
| `GET` | `api/dashboard/data/` | view | All chart data in one response |
|
|
132
|
+
| `GET` | `api/webhooks/` | admin | List webhook configurations |
|
|
133
|
+
| `POST` | `api/webhooks/` | admin | Create webhook configuration |
|
|
134
|
+
| `PUT` | `api/webhooks/<id>/` | admin | Update webhook configuration |
|
|
135
|
+
| `DELETE` | `api/webhooks/<id>/` | admin | Delete webhook configuration |
|
|
136
|
+
| `GET` | `api/webhooks/events/` | view | Webhook delivery history |
|
|
137
|
+
| `POST` | `api/webhooks/test/` | admin | Send test webhook to all active configs |
|
|
138
|
+
| `POST` | `api/webhook/receive/` | admin | Simulated receiver endpoint |
|
|
139
|
+
| `GET` | `dashboard/` | view | Browser dashboard (HTML) |
|
|
140
|
+
|
|
141
|
+
**Auth tiers:**
|
|
142
|
+
- `view` — superuser **or** user with `nocturne.view_nocturne` permission
|
|
143
|
+
- `admin` — superuser only
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Webhook Payload
|
|
148
|
+
|
|
149
|
+
When an anomaly is detected, Nocturne fires this payload to every active webhook config:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"event": "anomaly.detected",
|
|
154
|
+
"timestamp": "2026-06-19T03:22:27Z",
|
|
155
|
+
"watchdog_version": "0.1.0",
|
|
156
|
+
"anomaly": {
|
|
157
|
+
"id": 42,
|
|
158
|
+
"service": "auth-service",
|
|
159
|
+
"severity": "CRITICAL",
|
|
160
|
+
"z_score": 4.7,
|
|
161
|
+
"error_count": 50,
|
|
162
|
+
"window_start": "...",
|
|
163
|
+
"window_end": "...",
|
|
164
|
+
"ai_diagnosis": "..."
|
|
165
|
+
},
|
|
166
|
+
"health": {
|
|
167
|
+
"score_before": 85.0,
|
|
168
|
+
"score_after": 20.0,
|
|
169
|
+
"trend": "degrading"
|
|
170
|
+
},
|
|
171
|
+
"action_required": true,
|
|
172
|
+
"dashboard_url": "/nocturne/dashboard/"
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Headers sent:
|
|
177
|
+
- `Content-Type: application/json`
|
|
178
|
+
- `X-Watchdog-Event: anomaly.detected`
|
|
179
|
+
- `X-Watchdog-Severity: CRITICAL`
|
|
180
|
+
- `X-Watchdog-Signature: sha256=<hmac>` (when `WEBHOOK_SECRET` is set)
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Management Commands
|
|
185
|
+
|
|
186
|
+
Commands included with the package (available after `pip install django-nocturne`):
|
|
187
|
+
|
|
188
|
+
| Command | Description |
|
|
189
|
+
|---------|-------------|
|
|
190
|
+
| `nocturne_config` | Print resolved NOCTURNE settings + DB stats |
|
|
191
|
+
| `test_ai_diagnosis` | Verify AI backend is working |
|
|
192
|
+
| `create_nocturne_user` | Create a viewer user with correct permissions |
|
|
193
|
+
| `snapshot_health` | Take a health snapshot for all active services |
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
python manage.py nocturne_config
|
|
197
|
+
python manage.py test_ai_diagnosis
|
|
198
|
+
python manage.py test_ai_diagnosis --backend openai
|
|
199
|
+
python manage.py create_nocturne_user
|
|
200
|
+
python manage.py create_nocturne_user --username viewer1 --password secret
|
|
201
|
+
python manage.py snapshot_health
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Commands available in the example project only:
|
|
205
|
+
|
|
206
|
+
| Command | Description |
|
|
207
|
+
|---------|-------------|
|
|
208
|
+
| `generate_demo_logs` | Seed 975 demo logs with 3 anomaly spikes, WebhookEvents, and HealthSnapshots |
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
python manage.py generate_demo_logs
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Running the Example Project
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
git clone https://github.com/rishav00a/django-nocturne
|
|
220
|
+
cd django-nocturne
|
|
221
|
+
python -m venv .venv && source .venv/bin/activate
|
|
222
|
+
pip install -e ".[anthropic]" # or [ollama], [openai], [gemini]
|
|
223
|
+
cd example_project
|
|
224
|
+
python manage.py migrate
|
|
225
|
+
python manage.py createsuperuser
|
|
226
|
+
python manage.py generate_demo_logs
|
|
227
|
+
python manage.py runserver
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Visit **http://localhost:8000/nocturne/dashboard/** and log in.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Running Tests
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
pip install -e ".[dev]"
|
|
238
|
+
pytest tests/ -v
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Contributing
|
|
244
|
+
|
|
245
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Changelog
|
|
250
|
+
|
|
251
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT — see [LICENSE](LICENSE).
|