VMware Cloud Community
DanielVaknin
Enthusiast
Enthusiast
Jump to solution

Gather VM performance statistics from vRO

Hi all,

I'm trying to create a workflow which will show me (System.log or something like that) CPU and Memory statistics of a specified VM from the past year (or a couple of months).

Specifically I'm interested in the Max amount of CPU and MEM usage of the VM (in the specified time).

I've already created a similar script with PowerCLI but I want to do it in the vRO but unfortunately I can't find the correct class.

Is it possible with the default plugins?

If not, how can it be done?

1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

OK, first you need to figure out the IDs of the performance counters you want to collect. You can dump the counter IDs with something like:

var perfMgr = VcPlugin.allSdkConnections[0].performanceManager;

for each (var pc in perfMgr.perfCounter) {

  System.log("counter -> " + pc.key + " , " + pc.nameInfo.key + " , " + pc.nameInfo.label);

}

After you have the counter IDs, you can use PerformanceManager.queryPerf() method to fetch statistics for these counters. Her is some sample code (for counters with Id 2 and 6)

var querySpec = new VcPerfQuerySpec();

querySpec.entity = vm.reference;

querySpec.startTime = new Date(2016, 5, 14);

querySpec.endTime = new Date(2016, 5, 15);

var mid1 = new VcPerfMetricId();

mid1.counterId = 6;

mid1.instance = "";

var mid2 = new VcPerfMetricId();

mid2.counterId = 2;

mid2.instance = "";

querySpec.metricId = [mid1, mid2];

querySpec.format = "csv";

var result = perfMgr.queryPerf([querySpec]);

for each (var r in result) {

  for each (var q in r.value) {

    System.log("value -> " + q.value);

  }

}

View solution in original post

4 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Yes, this can be done with vCenter plug-in.

First, you need to get a reference to Performance Manager object for the given vCenter Server, and then call some of its methods, eg. queryAvailablePerfMetric, queryPerf, queryPerfCounter, etc.

Here is a sample how to obtain a reference to Performance Manager to the first registered vCenter and get a list of available metric for a given interval (the input parameter is 'vm' of type VC:VirtualMAchine):

var perfMgr = VcPlugin.allSdkConnections[0].performanceManager;

var metrics = perfMgr.queryAvailablePerfMetric(vm.reference, new Date(2016, 5, 14), new Date(2016, 5, 15), 20);

System.log(metrics);

DanielVaknin
Enthusiast
Enthusiast
Jump to solution

Thank you for your fast response!

OK, so after I got the metrics, how do I get specifically the max CPU or MEM (for example)?

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

OK, first you need to figure out the IDs of the performance counters you want to collect. You can dump the counter IDs with something like:

var perfMgr = VcPlugin.allSdkConnections[0].performanceManager;

for each (var pc in perfMgr.perfCounter) {

  System.log("counter -> " + pc.key + " , " + pc.nameInfo.key + " , " + pc.nameInfo.label);

}

After you have the counter IDs, you can use PerformanceManager.queryPerf() method to fetch statistics for these counters. Her is some sample code (for counters with Id 2 and 6)

var querySpec = new VcPerfQuerySpec();

querySpec.entity = vm.reference;

querySpec.startTime = new Date(2016, 5, 14);

querySpec.endTime = new Date(2016, 5, 15);

var mid1 = new VcPerfMetricId();

mid1.counterId = 6;

mid1.instance = "";

var mid2 = new VcPerfMetricId();

mid2.counterId = 2;

mid2.instance = "";

querySpec.metricId = [mid1, mid2];

querySpec.format = "csv";

var result = perfMgr.queryPerf([querySpec]);

for each (var r in result) {

  for each (var q in r.value) {

    System.log("value -> " + q.value);

  }

}

DanielVaknin
Enthusiast
Enthusiast
Jump to solution

Great. Thanks you!

Reply
0 Kudos