Monitoring Phoenix

Edited July 11, 2015

Updated the plug gist (fixed typo) and repo gist (adjusted to the latest ecto version).


As lots of engineers in the Elixir community I have a ruby background. Rails used to be my go-to MVC framework.

Custom monitoring for Phoenix

Thankfully I found the ideal replacement for the SaaS tools I was using with rails. The powerful combination of Exometer, StatsD and DataDog. Let me explain each part of the system.


Last December I was in Berlin for Erlang Factory 2014. I was lucky enough to attend a talk by Brian Troutwine from AdRoll. It convinced me that Exometer would be the perfect library to do this. You can find his talk here:


StatsD is an agent that receives metric values using UDP and forwards them to other services. It is comparable to an intermediary. The metrics have to be formatted in a way that makes sense to StatsD. It also does aggregation, too.


DataDog is a SaaS that enables you to send it stats and events and displays these in highly customisable graphs. You can create dashboards with graphs and gauges. Finally you can define events for which you can receive alerts. E.g. when your server’s CPU load gets too high, you perform too many DB queries per second and so on.


Now that we know the ingredients, let us use them to get insights into your Phoenix app. First add the dependencies to your mix.exs. I used PSPDFKit’s forks as they work better with mix:

Defining the metrics and reports

We use an application config to configure Exometer. It defines the metrics we want to record and where we would like to report it. This is by far the hardest part. Let me show you a gist and then walk you through it:

Recording metrics

Now as you can see we poll the Erlang VM metrics in our config. That’s super helpful. But we still need to record metrics like hit count and response time. If you’re using Ecto you might also want to record query count and execution times. Let’s start with hit counts and response times. I wrote a plug that does it:

Using your metrics

There are many ways of using your metrics, the most common one is to visualise them. There are a variety of ways to do this. Since we are using StatsD and Exometer we can export our metrics to a variety of formats. One of the formats is for most popular graphing solution graphite.


Currently I am only collecting the average response time. It might be interesting to record response times per method and path to identify worst offenders. Thanks to Exometer’s dynamic metric definition interface that is not a problem. I just haven’t gotten around to doing it. The same goes for Ecto: Recording which queries take the longest might be a smart thing to do however I haven’t gotten around to it yet.

    Michael Schaefermeyer

    Written by

    VP of Venture Development at lab25. Passionate about engineering — especially Elixir. Start-up history in SF, NYC, London and now Münster, Germany.

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade