...

/

Collect Measurements using StatsD

Collect Measurements using StatsD

Learn how to use different tools to collect measurements.

StatsD

We can use a number of different tools to take measurements in our code. A commonly used tool is StatsD, and that’s what we’ll use throughout this course. StatsD is a daemon that aggregates statistics. It takes measurements sent by our application and aggregates them into other back-ends that collect the stats. Many APMs provide a StatsD back-end integration; this makes StatsD a great choice for collecting measurements.

There are other tools we can use to collect measurements. StatsD is commonly used and easy to understand. If we prefer a different tool, then we should use that. The important thing is that we are collecting measurements.

It is easy to get started with StatsD in Elixir by using the Statix library. This library has a simple interface with functions that correspond to StatsD measurement types. We’ll use Statix in this course to capture measurements in our application.

Let’s capture various measurements in our HelloSockets application by using Statix and a local StatsD server. We’ll use a fake StatsD server for development that simply logs any packets to the Elixir application console.

Let’s start by adding Statix and a fake StatsD logger to our application.

Press + to interact
# hello_sockets/mix.exs
{:statix, "~> 1.2"},
{:statsd_logger, "~> 1.1", only: [:dev, :test]},

Run mix deps.get to fetch these dependencies. We must configure Statix to work in our application.

Press + to interact
# hello_sockets/config/dev.exs
config :statsd_logger, port: 8126
config :statix, HelloSockets.Statix, port: 8126

We’re using the non-standard StatsD port of 8126 for our development. This will help ensure that our StatsD ...