The absolute beginners guide to Grafana


Note: This guide was last updated on 03/04/2018. Originally, this guide was built on a dockerized version of Grafana and Influx. I have since moved away from the dockerized version. Should you still want to use the dockerized version, I will continue to update and maintain the script and it can be found HERE. Moving forward the guide will follow the undockerized version of the script however most pieces should still be the same.


If you’re like me, you want to set up Grafana and have it looking nice and pretty, but you just don’t know where to start and there are too many guides that are not very detailed or just don’t have the right information. I’ve created this guide to attempt to resolve that issue by making this extremely easy and straight forward, as well as by putting as much detail in to the process as I can.


Part One: Installation

This guide was designed for Ubuntu 16.04 Server, your experience may vary depending on your distro.

We will be using the grafana script located on my github: grafana.sh

This script is designed to be extremely straight forward. If we open up the script and break it down, we first check for sudo rights. The script is designed to be run as a sudo user, and thus will error our if its not. The next big chunk of code is defining our “spinner”. This is just used so that there is some motion during more lengthy steps and thus we know nothing is frozen or broken. Once we’ve defined the spinner function, we ask if you want to update and upgrade the system. After that, we simply install the Grafana and influxdb. This version of the script has been extremely simplified since its original version. Trying to cut down on as much human error as possible.

Now that we understand what the script does, we’ll go ahead and let it go.

Note: Should you prefer to go through the process step by step for learning purposes, I’ve added comments to the script to explain it step by step as best I could.

Lets download the script using wget, and the RAW link to the script on github, then we’re going to give it permissions, and finally we’re going to run it.

wget https://raw.githubusercontent.com/tylerhammer/grafana/master/grafana.sh && chmod +x grafana.sh && sudo ./grafana.sh

The script will ask you if you wish to update and upgrade. I recommend you do, however if you’re against it, you can select no.

Once the script has finished, you’ll be able to access Grafana at http://IPADDRESS:3000. Please note, that as of influx v1.3.0[06-21-2017], the AdminUI no longer exists and its not possible to enable it.

If you’re able to access Grafana, Congrats! You’ve officially set up the base for your Grafana server! No need to log into Grafana yet, we’ll cover all of that in Part Three.

To continue and start getting data into Influx and Grafana, take a look at the Data Collection section and see if there is a service you’re looking for, is listed there.

Note: If you have comments or suggestions for anything listed, please feel free reach out to me at contact@cyanlab.io


Part Two: Getting Started

If you’re here, you’ve successfully installed Grafana and InfluxDB. In part two, we’ll take a look at an example script, getting data into InfluxDB, and finally adding it into Grafana. This example script requires ESXi. If you do not have ESXi, you can use one of the other scripts located on my Github and follow along.

Lets jump right into it!

For this example, we’ll be using ESXi. We’ll be grabbing CPU Core performance as well as Memory usage. I’ll go through other scripts step by step in a later section.

I’ve recently updated this process to make it more streamlined. The idea is to make it as easy as possible for new comers to get up and running. Basically, what we’ll do is download a setup script for ESXi and run it. Its going to ask you a series of questions for information it needs to run. Then it will create all the required variables, files and databases you’ll need.
Note: In order for this script to properly work, you will need to enable SSH and SNMP on your ESXi Host.

wget https://raw.githubusercontent.com/tylerhammer/grafana/master/Data%20Collection/ESXi/esxi_setup.sh && chmod +x esxi_setup.sh && ./esxi_setup.sh

You can double check that the script is running smoothly by using

systemctl status esximon.service -l

If you’re getting an error where it’s telling you have a missing value, check THIS article for a solution.


Part Three: Setting Up Grafana

So you’ve made it this far. We completed the pretty easy installation process, and we’ve updated our script, and created our database in Influx. We’re finally ready to start pupping that glorious data into Grafana!

1. So assuming, you’ve not done anything with Grafana yet, we should see this screen:


​​
2. The default login for this installation is Username: admin | Password: admin :



3. By default, you’ll be placed into the “Main Org.” Org. This is fine for most people. Orgs are useful if you’re monitoring multiple locations/companies on the same system. We wont be going into orgs in this guide. Now that we’ve logged in, we’ll want to add a data source so we can access the all the sweet data we are collecting. On the main home page, select “Add data source” :



Note: Here, we’ll want to fill in the information required to connect to our influxdb database. Name is whatever you want it to be referred to. Type, we’ll select InfluxDB since thats the backend we are utilizing. URL needs to be a complete URL, mine looks like “http://10.10.10.249:8086”. For Acccess, either Direct or Proxy will work. Proxy is preferred if you plan to utilize Grafana with a Reverse Proxy. Under Auth we’ll leave everything unchecked. The same goes with Advanced HTTP Settings. Under InfluxDB Details, we’ll enter the name of our Database. For User/Pass unless you set one up, you can leave them blank. Your page should look something similar to mine below, if it does hit “Save & Test” :



4. Once we’ve added the data source, we need to add a new dashboard for us to work on.



5. First thing we want to try and add is our CPU data. When we created the new dashboard it already gave us the ability to select a graph, so we’ll do that now. It will automatically add a Graph with filler data. We’ll want to edit that by clicking on the “Panel Title” section and clicking edit.





6. Now that we have a graph, we need to add your InfluxDB Data to it. At the bottom, where it says “Data Source”, we want to select the data source we just added. For me, that’s “ExampleDB”.



7. Now we need to select our parameters and get data displayed. There are two ways to enter queries, manually by text, or through the guided method. We’ll just the guided method. Click on the A to drop down the options panel. This is how we’ll add a majority of our data. For this example, we’ll do the following: Click “Select Measurement” and choose “esxi_stats” . After “WHERE” click the + icon and click cpu_number. Then we’ll click “Select Tag Value” and choose “1” . This will select the first core thats being monitored. Next, we’ll change the “fill” in the “GROUP BY” row from null to none. The last thing needed for this panel is “Alias By”. I prefer to use this to label my cores “Core 1” etc etc.



Lets use this time to add a couple of more cores so we get some real data. The easiest way to do this is by clicking the menu button, and selecting duplicate. Once you’ve duplicated the row, update the Core number and the Alias. We should now have something like this : \



8. Now that we have a good chunk of data, lets make sure its displayed correctly. Because we are looking at CPU Usage %, we need to update our graph. So lets select “Axes” tab. We need to update the “Left Y Unit” to be “Percentage 0-100”, we then need to changed the “Y-Min” to 0, and the “Y-Max” to 100. This will ensure our graph stays at 0-100% at all times (See below screenshot).



We’ve officially added data into Grafana! The rest is up to you to play with on how you like things displayed, and what other data you want displayed. Step by step guides for the rest of the scripts on my Repo will be posted as soon as I get a chance!

Should you need any help, please feel free to reach out to me through the following methods, though do keep in mind, I may not respond immediately. Reddit: /u/tyler_hammer | /r/homelab Discord: Hammer#4341 | Email: contact@cyanlab.io

Useful Information for the Dockerized Version


To access InfluxDB via the CLI

docker exec -ti influxdb /usr/bin/influx


To install a plugin into Grafana (Plugins can be found here: https://grafana.net/plugins

grafana-cli plugins install