Metadata-Version: 2.1
Name: django_aetos
Version: 0.2.0
Summary: Export Django monitoring metrics for prometheus.io
Project-URL: Homepage, https://github.com/uberspace/django-aetos
Project-URL: Issues, https://github.com/uberspace/django-aetos/issues
Author-email: "uberspace.de" <hallo@uberspace.de>
Maintainer-email: "uberspace.de" <hallo@uberspace.de>
License: Copyright (c) 2023 uberspace.de
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.txt
Keywords: exporter,metrics,prometheus
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Requires-Python: >=3.9
Description-Content-Type: text/x-rst

Django Aetos
============

A Django app to expose metrics to be scraped by prometheus.io.

Usage
-----

First, install django-aetos:

.. code-block:: python

    pip install django-aetos

then, add the app to `settings.py`:

.. code-block:: python

    INSTALLED_APPS = [
        # ... other apps ...
        "django_aetos",
        # ... other apps ...
    ]

and send requests to `/metrics` to Aetos in your `urls.py`:

.. code-block:: python

    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`:

.. code-block:: python

    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`:

.. code-block:: python

    from django.apps import AppConfig

    class YourAppConfig(AppConfig):
        name = "yourapp"

        def ready(self):
            from . import signals  # NOQA

Dev Setup
---------

.. code-block::

    python3 -m venv venv
    source venv/bin/activate
    make setup
    make install-dev

Testing
---------

.. code-block::

    make test

Packaging
---------

.. code-block::

    git pull
    make bump-version part=minor
    git push origin main v$(bump-my-version show current_version)

.. code-block::

    make build
    make upload-test

once the package looks good, run `make upload`.
