Django Aetos
A Django app to expose metrics to be scraped by prometheus.io.
Usage
First, install django-aetos:
pip install django-aetos
then, add the app to settings.py:
INSTALLED_APPS = [
# ... other apps ...
"django_aetos",
# ... other apps ...
]
configure aetos in settings.py:
ℹ️ Important: When using django-aetos in a project behind a reverse proxy, include django-xff in your project, so that a request’s REMOTE_ADDR header gets rewritten to the correct client ip.
# on enabled ip allowlist with empty list, requests are denied
AETOS_ENABLE_IP_ALLOWLIST = True
AETOS_IP_ALLOWLIST = ["127.0.0.1"]
# enables authentication via bearer token
# if enabled with empty list, requests are denied
AETOS_ENABLE_AUTH = True
AETOS_AUTH_TOKENLIST = ["ooy9Evuth0zahka"]
and send requests to /metrics to Aetos in your urls.py:
from django.urls import include
urlpatterns = [
path("", include("django_aetos.urls")),
# ... your other patterns ...
]
Then, add your own metrics using the @metric_collector decorator. Your signal handler can return multiple metrics, each represented as a dict within a list of generator.
Your src/app/signals.py:
from django_aetos.signals import metric_collector
@metric_collector(category="cheap")
def metric_universes_count(sender, **kwargs):
yield {
"name": "universes_count",
"help": "Total number of universes",
"type": "counter",
"value": 1,
}
@metric_collector(category="expensive")
def metric_complex_calculation(sender, **kwargs):
yield {
"name": "complex_metric",
"help": "An expensive calculation",
"type": "gauge",
"value": some_expensive_database_query(),
}
You can do anything you like here, like make database queries or look at files in the filesystem.
Multiple Metric Endpoints
Metrics are organized by category. You can scrape different categories at different intervals:
/metrics - Returns ALL metrics (all categories combined)
/metrics/cheap - Returns only metrics tagged with category=”cheap”
/metrics/expensive - Returns only metrics tagged with category=”expensive”
This allows you to scrape cheap metrics frequently and expensive metrics less often.
Categories are arbitrary strings - use any names that make sense for your use case (e.g., “fast”, “slow”, “realtime”, “daily”, etc.).
Legacy Pattern
The old signal-based pattern still works for backward compatibility:
from django.dispatch import receiver
from django_aetos.signals import collect_metrics
@receiver(collect_metrics, dispatch_uid='metric_legacy')
def metric_legacy(sender, **kwargs):
yield {
"name": "legacy_metric",
"help": "Using the old pattern",
"type": "counter",
"value": 42,
}
Metrics registered this way appear on /metrics but not on category-specific endpoints.
To make sure your receiver actually connects, add an import to your src/app/apps.py:
from django.apps import AppConfig
class YourAppConfig(AppConfig):
name = "yourapp"
def ready(self):
from . import signals # NOQA
Dev Setup
python3 -m venv venv
source venv/bin/activate
make setup
make install-dev
Testing
make test
Packaging
git pull
make bump-version part=minor
git push origin main v$(bump-my-version show current_version)
make build
make upload-test
once the package looks good, run make upload.
Metadata
Release files for django-aetos 0.4.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_aetos-0.4.0.tar.gz | 11.1 kB | Without provenance | Details for django_aetos-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_aetos-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for django_aetos-0.4.0-py3-none-any.whl |
Total release size: 18.2 kB
Release files / django_aetos-0.4.0.tar.gz
| Download URL | django_aetos-0.4.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b65d54a5c016ccd6c20dba85efc9b4883e5c081df23b1b20e43c367d67177c12
|
|
BLAKE2b-256 checksum How to use checksums |
155386d5d306b8d5b614b131a1e087938700ddfc7f1430bb86d8c82527512892
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / django_aetos-0.4.0-py3-none-any.whl
| Download URL | django_aetos-0.4.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0cd82331453575c5ffcecfe9d648aef892970e3fb0ec9d1db8a4c7a0ebe50a07
|
|
BLAKE2b-256 checksum How to use checksums |
67974c43e15cb9734cd88646f31e1f8a17ac86575b01dbb7761a15109616dbac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for django-aetos 0.4.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.