VMware Cloud Community
abassoonkid
Contributor
Contributor

Obtain VM usage statistics through Java SDK

More or less, just what the title says. I've looked into the Java SDK and it is fairly simple to retrieve the allocated memory, CPU, and storage, but I did not see a direct way to obtain the usage amounts.

Reply
0 Kudos
4 Replies
PhilPollard
Enthusiast
Enthusiast

If the user you're connected with is an Administrator, you should see the method "getVMVimRef()" available on your VM reference. (The individual VMs are inside each vApp object.)

From that you can use the getMoRef() method to get the Managed Ojbect reference that can be used to collect statistics about the VM from vCenter via the vSphere API.

The vCloud API itself does not have VM specific statistics available. Or so I have been told.

I am currently struggling with this problem myself, as the vSphere API is a bit on the verbose side. I'm missing a simple method to just instance the MOR and not have to filter for it in some sort of global search routine.

Let me know if you figure it out.

I am available for consulting: http://www.tsslink.com/ My focus is automation and programming with VMware.
Reply
0 Kudos
guitzer
Contributor
Contributor

Dear Sender:

I will be Out Of Office returning by Nov. 14th, 2011. I will get back to you ASAP when return.

Regards

Reply
0 Kudos
abassoonkid
Contributor
Contributor

I figured I could get the performance statistics through vSphere via the MoRef and have thus been persuing that route without another solid answer. I guess I'm just surprised that vCloud doesn't have it directly. If you look for a Managed Object type called PerformanceManager, you should be able to find statistics through that.

Reply
0 Kudos
PhilPollard
Enthusiast
Enthusiast

So it looks like there are a few ways to do this.

As mentioned above, you use the Mor Id to filter for the VM out of the vSphere SDK. And then you can draw some stats out for the VM.

There are several places to draw different bits of statically readable stats and runtime data:

* Summary QuickStats -  Reference here: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.Summary.QuickStats....

* VirtualMachineRuntimeInfo -

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.RuntimeInfo.html

* Basic GuestInfo -

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.GuestInfo.html#fiel...

* GuestDiskInfo -

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.GuestInfo.DiskInfo....

* GuestNicInfo -

http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.GuestInfo.NicInfo.h...

Otherwise, you have to use queryPerf() to pull more data, and perform your own calculations with counter data:

http://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.PerformanceManager.html

There are some aggregate and realtime example files for queryPerf() in the SDK. Look at GetMultiPerf.java and PrintPerfMgr.java. Be careful that MultiPerf.java is using queryPerfComposite() method which is averaging the statistucs for the full array of QuerySpecperf() objects you ask for. So that doesn't make it very helpful for stats on single objects, but the Java example is illustrative.

Steve Jin's book "VMware VI and vSphere SDK" covers queryPerf() a bit more readably than most in Chapter 11, "Performance Monitoring", page 379. You can see that online in SafariBooks if you have an account.

I've put together a sample program that highlights and shows data from all of the above options. It crawls a VCD server for all VMs and then prints out the various stats it can find for each of them from VCD and vSphere. I'll attach it to this post.

This code is drawn from many examples and is free for folks to use. You'll need to change the server names, users and passwords on lines 52, 54 and 58.

In the point of giving credit, lamw gets some points here. His answer in the Perl SDK area had some really helpful links: http://communities.vmware.com/thread/197287

Additionally, his post points to a reference doc for performance monitoring in the SDK: http://communities.vmware.com/docs/DOC-9840

If I had found both of those earlier, it would have been less of a waste of time.

I am available for consulting: http://www.tsslink.com/ My focus is automation and programming with VMware.
Reply
0 Kudos