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 | apt-key add -
# source /etc/lsb-release
# echo "deb${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | tee /etc/apt/sources.list.d/influxdb.list
# apt-get update
# apt-get install influxdb
# cd /etc/influxdb/
# wget
# mkdir /usr/share/collectd
# cd /usr/share/collectd/
# wget
# 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
# 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 jessie main" | tee /etc/apt/sources.list.d/grafana.list
# curl | 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 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 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$__auto_interval
Figure 9: Grafana shows metrics to collectd01.


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.


  1. Libvirt:
  2. Official InfluxDB website:
  3. Collectd:
  4. Grafana:
  5. Grafana dashboard for the virtual lab:

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

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