Search in sources :

Example 1 with HealthCheckResultEntry

use of fish.payara.notification.healthcheck.HealthCheckResultEntry in project Payara by payara.

the class HeapMemoryUsageHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    HealthCheckResult result = new HealthCheckResult();
    MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = memBean.getHeapMemoryUsage();
    String heapValueText = String.format("heap: init: %s, used: %s, committed: %s, max.: %s", prettyPrintBytes(heap.getInit()), prettyPrintBytes(heap.getUsed()), prettyPrintBytes(heap.getCommitted()), prettyPrintBytes(heap.getMax()));
    Double percentage = calculatePercentage(heap);
    result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), heapValueText + "heap%: " + percentage + "%"));
    return result;
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) HealthCheckResult(fish.payara.nucleus.healthcheck.HealthCheckResult) MemoryUsage(java.lang.management.MemoryUsage) HealthCheckResultEntry(fish.payara.notification.healthcheck.HealthCheckResultEntry)

Example 2 with HealthCheckResultEntry

use of fish.payara.notification.healthcheck.HealthCheckResultEntry in project Payara by payara.

the class HoggingThreadsHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    if (!getOptions().isEnabled()) {
        return null;
    }
    HealthCheckResult result = new HealthCheckResult();
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    if (!threadBean.isCurrentThreadCpuTimeSupported()) {
        result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "JVM implementation or OS does" + " not support getting CPU times"));
        return result;
    }
    final long[] ids = threadBean.getAllThreadIds();
    for (long id : ids) {
        if (id == Thread.currentThread().getId())
            continue;
        final long c = threadBean.getThreadCpuTime(id);
        final long u = threadBean.getThreadUserTime(id);
        ThreadInfo threadInfo = threadBean.getThreadInfo(id);
        if (c == -1 || u == -1)
            continue;
        ThreadTimes times = threadTimes.get(id);
        if (times == null) {
            times = new ThreadTimes();
            times.setId(id);
            times.setName(threadInfo.getThreadName());
            times.setStartCpuTime(c);
            times.setEndCpuTime(c);
            times.setStartUserTime(u);
            times.setEndUserTime(u);
            threadTimes.put(id, times);
        } else {
            times.setStartCpuTime(times.getEndCpuTime());
            times.setStartUserTime(times.getEndUserTime());
            times.setEndCpuTime(c);
            times.setEndUserTime(u);
            long checkTime = getOptions().getUnit().toMillis(getOptions().getTime());
            long duration = times.getEndCpuTime() - times.getStartCpuTime();
            double percentage = ((double) (TimeUnit.NANOSECONDS.toMillis(duration)) / (double) (checkTime)) * 100;
            if (percentage > options.getThresholdPercentage()) {
                if (times.getRetryCount() == 0) {
                    times.setInitialStartCpuTime(System.nanoTime());
                    times.setInitialStartUserTime(System.nanoTime());
                }
                if (times.getRetryCount() >= options.getRetryCount()) {
                    result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "Thread with <id-name>: " + id + "-" + times.getName() + " is a hogging thread for the last " + prettyPrintDuration(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - times.getInitialStartCpuTime())) + "\n" + prettyPrintStackTrace(threadInfo.getStackTrace())));
                }
                times.setRetryCount(times.getRetryCount() + 1);
            }
        }
    }
    return result;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) HealthCheckResult(fish.payara.nucleus.healthcheck.HealthCheckResult) HealthCheckResultEntry(fish.payara.notification.healthcheck.HealthCheckResultEntry) ThreadTimes(fish.payara.nucleus.healthcheck.entity.ThreadTimes)

Example 3 with HealthCheckResultEntry

use of fish.payara.notification.healthcheck.HealthCheckResultEntry in project Payara by payara.

the class MachineMemoryUsageHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    HealthCheckResult result = new HealthCheckResult();
    long memAvailable = 0;
    long memFree = 0;
    long memTotal = 0;
    long memActiveFile = 0;
    long memInactiveFile = 0;
    long memReclaimable = 0;
    boolean memAvailableFound = false;
    if (isLinux()) {
        try {
            List<String> lines = Files.readAllLines(Paths.get("/proc/meminfo"), StandardCharsets.UTF_8);
            if (lines.isEmpty()) {
                return result;
            }
            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 = ((double) 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));
        }
    } else {
        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;
}
Also used : DecimalFormat(java.text.DecimalFormat) HealthCheckResult(fish.payara.nucleus.healthcheck.HealthCheckResult) IOException(java.io.IOException) IOException(java.io.IOException) HealthCheckResultEntry(fish.payara.notification.healthcheck.HealthCheckResultEntry) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 4 with HealthCheckResultEntry

use of fish.payara.notification.healthcheck.HealthCheckResultEntry in project Payara by payara.

the class CpuUsageHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    if (!getOptions().isEnabled()) {
        return null;
    }
    HealthCheckResult result = new HealthCheckResult();
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    if (!threadBean.isCurrentThreadCpuTimeSupported()) {
        result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "JVM implementation or OS does not support getting CPU times"));
        return result;
    }
    final long[] ids = threadBean.getAllThreadIds();
    for (long id : ids) {
        if (id == java.lang.Thread.currentThread().getId())
            continue;
        final long c = threadBean.getThreadCpuTime(id);
        final long u = threadBean.getThreadUserTime(id);
        if (c == -1 || u == -1)
            continue;
        ThreadTimes times = threadTimes.get(id);
        if (times == null) {
            times = new ThreadTimes();
            times.setId(id);
            times.setStartCpuTime(c);
            times.setEndCpuTime(c);
            times.setStartUserTime(u);
            times.setEndUserTime(u);
            threadTimes.put(id, times);
        } else {
            times.setEndCpuTime(c);
            times.setEndUserTime(u);
        }
    }
    long totalCpuTime = getTotalCpuTime();
    long time = System.nanoTime();
    double percentage = ((double) (totalCpuTime - totalTimeBefore) / (double) (time - timeBefore)) * 100;
    result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), "CPU%: " + new DecimalFormat("#.00").format(percentage) + ", Time CPU used: " + prettyPrintDuration(TimeUnit.NANOSECONDS.toMillis(getTotalCpuTime() - totalTimeBefore))));
    totalTimeBefore = totalCpuTime;
    timeBefore = time;
    return result;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) DecimalFormat(java.text.DecimalFormat) HealthCheckResult(fish.payara.nucleus.healthcheck.HealthCheckResult) HealthCheckResultEntry(fish.payara.notification.healthcheck.HealthCheckResultEntry) ThreadTimes(fish.payara.nucleus.healthcheck.entity.ThreadTimes)

Example 5 with HealthCheckResultEntry

use of fish.payara.notification.healthcheck.HealthCheckResultEntry in project Payara by payara.

the class GarbageCollectorHealthCheck method doCheck.

@Override
public HealthCheckResult doCheck() {
    HealthCheckResult result = new HealthCheckResult();
    List<GarbageCollectorMXBean> gcBeanList = ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gcBean : gcBeanList) {
        double percentage = 0;
        if (YOUNG_PS_SCAVENGE.equals(gcBean.getName()) || YOUNG_G1GC.equals(gcBean.getName()) || YOUNG_COPY.equals(gcBean.getName()) || YOUNG_PARNEW.equals(gcBean.getName())) {
            long diffCount = gcBean.getCollectionCount() - youngLastCollectionCount;
            long diffTime = gcBean.getCollectionTime() - youngLastCollectionTime;
            if (diffTime > 0 && youngLastCollectionCount > 0) {
                percentage = ((diffCount) / (youngLastCollectionCount)) * 100;
                result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), diffCount + " times Young GC (" + gcBean.getName() + ") after " + prettyPrintDuration(diffTime)));
            }
            youngLastCollectionCount = gcBean.getCollectionCount();
            youngLastCollectionTime = gcBean.getCollectionTime();
        } else if (OLD_PS_MARKSWEEP.equals(gcBean.getName()) || OLD_G1GC.equals(gcBean.getName()) || OLD_MARK_SWEEP_COMPACT.equals(gcBean.getName()) || OLD_CONCURRENTMARKSWEEP.equals(gcBean.getName())) {
            long diffCount = gcBean.getCollectionCount() - oldLastCollectionCount;
            long diffTime = gcBean.getCollectionTime() - oldLastCollectionTime;
            if (diffTime > 0 && oldLastCollectionCount > 0) {
                percentage = ((diffCount) / (oldLastCollectionCount)) * 100;
                result.add(new HealthCheckResultEntry(decideOnStatusWithRatio(percentage), diffCount + " times Old GC (" + gcBean.getName() + ") after " + prettyPrintDuration(diffTime)));
            }
            oldLastCollectionCount = gcBean.getCollectionCount();
            oldLastCollectionTime = gcBean.getCollectionTime();
        } else {
            result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "Could not identify " + "GarbageCollectorMXBean with name: " + gcBean.getName()));
        }
    }
    return result;
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) HealthCheckResultEntry(fish.payara.notification.healthcheck.HealthCheckResultEntry)

Aggregations

HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)7 HealthCheckResult (fish.payara.nucleus.healthcheck.HealthCheckResult)5 ThreadMXBean (java.lang.management.ThreadMXBean)3 DecimalFormat (java.text.DecimalFormat)3 ThreadTimes (fish.payara.nucleus.healthcheck.entity.ThreadTimes)2 ThreadInfo (java.lang.management.ThreadInfo)2 PoolStatus (com.sun.enterprise.resource.pool.PoolStatus)1 IOException (java.io.IOException)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1