Library to monitor your Django 2.0+ app using Satella's metrics
Project description
django-satella-metrics
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.
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
}
}
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
Built Distribution
File details
Details for the file django-satella-metrics-1.4.win-amd64.zip
.
File metadata
- Download URL: django-satella-metrics-1.4.win-amd64.zip
- Upload date:
- Size: 7.2 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d53f521426435738ac2c054d650eaa8a6b1975d84516caa640e0f0bf5132d83 |
|
MD5 | b5aa0bb029893a9d6b3fff6299f04666 |
|
BLAKE2b-256 | bb4a12853092d17b143c0b5f0edf8178ee10244521c9fdf3214b2f7e8ce3b70e |
File details
Details for the file django_satella_metrics-1.4-py2.py3-none-any.whl
.
File metadata
- Download URL: django_satella_metrics-1.4-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccca3112213a93d7236b24ca0d424f79f6d6ac41336d27dcf2b9fb2dd65b056c |
|
MD5 | b9b44b31d416d66635eb68a46f83b4f3 |
|
BLAKE2b-256 | 39e642b2c8b84d36067bda01664203b14039a28c08fc2fc9e32aa67f53365817 |