Skip to main content

Export Django monitoring metrics for prometheus.io

Project description

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](https://pypi.org/project/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_TOKENS = ["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 by listening 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": "universes_count",
        "help": "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
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_aetos-0.3.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

django_aetos-0.3.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file django_aetos-0.3.0.tar.gz.

File metadata

  • Download URL: django_aetos-0.3.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for django_aetos-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f8ae2cff816c65a9b4c20abd4ebcb346271ee50177c804220a862c01de8f1189
MD5 42985a614284ac5df80217bdf3dcad82
BLAKE2b-256 3bdf9c185ac513213cd2e5ad728c45f6167bd2f9b7e1b6a09cacb8e3eff7e04d

See more details on using hashes here.

File details

Details for the file django_aetos-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_aetos-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 153f8004a886b2c829949e03a82fccb1ad8536996a4d96de078d072ee35ab610
MD5 d39e0da0e6bf5fd2eca18fe5272e7617
BLAKE2b-256 ef6e018a3e8281892e6cdd35c033db28762d252e7eb7222f526d8934b690d2ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page