Hello, I expanded on the example from http://mighty-virtualization.blogspot.ca/2010/11/vco-get-performance-data-from-vm-build.html. Here is the JavaScript to retrieve the performance metrics from a resourcepool for a day, week and month. Hopefully this will help someone out.
Joe
/* Example Assistance from: http://mighty-virtualization.blogspot.ca/2010/11/vco-get-performance-data-from-vm-build.html */var querySpec = new Array();querySpec.push(new VcPerfQuerySpec());querySpec.push(new VcPerfQuerySpec());querySpec.push(new VcPerfQuerySpec());querySpec[0].entity = resourcepool.reference;querySpec[1].entity = resourcepool.reference;querySpec[2].entity = resourcepool.reference;/* _vSphere_SDK_URL_* The intervalId must equal to last arg of queryAvailablePerfMetric*/querySpec[0].intervalId = 300;querySpec[1].intervalId = 1800;querySpec[2].intervalId = 7200;/* To find metricId - perfCounter PerfCounterInfo[]*/querySpec[0].metricId = resourcepool.sdkConnection.perfManager.queryAvailablePerfMetric(resourcepool.reference,null,null,300);querySpec[1].metricId = resourcepool.sdkConnection.perfManager.queryAvailablePerfMetric(resourcepool.reference,null,null,1800);querySpec[2].metricId = resourcepool.sdkConnection.perfManager.queryAvailablePerfMetric(resourcepool.reference,null,null,7200);querySpec[0].format = "normal";querySpec[1].format = "normal";querySpec[2].format = "normal";/* Return Type: VcPerfEntityMetricBase[] */var results = resourcepool.sdkConnection.perfManager.queryPerf(querySpec);/* Create hash table */var hashMaximums = new Object();/* Keep the metricIds */var metricIdArray = new Array();for(var j in results) {var result = results[j]; // VcPerfEntityMetricvar perfMetricSeries = result.value; //VcPerfMetricSeries[]for(var k in perfMetricSeries) { //VcPerfMetricIntSeriesvar average = AverageArray(perfMetricSeries[k].value); //Number[] (Int64)/* If j == 0 then we need to init values to the hashtable based on the counterId key */if( j == 0 ) {hashMaximums[perfMetricSeries[k].id.counterId] = average;metricIdArray.push(perfMetricSeries[k].id.counterId);} /* if the existing value is less the current, replace */else if( hashMaximums[perfMetricSeries[k].id.counterId] < average ) {hashMaximums[perfMetricSeries[k].id.counterId] = average;}}}for( var i in metricIdArray ) {var nameInfoLabel = resourcepool.sdkConnection.perfManager.perfCounter[metricIdArray[i]].nameInfo.label;var unitInfoLabel = resourcepool.sdkConnection.perfManager.perfCounter[metricIdArray[i]].unitInfo.label;System.log(nameInfoLabel + " = " + hashMaximums[metricIdArray[i]] + " " + unitInfoLabel);}/* Source Code Source*/function AverageArray(t_array) {var av = 0;var cnt = 0;var len = t_array.length;for (var i = 0; i < len; i++) {var e = +t_array[i];if(!e && t_array[i] !== 0 && t_array[i] !== '0') e--;if (t_array[i] == e) {av += e; cnt++;}}return av/cnt;}
Great! Thanks for sharing!
Can you explain exactly what versions you use (of vCenter, vCO and the vCenter Plugin)?
(I remember that there were some issues in certain combinations...)
Thanks!
Joerg
