Skip to main content

Library to monitor your Django 2.0+ app using Satella's metrics

Project description

django-satella-metrics

Build Status Test Coverage Code Climate Issue Count PyPI PyPI version PyPI

django-satella-metrics is a library to measure Django's requests using Satella's metrics

See LICENSE for text of the license. This library may contain code taken from elsewhere on the internets, so this is copyright (c) respective authors.

As far as compatible Djangos are considered: This has been tested as early as Django 1.8 with Python 3.6 and as late as

Usage

First, add the following to your MIDDLEWARE (or MIDDLEWARE_CLASSES): 'django_satella_metrics.DjangoSatellaMetricsMiddleware'

Define the following in your settings:

from satella.instrumentation.metrics import getMetric
DJANGO_SATELLA_METRICS = {
    'summary_metric': getMetric('django.summary', 'summary'),
    'histogram_metric': getMetric('django.histogram', 'histogram'),
    'status_codes_metric': getMetric('django.status_codes', 'counter')
}

Or pass any other metrics that you'd like. This is the default configuration, so if you pass nothing it will be as if you passed the listed code.

Extra configuration

If you want URL readed from the request in a different way than reading URL, you can define a key called url_getter. This should contain a callable that accepts a single argument, the request passed, and return a str, the URL to use.

Additionally, if you want the Prometheus exporter to add extra labels to your exported metrics, you can add a key to the config of name extra_labels which will contain a dict with the labels to add, eg.

DJANGO_SATELLA_METRICS = {
    'extra_labels': {
        'service_name': 'my_service',
        'instance': 1
    },
    'monitor_metrics': False
}

If you specify monitor_metrics, which is a bool, to be True, then /metrics endpoint will also be considered during monitoring.

Exporting from the same server

If you want to export metrics to Prometheus using Django, here you go. Just add following rule to your urlpatterns:

from django_satella_metrics import export_metrics

urlpatterns = [
    ... ,
    path('metrics', export_metrics),
    ...
]

External Prometheus server

If you want to set up an external Prometheus server, use the following snippet:

from satella.instrumentation.metrics.exporters import PrometheusHTTPExporterThread
phet = PrometheusHTTPExporterThread('0.0.0.0', 8080, {'service_name': 'my_service'})
phet.start()

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-satella-metrics-1.5.win-amd64.zip (7.3 kB view details)

Uploaded Source

Built Distribution

django_satella_metrics-1.5-py2.py3-none-any.whl (5.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-satella-metrics-1.5.win-amd64.zip.

File metadata

  • Download URL: django-satella-metrics-1.5.win-amd64.zip
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4

File hashes

Hashes for django-satella-metrics-1.5.win-amd64.zip
Algorithm Hash digest
SHA256 ee9787d40fb3d5b95bdf0cb6f9803dc1b25579b50555a8f055915e13cfeae6e6
MD5 e62bad7ee854141fe6834d39d1d9f7bc
BLAKE2b-256 7a0b82b2e54b12c74c786aa98c6de1d3183e4e3f6d02659af4c1bc918e3ca575

See more details on using hashes here.

File details

Details for the file django_satella_metrics-1.5-py2.py3-none-any.whl.

File metadata

  • Download URL: django_satella_metrics-1.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4

File hashes

Hashes for django_satella_metrics-1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b83b5eab85936d7f275e93f88ec101d531024b5c5e5db5d859e981f528cfc282
MD5 a592676cb6cc4039fae00134209dba99
BLAKE2b-256 8cfbf3b858e8b6e0462e4895bd745ec29cb2bfa194d40a4265bf12a92282b33f

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