Export Django monitoring metrics for prometheus.io
Project description
A Django app to expose metrics to be scraped by prometheus.io.
Usage
First, add the app to settings.py:
INSTALLED_APPS = [
# ... other apps ...
"aetos",
# ... other apps ...
]
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. To do this, listen for the collect_metrics signal. Refer to [the django docs](https://docs.djangoproject.com/en/dev/topics/signals/) on details how to do this.
Your signal handler can return multiple metrics, each represented as a dict within a list of generator.
Your src/app/signals.py:
from django.dispatch import receiver
from django_aetos.signals import collect_metrics
@receiver(collect_metrics, dispatch_uid='metric_universes_count')
def metric_universes_count(sender, **kwargs):
yield {
"name": f"universes_count",
"help": f"Total number of universes",
"type": "counter",
"value": 1,
}
You can do anything you like here, like make database queries or look at files in the filesystem.
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
pip install -r requirements.txt -e .
pre-commit install --install-hooks
Packaging
mkdir -p dist
rm -f dist/*
python3 -m build
python3 -m twine upload --repository testpypi dist/*.tar.gz dist/*.whl
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_aetos-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | daae7568e741d646540af0970ad3e58d4e8e7aea9a88fc986facd8c0df896ffb |
|
MD5 | fa58b75d9582e44d2c5c8f2209aed484 |
|
BLAKE2b-256 | 5409470c318416d21bad2a4142420bcc528d3a048f0990056d920cd13a8aa736 |