Skip to content

Query Disk and Memory Usage on all vSphere hosts

This one leverages the VMWare APIs and queries all your hosts. You’ll need the VMWare Perl APIs installed on the system. It outputs to a web page so you can crontab it to run once a day and then just check the website when you need to see what memory or disk space is available on each host.

For accurate memory usage, modify /usr/lib/vmware-viperl/apps/host/ with however much memory you have installed. For example, if you have 6GB of memory then it would look like:

if (defined ($host_view->summary->quickStats->overallMemoryUsage)){
print_log(” “.(6000 – $host_view->summary->quickStats->overallMemoryUsage).” MB”,
“MemoryUsage”,”\tMemory Available”);
I’ve also modified so it would come out a little better
Examples are available here:
Once you’ve modified that perl file, your ready for the good stuff. Make sure each host’s datastore has a unique name too.
dm605_stores=(dm605-01:storage1 dm605-02:storage1 dm605-03:storage1 dm605-04:storage1 dm605-05:storage1 dm605-06:storage1 dm605-07:storage1 dm605-08:storage1 dm605-09:storage1 dm605-10:storage1)
for (( c=0; c<10; c++ ))
perl /usr/lib/vmware-viperl/apps/host/ –url –username info –password info
–attributes freespace –name ${dm605_stores[$c]} >> $DEST_FILE
perl /usr/lib/vmware-viperl/apps/host/ –url –username info –password info –hostname ${dm605_hostnames[$c]} –fields memoryusage >> $DEST_FILE
echo ” ” >> /var/www/
date >> /var/www/

Post a Comment

You must be logged in to post a comment.