Build a Homelab Dashboard: Part 6, Grafana Introduction

Categories:Hyperion Home Lab
Brian Marshall

Another week, another part of the homelab dashboard series!  This week we will finally bring all of our work into Grafana so that we can see some pretty pictures.  Before we dive in, let’s take a look at the series so far:

  1. An Introduction
  2. Organizr
  3. Organizr Continued
  4. InfluxDB
  5. Telegraf Introduction
  6. Grafana Introduction

What is Grafana?

Grafana is the final piece of our TIG stack.  This is the part you’ve been waiting for, as it provides the actual results of our labors in the form of beautiful dashboards.  Like Telegraf and InfluxDB, Grafana is also open source, which makes it even more awesome.   Grafana really does two things, first it build (or allows you to build) a query back to a data source.  In our case, this means building an InfluxQL query.  Once the query has been prepared, Grafana then gives you the ability to make it look nice…very nice.  Let’s get started!

Installing Grafana on Linux

Installation, like everything else we’ve installed so far in this series is pretty straight forward.  We’ll start by downloading and installing Grafana using these commands:

sudo wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.2.2_amd64.deb 
sudo dpkg -i grafana_5.2.2_amd64.deb

Executing those commands should look something like this:

Now we need to start the service:

sudo service grafana-server start

Finally we need to make sure the service starts automatically at boot each time:

sudo systemctl enable grafana-server.service

Installation complete…now let’s do some configuration.

Configuring Grafana

We’ll start by opening our browser and going to http://youripaddressorhostname:3000/:

The default username and password for the administrator account will be admin.  Once logged in, we will be prompted to change our password.  I highly recommend that you do not click the skip button:

Once you are logged in, we’ll see that we’ve only completed the first step in the five that they have listed:

  • Install Grafana
  • Add data source
  • Create your dashboard
  • Invite your team
  • Install apps & plugins

We’ll focus on the first three as its assumed that this is a homelab where you don’t have a lot of users and for now won’t need any apps or plugins.  Now we can move on to the next step.

Adding a Data Source

Now that we have Telegraf feeding stats to InfluxDB, we can start with that database as our source.  Start by clicking on Add data source:

Enter a name for the data source, choose InfluxDB for the type, enter the URL (I used localhost as I have it all on the same system), enter the name of the database, enter the username and password used to access the database.  Finally, click Save & Test:

Assuming everything went well, you should see the following:

Creating a Dashboard

Finally…after six parts of this series, we are to a point where we get to see a pretty picture.  The moment we have all been waiting for!  While I could just upload my JSON file for this dashboard, I learn much better if I actually go through and build it myself.  So we’ll go that route.  If we go back to our home dashboard, we can click on the next box:

Simple Line Graph

We’ll start with something simple, so we’ll click on Graph:

This will give you a nice looking random sample data graph:

While this is cool looking, it wasn’t exactly intuitive that you click on the panel title to get editing options:

Once you’ve clicked edit, you should have a full screen of editing options.  We’ll start by changing the data source to our newly created data source, TelegrafStats in my case:

Now we need to pick a table to pull data from.  We’ll start with something that seems simple like CPU statistics from the cpu table:

Next we’ll add host to our where clause so that we don’t try to aggregate multiples as we add in future devices:

And now we need to specify the host we wish to filter on:

Finally, we can select a field.  In some cases, this will a single value of interest.  As we look at CPU options, we’ll notice that there are quite a few to select from.  This will vary based on the operating system that we are using, but in my case (Debian Stretch), I have a lot of choices.  We’ll start by picking a single item from the list:

Before we get into the rest of our CPU options, let’s give our series a name:

Given that we have all of these choices, we really need all of them on the graph to adequately illustrate CPU utilization.  To make this a faster process, we’ll simply duplicate our first entry.  We’ll click the menu button on the query and select Duplicate:

We’ll do this for every field available so that we can represent all of the possible ways our CPU will be utilized.  Now that we’ve added all of our data, its time to make things look a little more polished.  We’ll start with our legend.  Click on the Legend tab:

I prefer to see more information on my legend.  Grafana gives us a great selection of options.  I’ve chosen to display my legend as a table with min, max, avg, and current values:

Next we’ll click on our General tab so that we can adjust our title:

The only thing left to do now is to adjust a few settings about our axes.  From the Axes tab, we’ll select the unit of none followed by the unit of percent (0-100):

Now that we have it set to percent, we’ll also want to set the range from 0 to 100 as our usage should never exceed 100:

Next we need to click back and actually save our work.  Up until this point, nothing we have done has been saved.  Once we have clicked the back button in the top right corner, we should see our completed panel and we’re ready to click the save button:

Now we just need to enter a name for the new dashboard and click Save:

We have officially created our first dashboard in Grafana!  But wait, that will be a pretty boring dashboard.  Let’s add some memory and disk metrics next.  To do this, we’ll use a different type of visualization.

Singlestat (Gauge)

Everyone loves pretty gauges, so let’s add one or two of those to our dashboard.  To create a gauge we add a new panel:

The Singlestat panel can be modified the same way as our graph:

Now we modify our query just like we did with a graph and then we’ll go to the options tab:

We’re going to first change our stat.  Essentially we want to change it from the default of Average to the setting of Current.  This ensures that our gauge will always show the most recent value rather than an average of the time period selected.  We also need to change our thresholds, I chose 70 and 90 for my orange and red.  We’ll also set our gauge to Show and set our units to percent.  If your colors are reversed, just click the Invert button:

Once we have our gauge configured, we just need to name our panel:

One More SingleStat

I won’t go step by step, but here are the settings I used for the disk space gauge:

The Dashboard

Finally, we have a dashboard.  I moved things around a bit and ended up with this:

Putting It All Together

Now that we have a dashboard, we should be ready to put it all together.  This means all the way back to Organizr.  Before we head over there, we need to copy a link.  Click on the share button:

Next we will deselect Current time range and Template variables.  Finally we’ll copy the link:

We’ll head back over the Organizr and go to our Tab Editor and click the add new tab button:

Now we just need to name our tab, paste our URL, and choose the Grafana logo:

And once we reload Organizr, here we go:

Conclusion

If you have followed the entire series so far, you should have a fully functionally dashboard inside of Organizr.  Soup to nuts as promised.  We’ll continue the series by adding in more and more devices and data into InfluxDB and Grafana…another day.

Author:

Leave a Reply

Name*
Email*
Url
Your message*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.