Some time back, I wanted to get the cluster resource usage (cpu, memory, storage)for one of my project requirements. I was exploring the ways to get cluster resource usage and to my surprise, vSphere 6.0 has introduced new API which can fetch detailed cluster resource usage. It was tricky to get this info earlier and now single API call will help to get this. How cool it is! If you are not using vSphere HA/DRS, this API is super life saver for you in order to keep the track of the cluster resources and monitor these resources on all the cluster across vCenter. New method that I am talking about is “getResourceUsage()”. This method is introduced in vSphere 6.0 under “ClusterComputeResource” managed object. It is mean that you need to have this managed object to call this useful method. i.e. getResourceUsage(). This API can fetch not only the resource capacity but also current resource usage.
Below is the complete code sample which can help you quickly to get Cluster resource usage (cpu,memory and storage)..
[java]
//:: # Author: Vikas Shitole
//:: # Website: www.vThinkBeyondVM.com
//:: # Product/Feature: vCenter Server/DRS
//:: # Description: Script to quickly get Cluster resource usage (cpu,memory and storage).
package com.vmware.yavijava;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import com.vmware.vim25.ClusterResourceUsageSummary;
import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.mo.ClusterComputeResource;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ServiceInstance;
public class GetClusterResourceUsage {
public static void main(String[] args) throws Exception {
if(args.length!=3)
{
System.out.println("Usage: GetClusterResourceUsage url username password");
System.exit(-1);
}
URL url = null;
try
{
url = new URL(args[0]);
} catch ( MalformedURLException urlE)
{
System.out.println("The URL provided is NOT valid. Please check it…");
System.exit(-1);
}
String username = args[1];
String password = args[2];
String ClusterName = "Cluster1"; //Your cluster Name
// Initialize the system, set up web services
ServiceInstance si = new ServiceInstance(url, username,
password, true);
Folder rootFolder = si.getRootFolder();
ClusterComputeResource cluster = null;
cluster = (ClusterComputeResource) new InventoryNavigator(rootFolder)
.searchManagedEntity("ClusterComputeResource", ClusterName);
System.out.println();
System.out.println("Resource Usagae Summary for cluster::"+cluster.getName());
//Get the Cluster resource summary object
ClusterResourceUsageSummary resourceSummary= cluster.getResourceUsage();
System.out.println("CPU Capacity::"+resourceSummary.getCpuCapacityMHz()+" MHz");
System.out.println("CPU used::"+resourceSummary.getCpuUsedMHz()+" MHz");
System.out.println("Memory Capacity::"+resourceSummary.getMemCapacityMB()+" MB");
System.out.println("Memory used::"+resourceSummary.getMemUsedMB()+" MB");
System.out.println("Storage Capacity::"+resourceSummary.getStorageCapacityMB()+" MB");
System.out.println("Storage used::"+resourceSummary.getStorageUsedMB()+" MB");
si.getServerConnection().logout();
}
}
[/java]
Note:
– For the sake of simplicity, I have hard-coded DRS cluster name, you can change it based on your environment.
– You can scale the same code to all the clusters in a datacenter or multiple datacenter.
If you have still not setup your YAVI JAVA Eclipse environment:Getting started tutorial
Important tutorials to start with: Part I & Part II

Vikas Shitole is a Senior Tech Lead at VMware by Broadcom, VCF division, India, where he leads system test effortsโincluding scale, stress, and resiliency testingโand drives product quality across VMware Cloud Foundation (VCF), Broadcomโs flagship private cloud platform. He is an AI and Kubernetes enthusiast, and is passionate about VMware customers and automation around vSphere and VCF. Vikas has been honoured as a vExpert for 13 consecutive years (2014โ2026) for his sustained technical contributions and community leadership. He is the author of two VMware Flings, holds multiple industry certifications including VCF admin 9.0, and is one of the top contributors to the VMware API Sample Exchange, where his automation scripts have been downloaded over 50,000 times. Vikas has shared his expertise as a speaker at international conferences such as VMworld Europe and VMworld USA, and was selected as an official VMworld 2018 blogger. He also served as lead technical reviewer for the Packt-published books vSphere Design and VMware Virtual SAN Essentials. Beyond tech, Vikas is a dedicated cricketer, cycling enthusiast, and a lifelong learner in fitness and nutrition, with the personal goal of completing an Ironman 70.3