django-container-monitor
Watch the server and the Docker containers behind a Django project, from the Django admin.
- Host and containers. CPU, load, memory, swap and disks of the host; state, health, restarts, CPU and memory against its own limit for every container.
- A verdict. Each check is OK, warning or danger, with the reasons, worst first. Thresholds are settings.
- Alerts on change. When the status changes, and on recovery; again every
REPEAT_ALERT_MINUTESwhile a problem lasts. Log, e-mail, webhooks (Slack, Mattermost, Discord, Teams through a workflow, anything that takes JSON), a Django signal, or your own channel. - Container logs in the admin. The last lines of any container, read on demand.
- A status endpoint for uptime monitors: JSON, HTTP 503 on danger.
- No dependencies. The Docker API is spoken over the standard library, via the socket or a read-only proxy.
Install
pip install django-container-monitor
INSTALLED_APPS = [..., "container_monitor"]
# urls.py - optional, for the status endpoint
path("monitor/", include("container_monitor.urls")),
python manage.py migrate container_monitor
Schedule a check every few minutes - cron, a systemd timer, Celery beat, or
anything that enqueues container_monitor.tasks.run_check with django.tasks:
*/5 * * * * python manage.py monitor_check
0 4 * * * python manage.py monitor_prune
Container monitor > Checks shows the history, Check now, and each container's logs.
Reaching Docker safely
The worker running the check needs the Docker Engine API. Mounting
/var/run/docker.sock gives that process root on the host, so put a
read-only proxy in between:
# docker-compose.yml
docker-proxy:
image: tecnativa/docker-socket-proxy:v0.4.2
environment: {CONTAINERS: 1, INFO: 1, POST: 0}
volumes: ["/var/run/docker.sock:/var/run/docker.sock:ro"]
CONTAINER_MONITOR = {"DOCKER_URL": "http://docker-proxy:2375"}
Inside a container, /proc still describes the whole machine, so host figures
are the server's. The disk checked is the one DISK_PATHS live on.
Settings
CONTAINER_MONITOR = {
"DOCKER_URL": "unix:///var/run/docker.sock", # or None: host only
"CONTAINERS": ["shop-*"], # judged (fnmatch); others are listed only
"DISK_PATHS": ["/", "/var/lib/postgresql"],
"THRESHOLDS": { # (warning, danger), percent
"memory": (85, 93), # host memory, by MemAvailable
"swap": (25, 60),
"disk": (80, 90),
"cpu": (85, 97),
"load_per_core": (1.0, 2.0),
"container_memory": (85, 95),
},
"ALERTS": [
{"BACKEND": "container_monitor.alerts.LogAlert"},
{"BACKEND": "container_monitor.alerts.EmailAlert",
"OPTIONS": {"recipients": ["ops@example.com"]}, "MIN_STATUS": "danger"},
{"BACKEND": "container_monitor.alerts.WebhookAlert",
"OPTIONS": {"url": "https://hooks.slack.com/services/..."}},
],
"REPEAT_ALERT_MINUTES": 60, # None: only on change
"RETENTION_DAYS": 30,
"TOKEN": "a-long-random-string", # for the status endpoint
"LOG_LINES": 200,
}
A channel is a class with send(subject, message, check); subclass
container_monitor.alerts.AlertChannel and point BACKEND at it. To react in
code instead:
from container_monitor.signals import status_changed
@receiver(status_changed)
def page_someone(sender, check, previous_status, status, **kwargs):
...
Status endpoint
curl -H "Authorization: Bearer $TOKEN" https://example.com/monitor/status/
HTTP 200 while OK or warning, 503 on danger, so a plain uptime check alerts on what matters. Staff users can open it in the browser without the token.
Alongside django-health-check
django-health-check answers "can this instance serve requests?" for load balancers and probes; this package keeps a history of the machine and its containers and tells you when it changes. They do not overlap and can run side by side.
Development
python runtests.py
License
BSD-3-Clause.
Metadata
Release files for django-container-monitor 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_container_monitor-0.1.0.tar.gz | 22.8 kB | Without provenance | Details for django_container_monitor-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_container_monitor-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_container_monitor-0.1.0-py3-none-any.whl |
Total release size: 45.5 kB
Release files / django_container_monitor-0.1.0.tar.gz
| Download URL | django_container_monitor-0.1.0.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06579829b18680703a84f0d7c6c1bb5d0a83d58c9ee6f4ae7d9214b226de6962
|
|
BLAKE2b-256 checksum How to use checksums |
d48b9e0414e93458c0b9ac23d24ca5c9e747a0cf76a4d53576dd35da830a4268
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / django_container_monitor-0.1.0-py3-none-any.whl
| Download URL | django_container_monitor-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1042db7a93ebf21d6ba3debbe560c2b8b571d3db07463bc0c8f0e10bffc6e635
|
|
BLAKE2b-256 checksum How to use checksums |
c72d34e88dd6af6621aac86d610bfd161e887c648a89853c7d17d71d900ce0f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for django-container-monitor 0.1.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.