The following code fragment calls the QueryPerf method to retrieve statistics. It performs these tasks:
Procedure
Example
/*
* Use <group>.<name>.<ROLLUP-TYPE> path specification to identify counters.
*/
String[] counterNames = new String[] {"disk.provisioned.LATEST",
"mem.granted.AVERAGE",
"power.power.AVERAGE"};
/*
* Create the list of PerfMetricIds, one for each counter.
*/
List<PerfMetricId> perfMetricIds = new ArrayList<PerfMetricId>();
for(int i = 0; i < counterNames.length; i++) {
/*
* Create the PerfMetricId object for the counterName.
* Use an asterisk to select all metrics associated with counterId (instances and rollup).
*/
PerfMetricId metricId = new PerfMetricId();
/* Get the ID for this counter. */
metricId.setCounterId(countersIdMap.get(counterNames[i]));
metricId.setInstance("*");
perfMetricIds.add(metricId);
}
/*
* Create the query specification for queryPerf().
* Specify 5 minute rollup interval and CSV output format.
*/
int intervalId = 300;
PerfQuerySpec querySpecification = new PerfQuerySpec();
querySpecification.setEntity(
querySpecification.setIntervalId(intervalId);
querySpecification.setFormat("csv");
querySpecification.getMetricId().addAll(perfMetricIds);
List<PerfQuerySpec> pqsList = new ArrayList<PerfQuerySpec>();
pqsList.add(querySpecification);
/*
* Call queryPerf()
*
* QueryPerf() returns the statistics specified by the provided
* PerfQuerySpec objects. When specified statistics are unavailable -
* for example, when the counter doesn't exist on the target
* ManagedEntity - QueryPerf() returns null for that counter.
*/
List<PerfEntityMetricBase> retrievedStats = apiMethods.queryPerf(performanceMgrRef, pqsList);