Set up your own lab environment with KVM, Qemu, and Libvirt

Setting up the Systems

When you get the VMs up and running, the next step is to install the applications that will run on three virtual systems: InfluxDB [2], collectd, and Grafana.

The InfluxDB packages are not part of the official Ubuntu repositories; however, a third-party repository contains everything we need. Execute the commands in Listing 9 as root on the influx01 VM.

Listing 9

Installing InfluxDB

# curl -sL https://repos.influxdata.com/influxdb.key | apt-key add -
# source /etc/lsb-release
# echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | tee /etc/apt/sources.list.d/influxdb.list
# apt-get update
# apt-get install influxdb
# cd /etc/influxdb/
# wget http://hoebel.net/downloads/articles/influxdb.conf
# mkdir /usr/share/collectd
# cd /usr/share/collectd/
# wget https://raw.githubusercontent.com/collectd/collectd/master/src/types.db
# systemctl restart influxdb

Now check if the InfluxDB application is running:

ps aux |grep influx

The next step is to log into the collectd01 system and set up the collectd daemon [3]. Collectd collects metrics of the local system and sends them to InfluxDB for permanent storage. Listing 10 shows the steps for installing the manic collectd collecting service on the collectd01 test system. Check to see if the daemon is actually running:

ps aux | grep collectd

If it isn't running, stop all collectd processes and relaunch the service.

Listing 10

Installing Collectd

# apt-get update
# apt-get install collectd collectd-utils
# cd /etc/collectd/
# wget http://hoebel.net/downloads/articles/collectd.conf
# systemctl restart collectd

After a few minutes of run time, the time-series database fills InfluxDB with metrics from the collectd01 test system. Check the status by running the influx command on the InfluxDB VM and listing all databases with show databases.

Use use collectd and show measurements to show which value categories ended up in the database. The quit command takes you back to the command line.

The virtual laboratory now collects metrics from one of the test systems and stores them in a database on another VM via the virtual network. The last step is to add visualization using Grafana [4].

Open a command line on the grafana01 test system and install Grafana (Listing 11). Line 1 sets up a software repository for Debian systems. (The system is Ubuntu, but Grafana developers have deliberately kept their package repository simple and have taken advantage of the fact that the package management works in the same way under Ubuntu and Debian.)

Listing 11

Installing Grafana

# echo "deb https://packagecloud.io/grafana/stable/debian jessie main" | tee /etc/apt/sources.list.d/grafana.list
# curl https://packagecloud.io/gpg.key | sudo apt-key add -
# apt-get update
# apt-get install grafana
# systemctl start grafana-server

After you launch Grafana, the service listens on port 3000. Open the http://172.100.100.31:3000 URL in a web browser, and you'll see a welcome to the login screen. Sign up as admin with the password admin and click on the Add data source link. In the Name field, enter the InfluxDB value and select the same value in the Type drop-down menu.

For URL, enter the http://172.100.100.21:8086 character string – Grafana will later reach InfluxDB under this address. Skip the configuration fields for Http Auth and, under InfluxDB Details, enter the name collectd in the Database field. Now press the green Add button and then Save & Test. Figure 8 shows the complete configuration.

Figure 8: Configuration for Grafana data source.

You'll find a Grafana dashboard prepared for this configuration at my website [5]. Download the configuration file and click on the Grafana icon in the top left in Grafana. The icon opens a menubar where you select Dashboards | Import. In the next dialog, install the recently downloaded JSON file using the Upload .json File button. Don't forget to select the correct data source InfluxDB before clicking Import.

Next, Grafana guides you to the recently imported dashboard. Enter the collectd01 value under Host in the top left, or simply go to the link shown in Listing 12. Figure 9 shows the visualized data. The prefabricated dashboard displays all sorts of processed metrics for the collectd01 test system.

Listing 12

Point Grafana to the Data

http://172.100.100.31:3000/dashboard/db/server-operating-system-metrics?refresh=1m&orgId=1&var-host=collectd01&var-interval=$__auto_interval
Figure 9: Grafana shows metrics to collectd01.

Conclusions

Creating a virtual test lab on your home computer requires less work than you might expect. Pay attention, take your time, and remain patient; you will very soon discover that the techniques described in this article will let you quickly configure and model complex test scenarios.

Infos

  1. Libvirt: https://libvirt.org/
  2. Official InfluxDB website: https://www.influxdata.com
  3. Collectd: https://collectd.org
  4. Grafana: https://grafana.com
  5. Grafana dashboard for the virtual lab: http://hoebel.net/downloads/articles/LinuxUser-Grafana-Dashboard.json

The Author

Valentin Höbel works as a Senior IT Consultant for the IT service provider open*i GmbH in Stuttgart, Germany. In his spare time, when he is not standing at the foosball table, he is looking at current open source technologies or tweeting under the http://@xenuser account.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Monitoring Beehives

    Beekeepers can get to know their colonies better without continuously disturbing the industrious insects. Using a Raspberry Pi and various sensors, two hobby beekeepers monitor the temperature and humidity of their hives, with plans to monitor their weight.

  • Tutorials – Collectd

    The collectd tool harvests your system stats and stores them for plotting into colorful graphs.

  • Tool Tips

    Tool review: Dialog 0.7, virtenv 0.8.6, collectd 5.4.0, convmv 1.15, Drukkar 1.11, and ngIRCd 20.3.

  • Skydive

    If you don't speak fluent Ethernet, it sometimes helps to get a graphical view of what your network is doing. Skydive offers visual insights that could reveal complex error patterns.

  • Performance Tools

    We describe five tools you can use to monitor and troubleshoot your system's performance.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News