Skip to content

Instantly share code, notes, and snippets.

@k4rtik
Created October 23, 2012 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4rtik/3938620 to your computer and use it in GitHub Desktop.
Save k4rtik/3938620 to your computer and use it in GitHub Desktop.
Simple utility to display stats of all active (running) KVM virtual machines, wrote for Fedora 17 platform for IBM Virtual Tux contest.
#!/usr/bin/env python
import os
import sys
import commands
status, domains = commands.getstatusoutput("virsh list | grep running | cut -f7 -d' '")
domains = domains.rsplit('\n')
for domain in domains:
print '\nDomain: ' + domain
print '\tCPU:'
comm = "virsh cpu-stats " + domain + " | tail -n 4 | grep cpu_time | cut -f2"
os.system(comm)
print
print '\tMem:'
comm = "virsh dommemstat " + domain
os.system(comm)
print '\tDisk:'
status, disks = commands.getstatusoutput("virsh domblklist " + domain + "| grep d | cut -f1 -d' '")
disks = disks.rsplit('\n')
for disk in disks:
print '\t\t' + disk
comm = "virsh domblkstat " + domain + ' '+ disk + " | grep bytes | cut -f2,3 -d ' '"
os.system(comm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment