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 honored as a vExpert for 12 consecutive years (2014–2025) for his sustained technical contributions and community leadership.
He is the author of two VMware Flings, holds multiple industry certifications, 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
Hi Vikas
This is a great post again, have you had to get the same cluster information but making use of pyvmomi? I currently make use of a PowerCli script to export loads of cluster related information daily, but as the process is taking 4+hours over 14vc’s we started experimenting with python to see if we can replace the original PowerCli script.
Any advise or response will be appreciated.
Hi Johan,
Thanks for your comment. Its same API ClusterResourceUsageSummary resourceSummary= cluster.getResourceUsage(); available in python SDK as well and it should be easy to implement there. If you need help on python for this particular cluster API, please let me know. Also, In powerCLi as well, we can do programming directly using .Net View objects (instead of PowerCLI cmdlets). PowerCLI .Net View objects have 1:1 mapping with APIs.
In this week, I will publish another blog post which will demonstrate how to achieve (getResourceUsage) using PowerCLI .Net view objects (no cmdlets) with one more small script.
Hi Vikas, I have been trying to get this translated to pyvomomi and facing trouble with the below lines
ClusterComputeResource cluster = null;
cluster = (ClusterComputeResource) new InventoryNavigator(rootFolder)
.searchManagedEntity(“ClusterComputeResource”, ClusterName);
But have been facing difficulty. Could you please take a look and help me out if possible.
which vijava version you used to show this class and method ClusterResourceUsageSummary resourceSummary= cluster.getResourceUsage(); ?