report.setStatus(ConfigurationUpdateStatus.FAILURE);
return;
}
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) {
SystemInfo info = this.resourceContext.getSystemInformation();
boolean isNative = info.isNative();
Mem platformMemoryInfo = null;
Swap platformSwapInfo = null;
CpuPerc cpuPerc = null;
try {
cpuPerc = SigarAccess.getSigar().getCpuPerc();
} catch (Exception e) {
// probably native api is unavailable, but getCpuPerc might also have a problem; in either case, nothing we can do
}
for (MeasurementScheduleRequest request : metrics) {
String property = request.getName();
if (property.startsWith(NATIVE_INDICATOR)) {
// we cannot collect a native measurement without native support - go on to the next
if (!isNative) {
continue;
}
property = property.substring(NATIVE_INDICATOR.length());
}
if (property.startsWith(TRAIT_INDICATOR)) {
report.addData(getMeasurementDataTrait(request));
} else if (property.startsWith("MemoryInfo.")) {
if (platformMemoryInfo == null) {
platformMemoryInfo = info.getMemoryInfo();
}
property = property.substring(property.indexOf(".") + 1);
double memoryValue = ((Number) getObjectProperty(platformMemoryInfo, property)).doubleValue();
report.addData(new MeasurementDataNumeric(request, memoryValue));
} else if (property.startsWith("SwapInfo.")) {
if (platformSwapInfo == null) {
platformSwapInfo = info.getSwapInfo();
}
if (platformSwapInfo != null) {
property = property.substring(property.indexOf(".") + 1);
double swapValue = ((Number) getObjectProperty(platformSwapInfo, property)).doubleValue();
report.addData(new MeasurementDataNumeric(request, swapValue));