Want to find out how much space is being consumed in your datastores, and by what? You can do this from the VMware ESX CLI using the ‘du’ command.
For example, if you have a set of datastores named with the prefix “netapp-” you can display the disk usage for all of the virtual machines in them with:
# du -s /vmfs/volumes/netapp-*/* 26214528 /vmfs/volumes/netapp-linux-1/vm-hr-1.company.com 40952192 /vmfs/volumes/netapp-linux-1/vm-payroll-2.company.com 49340800 /vmfs/volumes/netapp-linux-2/vm-payroll-1.company.com 48292224 /vmfs/volumes/netapp-linux-2/vm-hr-2.company.com 69263744 /vmfs/volumes/netapp-linux-3/vm-wiki.company.com
If you’d like the output with human-readable numbers, try using ‘-h’ with du:
# du -sh /vmfs/volumes/netapp-*/* 26G /vmfs/volumes/netapp-linux-1/vm-hr-1.company.com 40G /vmfs/volumes/netapp-linux-1/vm-payroll-2.company.com 48G /vmfs/volumes/netapp-linux-2/vm-payroll-1.company.com 47G /vmfs/volumes/netapp-linux-2/vm-hr-2.company.com 67G /vmfs/volumes/netapp-linux-3/vm-wiki.company.com
Maybe you’d like to sort by VM name. Use the ‘sort’ command:
# du -s /vmfs/volumes/netapp-*/* | sort -k 5 -t '/' 26214528 /vmfs/volumes/netapp-linux-1/vm-hr-1.company.com 48292224 /vmfs/volumes/netapp-linux-2/vm-hr-2.company.com 40952192 /vmfs/volumes/netapp-linux-1/vm-payroll-2.company.com 49340800 /vmfs/volumes/netapp-linux-2/vm-payroll-1.company.com 69263744 /vmfs/volumes/netapp-linux-3/vm-wiki.company.com
The ‘-t’ parameter changes how sort detects fields, specifically that the field delimiter is a different character than a tab (t). The -k parameter tells it what field to sort on. If you want to sort by space used, use the -n parameter, which tells it to treat the sort fields as numbers:
# du -s /vmfs/volumes/netapp-*/* | sort -n 26214528 /vmfs/volumes/netapp-linux-1/vm-hr-1.company.com 40952192 /vmfs/volumes/netapp-linux-1/vm-payroll-2.company.com 48292224 /vmfs/volumes/netapp-linux-2/vm-hr-2.company.com 49340800 /vmfs/volumes/netapp-linux-2/vm-payroll-1.company.com 69263744 /vmfs/volumes/netapp-linux-3/vm-wiki.company.com
Keep in mind that you’re seeing the disk space used by everything in that folder, including swap files (.vswp), snapshots, etc. Also keep in mind that this is only useful on ESX where you have a command line, so if you are running ESXi, or thinking about it, a PowerCLI or other API-based solution would probably be better. But for quick & dirty information this way is pretty handy.
Update: Dan in the comments does point out that ‘df’ is another utility that will show you your datastore usage. However, my intent was for per-VM breakdowns, and I updated my first sentence to reflect that. Use whatever tool does the job for you!
The `df` command is quicker, gives you information like free space and percentage used, and is available on ESXi (unlike du). The one bad thing is that is gives your datastores with the hex names, but an `ls -l` command can let you link these up.
Sample output from `df -h`:
vmfs3 1.8T 1.6T 230.9G 88% /vmfs/volumes/4a2a8f13-53a74ce0-a36e-0019d19a1ce5
You can then use `ls -l` to gives:
datastore2 -> 4a2a8f13-53a74ce0-a36e-0019d19a1ce5
Oh, definitely. I added an update to the post to indicate my intention wasn’t just raw utilization, though that’s how it came out. Thanks Dan!
There´s no DU utility at ESXi 3.5 ;(
Any1 have solution ?
As ESXi 4.x runs x64 kernel and 3.5 runs x32, i suppose that i could not port the du file from one platform to the other.
Algo looking for ‘last’ command .