This post is more than 5 years old

13 Posts

144963

February 6th, 2013 17:00

Get resource utilization from all VMs in a cluster

Hi,

I've developed a customized capacity management report that collects all the resource utilization of the virtual machines in a datacenter. The function that collects this looks like this:

def hostMemoryConsumed = []

def memoryConsumed = 0.0f

def memoryGranted = 0.0f

VMs.each() {

  vm ->

  try {

    memoryConsumed += vm.host.memory.consumed.current.average / 1024.0f <----- HOW TO DO THIS TO GET FROM CLUSTERS

    memoryGranted += vm.host.memory.capacity.current.average / 1024.0f

  

  }

  catch(NullPointerException e) { }

}

VMs is a function parameter of type VMW Virtual Machines

The above works for datacenter Virtual machines, but I need it to be after cluster. I can find a clusters virtual machines but I'm having troubles with referencing the specific values to get e.g memory consumed and capacity.

If I change the parameter to type: VMW Cluster how would the metrics reference look like (see the try{})?

I don't think a Query will help me.

Thanks in advance

Erik Alm

171 Posts

February 6th, 2013 22:00

If you want to do this for a cluster, you can just get the list of VMs in a cluster first and pass that into your script.  If you have a function for a VMWCluster you can add a parameter for "vmwCluster" which is below and it should give you an array (topologyObjects) that has all the VMs in the cluster.

qs = server.get("QueryService")  // Query Service

tquery = qs.createStatement("! VMWVirtualMachine where esxServer.parent.name = " + " '" + vmwCluster + "'").setQueryTopologyObjects(true);

topologyObjects = qs.executeStatement(tquery).getTopologyObjects()

No Events found!

Top