Created
October 23, 2012 13:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 '\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