Sending Phoenix 1.5 metrics to InfluxDb

Part 1: Adding custom metrics to a Phoenix 1.5 live dashboard

The code for this demo is available here

As I mentioned in the previous post, one of the downsides to the new Phoenix live dashboard is that the metrics and graphs are transient. In order to see longer term trends, we’re going to send our telemetry metrics to InfluxDB via StatsD.

Add the statsd reporter to your Phoenix app

Open lib/metrics_demo_web/telemetry.ex and add the following line to the deps:

It should now look like this:

Open lib/metrics_demo_web/telemetry.ex and add the following line to the children array:

It should look like this now:

Install and configure Telegraf

We’re going to opt for sending metrics to the cloud based InfluxDB rather than trying to get it running locally. Head on over to https://cloud2.influxdata.com/signup and create a free account.

You’ll land on a getting started page. From here, click on the Data page:

First thing you’re going to do is generate a new token if you don’t have one. We’ll give our token read/write access to our default bucket:

Click on the created token and copy it to your clipboard:

Next head over to the Telegraf tab and click “InfluxDB Output Plugin” and copy this section to your clipboard:

Next you’ve got two options.

Use this to generate a sample config and paste the section above into it, overwriting the [[outputs.influxdb]] part of the Output Plugins section:

Grab this significantly slimmed down config and set the following environment variables (or replace those values in the config):

Now start Telegraf with the updated config:

Click around your app and you should start seeing metrics coming in. To see them, we’ll head over to the Explore page, select some “measurements” and click Submit:

If you’d like to see the diff with all of these changes in one place, click here.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store