Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

marselester/django-prometheus-via-statsd

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Instrumenting Django with Prometheus and StatsD

This repository is an example setup of Django application that exposes its metrics for Prometheus monitoring toolkit using StatsD and statsd_exporter. The application and Prometheus run on Kubernetes cluster.

Get the Olympus application running to emit StatsD metrics.

$ git clone https://github.com/marselester/django-prometheus-via-statsd.git
$ cd ./django-prometheus-via-statsd/olympus-app
$ virtualenv venv
$ source ./venv/bin/activate
$ pip install -r requirements.txt
$ python manage.py runserver
$ curl http://localhost:8000/hello
Hello, World!

Forward DogStatsD Metrics to Prometheus

Another example is based on Datadog's StatsD fork (supports metric tagging).

$ cd ./django-prometheus-via-statsd/weather-app
$ virtualenv venv
$ source ./venv/bin/activate
$ pip install -r requirements.txt
$ python manage.py runserver
$ curl http://localhost:8000/forecast
It is sunny!

If you run tcpdump, you'll see StatsD metrics with tags.

$ tcpdump -i lo0 udp port 8125 -A
E..Ld ..@................8.Kweather.weatherapi.responses.total:1|c|#code:400
E..zi...@................f.yweather.request.duration.seconds:0.00187611579895|h|#method:GET,path:/forecast,status_code:200

They will be converted by statsd_exporter into:

$ statsd_exporter \
    -statsd.listen-address=:8125 \
    -statsd.add-suffix=false
# HELP weather_request_duration_seconds Metric autogenerated by statsd_exporter.
# TYPE weather_request_duration_seconds summary
weather_request_duration_seconds{method="GET",path="/forecast",status_code="200",quantile="0.5"} 0.00154209136963
weather_request_duration_seconds{method="GET",path="/forecast",status_code="200",quantile="0.9"} 0.00154209136963
weather_request_duration_seconds{method="GET",path="/forecast",status_code="200",quantile="0.99"} 0.00154209136963
weather_request_duration_seconds_sum{method="GET",path="/forecast",status_code="200"} 0.00154209136963
weather_request_duration_seconds_count{method="GET",path="/forecast",status_code="200"} 1
# HELP weather_weatherapi_responses_total Metric autogenerated by statsd_exporter.
# TYPE weather_weatherapi_responses_total counter
weather_weatherapi_responses_total{code="500"} 1

About

Instrumenting Django with Prometheus and StatsD.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages