diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseThresholdHealthCheck.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseThresholdHealthCheck.java index 5be4f47dc93..ae210c8f739 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseThresholdHealthCheck.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/BaseThresholdHealthCheck.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -83,7 +83,7 @@ protected HealthCheckResultStatus decideOnStatusWithRatio(Double percentage) { if (percentage >= options.getThresholdGood()) { return HealthCheckResultStatus.GOOD; } - return HealthCheckResultStatus.FINE; + return HealthCheckResultStatus.FINE; } @Override diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/HeapMemoryUsageHealthCheck.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/HeapMemoryUsageHealthCheck.java index b4fb9fed77f..5ab9a02c473 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/HeapMemoryUsageHealthCheck.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/HeapMemoryUsageHealthCheck.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development diff --git a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/MachineMemoryUsageHealthCheck.java b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/MachineMemoryUsageHealthCheck.java index caaed0c8229..0996fcaedbc 100644 --- a/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/MachineMemoryUsageHealthCheck.java +++ b/nucleus/payara-modules/healthcheck-core/src/main/java/fish/payara/nucleus/healthcheck/preliminary/MachineMemoryUsageHealthCheck.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -92,98 +92,98 @@ public String getDescription() { @Override public HealthCheckResult doCheck() { if (isLinux()) { - return doCheckLinux(); + return doCheckLinux(); } - return doCheckNonLinux(); + return doCheckNonLinux(); } - private HealthCheckResult doCheckLinux() { - HealthCheckResult result = new HealthCheckResult(); - long memTotal = 0; - try { - List lines = Files.readAllLines(Paths.get("/proc/meminfo"), StandardCharsets.UTF_8); - if (lines.isEmpty()) { - return result; - } - long memAvailable = 0; - long memFree = 0; - long memActiveFile = 0; - long memInactiveFile = 0; - long memReclaimable= 0; - boolean memAvailableFound = false; - - for (String line : lines) { - String[] parts = line.split("\\s+"); - - if (parts.length > 1) { - String part = parts[0]; - if (MEMAVAILABLE.equals(part)) { - memAvailable = parseMemInfo(parts); - memAvailableFound = true; - } - if (MEMFREE.equals(part)) { - memFree = parseMemInfo(parts); - } - if (MEMTOTAL.equals(part)) { - memTotal = parseMemInfo(parts); - } - if (ACTIVEFILE.equals(part)) { - memActiveFile = parseMemInfo(parts); - } - if (INACTIVEFILE.equals(part)) { - memInactiveFile = parseMemInfo(parts); - } - if (RECLAIMABLE.equals(part)) { - memReclaimable = parseMemInfo(parts); - } - } - } - - if (!memAvailableFound) { - memAvailable = memFree + memActiveFile + memInactiveFile + memReclaimable; - } - - double usedPercentage = memTotal == 0L ? 0d :((double) (memTotal - memAvailable) / memTotal) * 100; - - result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(usedPercentage), - "Physical Memory Used: " + prettyPrintBytes(memTotal - memAvailable) + " - " + - "Total Physical Memory: " + prettyPrintBytes(memTotal) + " - " + - "Memory Used%: " + new DecimalFormat("#.00").format(usedPercentage) + "%")); - - } catch (IOException exception) { - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, - "Memory information cannot be read for retrieving physical memory usage values", - exception)); - } catch (ArithmeticException exception) { - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, - "Error occurred while calculating memory usage values. Total memory is " + memTotal, - exception)); - } - return result; - } - - private HealthCheckResult doCheckNonLinux() { - HealthCheckResult result = new HealthCheckResult(); - try { - OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); - Long totalPhysicalMemSize = invokeMethodFor(osBean, "getTotalPhysicalMemorySize"); - Long freePhysicalMemSize = invokeMethodFor(osBean, "getFreePhysicalMemorySize"); - - double usedPercentage = ((double) (totalPhysicalMemSize - freePhysicalMemSize) / totalPhysicalMemSize) * - 100; - - result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(usedPercentage), - "Physical Memory Used: " + prettyPrintBytes((totalPhysicalMemSize - freePhysicalMemSize)) + " - " + - "Total Physical Memory: " + prettyPrintBytes(totalPhysicalMemSize) + " - " + - "Memory Used%: " + new DecimalFormat("#.00").format(usedPercentage) + "%")); - - } catch (Exception exception) { - result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, - "Operating system methods cannot be invoked for retrieving physical memory usage values", - exception)); - } - return result; - } + private HealthCheckResult doCheckLinux() { + HealthCheckResult result = new HealthCheckResult(); + long memTotal = 0; + try { + List lines = Files.readAllLines(Paths.get("/proc/meminfo"), StandardCharsets.UTF_8); + if (lines.isEmpty()) { + return result; + } + long memAvailable = 0; + long memFree = 0; + long memActiveFile = 0; + long memInactiveFile = 0; + long memReclaimable= 0; + boolean memAvailableFound = false; + + for (String line : lines) { + String[] parts = line.split("\\s+"); + + if (parts.length > 1) { + String part = parts[0]; + if (MEMAVAILABLE.equals(part)) { + memAvailable = parseMemInfo(parts); + memAvailableFound = true; + } + if (MEMFREE.equals(part)) { + memFree = parseMemInfo(parts); + } + if (MEMTOTAL.equals(part)) { + memTotal = parseMemInfo(parts); + } + if (ACTIVEFILE.equals(part)) { + memActiveFile = parseMemInfo(parts); + } + if (INACTIVEFILE.equals(part)) { + memInactiveFile = parseMemInfo(parts); + } + if (RECLAIMABLE.equals(part)) { + memReclaimable = parseMemInfo(parts); + } + } + } + + if (!memAvailableFound) { + memAvailable = memFree + memActiveFile + memInactiveFile + memReclaimable; + } + + double usedPercentage = memTotal == 0L ? 0d :((double) (memTotal - memAvailable) / memTotal) * 100; + + result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(usedPercentage), + "Physical Memory Used: " + prettyPrintBytes(memTotal - memAvailable) + " - " + + "Total Physical Memory: " + prettyPrintBytes(memTotal) + " - " + + "Memory Used%: " + new DecimalFormat("#.00").format(usedPercentage) + "%")); + + } catch (IOException exception) { + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, + "Memory information cannot be read for retrieving physical memory usage values", + exception)); + } catch (ArithmeticException exception) { + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, + "Error occurred while calculating memory usage values. Total memory is " + memTotal, + exception)); + } + return result; + } + + private HealthCheckResult doCheckNonLinux() { + HealthCheckResult result = new HealthCheckResult(); + try { + OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); + Long totalPhysicalMemSize = invokeMethodFor(osBean, "getTotalPhysicalMemorySize"); + Long freePhysicalMemSize = invokeMethodFor(osBean, "getFreePhysicalMemorySize"); + + double usedPercentage = ((double) (totalPhysicalMemSize - freePhysicalMemSize) / totalPhysicalMemSize) * + 100; + + result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(usedPercentage), + "Physical Memory Used: " + prettyPrintBytes((totalPhysicalMemSize - freePhysicalMemSize)) + " - " + + "Total Physical Memory: " + prettyPrintBytes(totalPhysicalMemSize) + " - " + + "Memory Used%: " + new DecimalFormat("#.00").format(usedPercentage) + "%")); + + } catch (Exception exception) { + result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, + "Operating system methods cannot be invoked for retrieving physical memory usage values", + exception)); + } + return result; + } private static boolean isLinux() { String osName = System.getProperty("os.name"); @@ -191,7 +191,6 @@ private static boolean isLinux() { osName.startsWith("FreeBSD") || osName.startsWith("OpenBSD") || osName.startsWith("gnu") || - osName.startsWith("gnu/kfreebsd") || osName.startsWith("netbsd"); }