Skip to content

Commit

Permalink
[GEOS-8302] Statatus monitoring community module is failing with divi…
Browse files Browse the repository at this point in the history
…sion by zero (NaN)
  • Loading branch information
Nuno Oliveira committed Sep 26, 2017
1 parent 21f0254 commit 73f3eb0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static String humanReadableByteCount(long bytes) {
/**
* Value holder used for XML and JSOn encoding.
*/
public static class ValueHolder {
public static class ValueHolder implements Serializable {

private final Object valueOlder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public OSHISystemInfoCollector() {
currentTime = process.getKernelTime() + process.getUserTime();
if (previousTime != -1) {
timeDifference = currentTime - previousTime;
cpuUsage = (100d * (timeDifference / ((double) 1000))) / pr.getLogicalProcessorCount();
int processors = pr.getLogicalProcessorCount();
if (processors > 0) {
cpuUsage = (100d * (timeDifference / ((double) 1000))) / pr.getLogicalProcessorCount();
} else {
cpuUsage = -1;
}
}
previousTime = currentTime;
try {
Expand Down Expand Up @@ -201,8 +206,12 @@ List<MetricValue> retrieveSystemInfo(MetricInfo info) {
MetricValue mv = new MetricValue(info);
mv.setAvailable(true);
double total = mm.getTotal();
double used = total - mm.getAvailable();
mv.setValue((used / total) * 100);
if (total > 0.0) {
double used = total - mm.getAvailable();
mv.setValue((used / total) * 100);
} else {
mv.setValue(0);
}
si = Collections.singletonList(mv);
break;
}
Expand All @@ -225,8 +234,12 @@ List<MetricValue> retrieveSystemInfo(MetricInfo info) {
MetricValue mv = new MetricValue(info);
mv.setAvailable(true);
double total = mm.getSwapTotal();
double used = mm.getSwapUsed();
mv.setValue(used / total * 100);
if (total > 0.0) {
double used = mm.getSwapUsed();
mv.setValue(used / total * 100);
} else {
mv.setValue(0);
}
si = Collections.singletonList(mv);
break;
}
Expand Down Expand Up @@ -260,7 +273,11 @@ List<MetricValue> retrieveSystemInfo(MetricInfo info) {
used += fsTotal - fs.getUsableSpace();
}
MetricValue mv = new MetricValue(info);
mv.setValue(used / total * 100);
if (total > 0.0) {
mv.setValue(used / total * 100);
} else {
mv.setValue(0);
}
mv.setAvailable(true);
si = Collections.singletonList(mv);
}
Expand All @@ -274,8 +291,12 @@ List<MetricValue> retrieveSystemInfo(MetricInfo info) {
OSFileStore fs = fss[i];
MetricValue mv = new MetricValue(info);
double total = fs.getTotalSpace();
double used = total - fs.getUsableSpace();
mv.setValue(used / total * 100);
if (total > 0.0) {
double used = total - fs.getUsableSpace();
mv.setValue(used / total * 100);
} else {
mv.setValue(0);
}
mv.setAvailable(true);
mv.setDescription("Partition [" + fs.getName() + "] used space");
mv.setPriority(info.getPriority() + (i + 1) * 3);
Expand Down Expand Up @@ -436,10 +457,12 @@ List<MetricValue> retrieveSystemInfo(MetricInfo info) {
}
// geoserver metrics
case GEOSERVER_CPU_USAGE: {
MetricValue mv = new MetricValue(info);
mv.setAvailable(true);
mv.setValue(cpuUsage);
si = Collections.singletonList(mv);
if (cpuUsage >= 0.0) {
MetricValue mv = new MetricValue(info);
mv.setAvailable(true);
mv.setValue(cpuUsage);
si = Collections.singletonList(mv);
}
break;
}
case GEOSERVER_THREADS: {
Expand All @@ -452,10 +475,15 @@ List<MetricValue> retrieveSystemInfo(MetricInfo info) {
}
case GEOSERVER_JVM_MEMORY_USAGE: {
OSProcess gsProc = os.getProcess(os.getProcessId());
double value = 100d * gsProc.getResidentSetSize() / mm.getTotal();
MetricValue mv = new MetricValue(info);
mv.setAvailable(true);
mv.setValue(value);
double total = mm.getTotal();
if (total > 0.0) {
double value = 100d * gsProc.getResidentSetSize() / total;
mv.setValue(value);
} else {
mv.setValue(0);
}
si = Collections.singletonList(mv);
break;
}
Expand Down

0 comments on commit 73f3eb0

Please sign in to comment.