property = property.substring(property.indexOf(".") + 1);
Long longValue = (Long) ObjectUtil.lookupAttributeProperty(cpu, property);
// A value of -1 indicates SIGAR does not support the metric on the Agent platform type.
if (longValue != null && longValue != -1) {
report.addData(new MeasurementDataNumeric(request, longValue.doubleValue()));
}
} else if (property.startsWith("CpuPerc.")) {
/*
* ! we no longer use the SIGAR CpuPerc object to report cpu percentage metrics. See
* ! RHQ-245 for an explanation. We now calculate our own percentages using
* ! the current raw cpu info from Sigar and the previous cpu numbers, cached per metric.
* ! This allows us to avoid the problem in RHQ-245 while handling perCpu-perMetric schedule
* ! granularity.
*/
// Grab the current cpu info from SIGAR, only once for this cpu for all processed schedules
if (null == cpu) {
cpu = cpuInformation.getCpu();
}
// Create a Cpu cacheEntry only once for this cpu for all processed schedules
if (null == currentCpu) {
currentCpu = new CpuEntry(cpu);
}
// Get the previous cpu numbers to be used for this metric and update the cache for the next go.
CpuEntry previousCpu = cpuCache.put(property, currentCpu);
previousCpu = (null == previousCpu) ? startCpuEntry : previousCpu;
// if for some reason the delta time is excessive then toss the metric, since it depends
// on a reasonable interval between prev and curr. This can happen due to avail down or a newly
// activated metric. Allow up to twice the metric interval. If the metric interval is
// 0 (for a live data request) then just use a 10 minute interval.
Number num = null;
long deltaTime = currentCpu.getTimestamp() - previousCpu.getTimestamp();
long metricInterval = (0 < request.getInterval()) ? request.getInterval() : 600000L;
if (deltaTime <= (2 * metricInterval)) {
// Use the same calculation that SIGAR uses to generate the percentages. The difference is that
// we use a safe "previous" cpu record.
num = getPercentage(previousCpu.getCpu(), cpu, property);
}
// Uncomment to see details about the calculations.
//System.out.println("\nCPU-" + cpuInformation.getCpuIndex() + " Interval="
// + ((currentCpu.getTimestamp() - previousCpu.getTimestamp()) / 1000) + " " + property + "="
// + num + "\n Prev=" + previousCpu + "\n Curr=" + currentCpu);
if (num != null) {
report.addData(new MeasurementDataNumeric(request, num.doubleValue()));
}
} else if (property.startsWith("CpuInfo.")) {
if (cpuInfo == null) {
cpuInfo = cpuInformation.getCpuInfo();
}
property = property.substring(property.indexOf(".") + 1);
Number num = ((Number) ObjectUtil.lookupAttributeProperty(cpuInfo, property));
if (num != null) {
report.addData(new MeasurementDataNumeric(request, num.doubleValue()));
}
} else if (property.startsWith("CpuTrait.")) {
if (cpuInfo == null) {
cpuInfo = cpuInformation.getCpuInfo();
}