VMware {code} Community
Jeff_39
Contributor
Contributor
Jump to solution

Total VMDK space per VM

Hello guys!

I would like to know if anyone knows a way to get the total VMDK space per VM in Virtual Center. We have 40 Datastore with 200 VM and we have to find wich are the bigger to plan our backup schedule with Netbacup/VCB. But if we can get the size of each folder containing a VM, it woud be just fine also. Do you think a script could do the job?

Thanx a lot!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

Now that is just me being stupid. Sorry I don't have a VM environment to run the script against to catch some of the runtime errors. Thanks for bearing with me.

I spelled guest as 'quest'. Smiley Sad

Fixed and updated.

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

0 Kudos
16 Replies
njain
Expert
Expert
Jump to solution

You can use the "config.hardware.device" property of the Virtual Machine to figure out the hard disk from the available devices. You can then drill down to "deviceInfo.summary" property to get the virtual machine disk size. Please note that this will give the size of the individual vmdk only. In case of multiple hard disks, you will have to sum up the values to get the total size for the VM. This will be the total space allocated to the virtual machine.

stumpr
Virtuoso
Virtuoso
Jump to solution

I wrote a script that did primarily though. IF the VMware Tools were installed and running it would sum the total VMDK capacity (assigned) and used. I'll attach my code. Looking at it, it's another script created on the fly, so don't kill the messenger for grammar. Smiley Happy It looks like I print it out in a CSV form, so you could just copy and paste it into a file and import it into an Excel sheet.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

Hello again!

I got the following message when I try to run the script :

Global symbol "$total_free" requires explicit package name at C:\ListVMDisks.pl

line 44.

Global symbol "$total_free" requires explicit package name at C:\ListVMDisks.pl

line 49.

Global symbol "$total_free" requires explicit package name at C:\ListVMDisks.pl

line 53.

Global symbol "$total_free" requires explicit package name at C:\ListVMDisks.pl

line 55.

Missing right curly or square bracket at C:\ListVMDisks.pl line 92, at end of line

syntax error at C:\ListVMDisks.pl line 92, at EOF

Execution of C:\ListVMDisks.pl aborted due to compilation errors.

Since i'm horrible at scripting, can you take a look at it?

Thanx a lot!

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

No problem. Like I said definitely hacked out script to answer some quick question.

Try this updated version. I don't have a current VMware environment to test it on (actually working on a Xen project currently), but feel free to shoot back any errors, I'll be happy to fix it. Sorry for the less than ideal script, hopefully it helps.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

Look like you fixed some error but this time, I have a connection error. I have ESX 3.02 avec VC 2.02 but the account I can provide only have read-only access and browse Datastore rights, do you think it's enought?

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

It might not be enough. Was it a connection error or permission error...usually the error output gives a pretty good clue.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

It was a connection error. That's because the administrator change the default port for VC. It's ok now but here's what I have now :

#vm, diskpath, capacity, free, disk count

Can't call method "capacity" on unblessed reference at C:\ListVMDisks.pl line 54

, <STDIN> line 1.

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

I must have corrected all this on site last time I ran it and not copied it back to my laptop, couple big errors. Sorry for the back and forth.

Try this updated copy, I don't think I had the disk array being cast properly.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

No problem, you work a lot for this script to work ;o) Here's what happen when I run the last upadated script:

#vm, capacity, free, disk count

VirtualMachine=HASH(0x30f60b8),103860376576.000000,97417047040.000000,7

VirtualMachine=HASH(0x276d370),146030718976.000000,72421605376.000000,4

VirtualMachine=HASH(0x274e29c),108161191936.000000,98826047488.000000,6

Can't use an undefined value as an ARRAY reference at C:\ListVMDisks.pl line 51,

<STDIN> line 1.

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

No worries. I actually remember hitting these bugs. Essentially I wrote this, copied it to a customer location, fixed it, then didn't copy it back. I'm updating my original since I keep using this script. Seems like a common question on a lot of jobs.

The first error was not calling the VM name, but the HASH reference. I sometimes may the name into a variable, I didn't do that this time. Fixed that for the output.

The second error (the one that bombs out) occurs when you encounter a VM with no disks attached. If it hits a guest disk array that's not defined, it'll just assume there are no disks and print 2 values for cap, used, and disk count.

These changes SHOULD resolve all the issues. Just trying to remember if there were any other conditions you have to test for that would drop the script out of its run.

I really should sit down and do a really robust disk measurement script. I have a couple others with the Datastores, etc. Should mesh them into one solid tool with a good output. Just on a Xen project now so haven't been very focused on VMware.

Feel free to keep posting errors, we should get it working soon Smiley Wink.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

Thanx a lot for the good work! The thing is that I try to figure out wich VM are the bigger in our environnement because we want to configure policies in Netbackup with a VCB Backup Proxy Server and find out how many temporary disk space we need to acheive this. And in the mean time, it will greatly help to know how much data we have to backup and try to fit all the VM in our backup window. And I forgot to mention that some VM also have RDM attach to them and they are supposed to be in virtual mode compatibility.

So,i'll go give a road test to your script and keep you updated!

0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

Here's and update:

#vm, capacity, free, disk count

Can't locate object method "quest" via package "VirtualMachine" at C:\ListVMDisk

s.pl line 52, <STDIN> line 1.

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

This should give you a pretty good idea. The Used vs Capacity numbers will help you estimate your 'on backup disk' storage after they're saved as sparse from VCB. I used it last for a SAN migration to get a better estimate of the 'real' storage needed to migrate the environment over. There will be a few KB more of data from the configuration files. VCB will only get disks defined in the VM configuration file, so you won't have to worry about 'orphaned VMDKs' on the LUNs, which was another problem I ran into at a large QA environment.

The RDMs shouldn't matter. I'm pulling the Guest OS view of the disk. So assuming you aren't partial partitioning a VMDK, it should tell you the total size in use by the VM. You could have unpartitioned disks which should generally be very minimal sparse VMDKs after the VCB export...unless they're attached, but not mounted in the guest OS.

You could look at the raw device capacity, but this won't give you any indication of the exported VMDK size from VCB. Unless you really need your estimate to be tight and nearly exact, I think the Guest OS disk usage from my script will probably be a good start.

I really want to put together a tool to compare Guest OS disk view, the VM's configured block device view, the Datastore view by VM, and list orphaned disk/cfg files on the DataStores. I'd love to see the total file usage on a Datastore by a VM (even across multiple datastores if so configured), then the guest disk view, then the VM's configured VMDK and a break down of files (% of total space used for snapshots, %used by guest os vs allocated on VMDK, etc).

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

Now that is just me being stupid. Sorry I don't have a VM environment to run the script against to catch some of the runtime errors. Thanks for bearing with me.

I spelled guest as 'quest'. Smiley Sad

Fixed and updated.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
Jeff_39
Contributor
Contributor
Jump to solution

I think you got it right ;o) And has I understand, the capacity and free space value will return "0" if the VMware Tools are not installed.

I agree with you that a script who can tell us how many space VM actually take per datastore or even if VMDK are spread accross Datastore (got a lot of them in my environnement and I know it's bad) would be invaluable. I know that I have to deal with the 1 snapshot per VMFS limitation so we want to maximize the number of VM we can take simulteanously (2 backup Proxy Server with 4 HBA in each).

Thanx again for the good work and if you write another script for VMDK space like the one you speak of, let me know ;o)

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

Yes, you'll get 0 values when the Guest tools are not installed and when there are no disks attached to the VM instance (which should be obvious though).

This can happen with boot from floppy/cd VMs or just non-used VMs (but they still show up in the VM list from the API call).

Let me know if you run into anymore snags with the tool.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos