Collectd for VM monitoring

Posted by Amol Dighe on November 22, 2017

Here’s an intresting use case - There is a need check the usage of customer VM’s without installing an agent on their VM.

Solution - Use collectd with libvirt plugin enabled on your KVM host.

I have tried this solution on my Ubuntu laptop which is running 2 KVM-VMs

root@hp-envy:~# virsh list --all
 Id    Name                           State
 1     ubuntu14                       running
 2     ubuntu14-new                   running
  • Install collectd on KVM server
apt-get install collectd
  • Collectd has several plugins available and enabled in
  • Configure collectd to load libvirt, better know as - virt plugin by creating this config file
root@hp-envy:~# cat /etc/collectd/collectd.conf.d/libvirt.conf 
<LoadPlugin virt>
 Globals false

 <Plugin "virt">
  Connection "qemu:///system"
  RefreshInterval 60
  Domain "dom0"
  BlockDevice "name:device"
  InterfaceDevice "name:interface"
  IgnoreSelected true
  HostnameFormat "name"

We will be adding a new config file to /etc/collectd/collectd.conf.d/ which will be included as per this directive in /etc/collectd/collectd.conf

<Include "/etc/collectd/collectd.conf.d">
        Filter "*.conf"
  • Restart collectd to enable virt plugin
service collectd restart
  • Now to view the metrics collected by collectd-virt plugin, we will be setting up collectd-web, using the below process:
cd /usr/local/

git clone

cd collectd-web/

chmod +x cgi-bin/graphdefs.cgi

The python script at /usr/local/collectd-web/ is configured to run on localhost IP

root@hp-envy:/usr/local/collectd-web# ./ 
Collectd-web server running at

To configure it to run on all interface acttached to KVM host, replace to, and start the python server

root@hp-envy:/usr/local/collectd-web# ./ &
[1] 3592
root@hp-envy:/usr/local/collectd-web# Collectd-web server running at

I have my local wifi router DHCP assigned the IP -

root@hp-envy:~# ip a | grep wlo1 
3: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    inet brd scope global dynamic wlo1

Now I can hit the IP in my local browser to bring up the collectd web UI

  • Reference Links