Fri 09 June 2017

If you ever wondered how to monitor your Django application with Prometheus this article is for you.
Quick search on the topic will lead you to django-prometheus.
For those who don't want to use it, there is another way to export application metrics
via StatsD.

The idea is to send metrics from Django by StatsD Python library to StatsD server over UDP.
Here is an example of incrementing "hello.requests.total" metric every time "say_hello" view is run.

StatsD server aggregates measurements over time and flushes them into monitoring backend.
Here statsd_exporter comes into play.
It uses the same UDP protocol as StatsD server and exports StatsD-style metrics as Prometheus metrics,
so "hello.requests.total" becomes "hello_requests_total_counter".

Run Everything on Kubernetes

Of course we will deploy everything on Kubernetes.
Minikube will help us here.
Minukube is an easy way to run Kubernetes locally.
When we want to build a Docker image in Minukube (so Kubernetes has an access to it),
we can configure our Docker client to communicate with the Minikube Docker daemon.

$ minikube start
Starting local Kubernetes cluster...Kubectl is now configured to use the cluster.$eval$(minikube docker-env)