Forum Discussion

Massimo's avatar
4 years ago

VMs monitoring based on vSphere folder

Hello,
In our infrastructure we have a vCenter that contains several thousand VMs.
The monitoring of this device is complex and slowed down by the tens of thousands of datapoints extracted for each VM, moreover it is necessary to apply different rules and standards depending on the folder where the VM resides.
Consulting the query system (Groovy) of the "VMware_vCenter_ *" datasources, I thought of changing the vCenter query method via ESX API, in particular by invoking the Java "searchManagedEntity" method in an alternative way during the instance extraction phase, in order to focus the extraction only on specific and reduced number of instances.
In this way, it is possible to extract only the information relating to the contents of a folder on vCenter, which was the set goal.

From:

// Open a connection to the vSphere API, get a service instance and root folder
def svc = new ESX();
svc.open(addr, user, pass, 10 * 1000); // timeout in 10 seconds

def rootFolder = svc.getServiceInstance().getRootFolder();

// Get all of the VM's
def vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");

 

To:
 

def String fName = hostProps.get("esx.folder");

// Open a connection to the vSphere API, get a service instance and root folder
def svc = new ESX();
svc.open(addr, user, pass, 10 * 1000); // timeout in 10 seconds

def rootFolder = svc.getServiceInstance().getRootFolder();
def fTarget = new InventoryNavigator(rootFolder).searchManagedEntity("Folder", fName);

// Get all of the VM's
def vms = new InventoryNavigator(fTarget).searchManagedEntities("VirtualMachine");

 

This code is from the "VMware_vCenter_VMDiskCapacity" datasource, but the same concepts apply for all the datasources based on Groovy + ESX API on vCenter instance level interrogation.

By cloning the DS and adding different properties it is even possible to apply the same code on multiple different folder(s) of the same vCenter, rendering so simpler (at least for us) to define custom alert exceptions or alert rules (for example, one for "production" VMs, one for "testing" VMs, and so on...).