Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to monitor/limit bandwidth for KVM guests? I'd like to give people VMs on my server but I want to be careful not to go over my monthly bandwidth limit. The only places I can find that support this are 'cloud' frameworks, I'm guessing I'm either missing something simple in Linux, or I need to talk to a router above me (which I don't have access to).

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I recommend using libvirt for managing your KVM virtual machines. It makes the whole thing much easier than with just plain QEMU/KVM and provides also nice CPU, IO and network statistics. You will like tools such as virt-top and virt-manager which work on top of the libvirt framework.

To collect the virtual machine interface statistics from a script, you could use virsh command line interface to libvirt or some of the language APIs. The format of the virsh command is as follows:

virsh domifstat VMNAME IFNAME

..where VMNAME is the name of your virtual machine and IFNAME is the name of a (virtual) network interface. To find out a name of a network interface you can do:

virsh dumpxml VMNAME

In the resulting XML output, look for your network interface definition(s). Look for a line such as follows:

<target dev='vnet0'/>

In this case your IFNAME would be "vnet0".

Alternatively you could use a statistics collection daemon, such as collectd which has support for monitoring libvirt statistics, but a simple shell script which some times stores the output of "virsh domifstat" is maybe enough in this case.

share|improve this answer
    
I do use libvirt. Where do I find network statistics? I'm not installing virt-manager, it wants to install Gnome. –  Andrew Koester Aug 2 '11 at 16:32
1  
I edited the answer to include further practical information for retrieving libvirt interface statistics with virsh command line tool. Also note that you do not need to install virt-manager on the VM host. You can install it in your workstation and instruct it to connect to a remote VM host (or several). Thus no need for Gnome/X11 libraries on the VM host. –  snap Aug 2 '11 at 16:59
    
Thanks for posting this. Given the general lack of information like this on the net (or just the difficulty finding it), you'd think that 99% of the people using KVM don't have customers. :-P –  deltaray Sep 4 '12 at 3:47
    
That is a strange distro that requires gnome for virt-manager. Debian just wants gconf2 - the rest seem like Python libraries. –  Nathan Adams Jun 14 at 3:43
    
I found it useful to use a modified command from this answer to find the interface. virsh dumpxml VMNAME | grep "target dev" –  Programster Oct 3 at 15:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.