Thoughts from your friendly neighborhood technologist.

Tag: influxdb

What’s all this about?

Having a home lab is great as I’m sure most of you are aware. But when you want to start running things that are more or less “production”, often we have the need to start tracking historical data. During my quest to begin graphing statistics associated with my homelab I started my journey first by looking at some of the more popular options for infrastructure visualization by exploring options like the 100 monitor license for PRTG, and LibreNMS.

While these would work in a majority of lab scenarios, I operate a few things that required a custom graphing and data collection solution.

You see I run a few community game-servers, mumble server, share a plex system with friends and family, and also all of the automation components that go along with it (CouchPotato, Sonarr, NZBGet, qBittorrent). While PRTG and LibreNMS are great for SNMP polling and logging, the type of systems I’m looking to monitor don’t have SNMP on them, thus it was time to explore other options.

For reference, here’s a look at what I’m running for my always on services.

Enough Hardware, what about the Software!?

Now that we’ve got the hardware out of the way, what about the software? Well originally I had planned on using Graphite, which includes Carbon, Whisper and the Web Frontend. However, it’s a fairly long pain in the ass process to setup so I opted for an alternative running Grafana and InfluxDB.

Unlike a traditional relational database, InfluxDB is a TSDB or Time Series Database. In our example here we’re using InfluxDB to store 3 things, the Measurement Name, the Measurement Value, and the Time which that measurement happened. Let’s have a look at an example.

homelab.servers.nanoserver.cpu.0.processortime, 8, 1454794445

Simple right? The first value is that of our Measurement Name, which can be anything we want. There’s no need to prepopulate the database with these measurement names, as anything fed into InfluxDB with the correct structure will create the measurement name and associate a measurement with it. Bitchin’ I know! The second value is the actual measurement itself, in this case 8% utilization of CPU core 0. The third and final value is the time this measurement was taken in UNIX time.

Once we’ve got data in an InfluxDB, we need a way to easily digest it. This is where Grafana comes in. Luckally Grafana (as of 2.1.0) has support for InfluxDB 0.8 and InfluxDB 0.9 out of the box. Note: There are two profiles because the query language changed between InfluxDB 0.8 and 0.9.

Now that we’ve gotten the what out of the way, it’s time to dive into the how. Or put more simply, how are we going to actually measure datapoints and get them into InfluxDB for Grafana to ya know, graph?

In my case my “Nanoserver” is running Windows 7 on the bare metal, and a few virtual machines under VMware Workstation 12. One of those machines is my general purpose Ubuntu 14 box that I run utilities on which don’t have native Windows support. This is where we’ll be installing InfluxDB, Grafana, an NMP stack (Nginx, MariaDB, Php). Now I mentioned previously that the Nanoserver is running Windows which I certainly want to retrieve and report performance statistics from, but I couldn’t find a script that would easily allow me to get performance data out of Windows and into InfluxDB. However I did find Matt Hodge’s excellent powershell script for getting performance data from windows and inserting it into Graphite. “BUT MATT! I thought you said we were working with InfluxDB?!” And you’re right, it turns out one of the great things about InfluxDB is that it has a Carbon Protocol Listener that while disabled by default, is easily activated with a config change, and allows us to receive data originally meant for a Graphite, Carbon, Whisper stack!

Alright I get it, InfluxDB and Grafana are awesome, but how do we set them up?

Ok ok. I promised you that this would be a how to and if you’ve made it this far, it’s time to actually show you how we’re going to accomplish this stuff. Ready? Here we go.

First we’ll start with the fact that this tutorial is based on the notion that we’re installing these components on Ubuntu 14, so that’s our first prerequisite.

Head to a web browser and enter the IP of your InfluxDB Server followed by port 8083 (http://INFLUXDB_IP:8083), then in the query textbox enter the following command.

1

CREATE USER'graphite'WITH PASSWORD'graphite'WITH ALL PRIVILEGES

Now we need to edit the InfluxDB config file to enable user authentication.

1

sudo nano/etc/influxdb/influxdb.conf

First we’ll enable authentication for InfluxDB by setting “auth-enabled = true” under [http] from it’s default of false.
Now let’s enable the Graphite protocol listener by setting “enabled = true” under the [[graphite]] config section from it’s default of false.

Note : InfluxDB by default does not require user authentication and is happy to allow anyone to just write measurement data to it, however the Grafana Data Source interface requires user credentials, so that’s why we enabled basic user authentication for the Graphite database.

Time to add the InfluxDB Data Source

Click on the Data Sources link on the left menu, and then select add new from the top menu.
Give your Data Source a name, in this case we’re going with InfluxDB Graphite
Select InfluxDB 0.9.x (even if version 0.10.x was installed) as your Data Source Type, and optionally select the Default checkbox to have this Data Source selected each time you want to add a new panel.
In the Http settings section enter your InfluxDB IP address followed by port 8086, (In this case because InfluxDB and Grafana are located on the same server go ahead and enter http://localhost:8086), your access mode should be proxy.
Now in the InfluxDB Details section we’ll enter our database (graphite) followed by our username and password (graphite / graphite)
Click Add and then click Test Connection, you should get a green box with “Success: Data source is working”

That’s it! Simple right?

You deserve a medal if you’ve made it this far, but in the next post we’ll actually show you how to get data into InfluxDB from various different sources, and then the all important step of actually graphing it! So stay tuned!