Instrumenting Your System

Learn how to instrument your system and practice one significant tool: Observer.

Many different applications can show you what’s going on given that they’re fed the right data. Although we can’t recommend which tool to use, we can try to give an overview of the data that can be gathered. In short, instead of discovering how to view the different performance views of the system, we’d like to focus on what to measure. We’ll illustrate what useful data can be coaxed out of the VM and how to use it to inform decisions. Let’s get started.

Using Observer as a guide

Because Elixir chose to build onto the Erlang ecosystem early on, we can take advantage of many tools. One of those is Observer—a tool for understanding how applications are using resources like processes and memory. We won’t use Observer to gather metrics in production, but it’s a great tool to explore what the VM offers. If the information is available to Observer, it is available to us as well.

In this section, we will create a new Phoenix application and we’ll use it through the rest of the chapter. We will start by observing this application and translating ideas we find into code.

We chose a Phoenix application because it comes with enough code for us to jump straight into measuring. In any case, the lessons here apply to any Elixir application.

If you are not yet familiar with Phoenix, see their website to get started. Once you have installed the Phoenix installer on your machine, create a new application like this:

Press + to interact
mix phx.new demo

Don’t worry, we have already created one for you below.

Follow the instructions printed out to get the application up and running with:

Press + to interact
iex -S mix

When the iex prompt becomes available, type the following:

Press + to interact
:observer.start()

That command will start Observer in all its glory.

Check it out! Please follow the steps written below to run the program.

# Please press the 'Run' button given below and follow the steps
Running the observer
...