Search in sources :

Example 36 with MemoryUsage

use of java.lang.management.MemoryUsage in project Lucee by lucee.

the class MacAddressWrap method getFreePermGenSpaceSize.

public static long getFreePermGenSpaceSize() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null)
        return -1;
    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0)
        return -1;
    return max - used;
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 37 with MemoryUsage

use of java.lang.management.MemoryUsage in project Lucee by lucee.

the class MacAddressWrap method getFreePermGenSpacePromille.

public static int getFreePermGenSpacePromille() {
    MemoryUsage mu = getPermGenSpaceSize(null);
    if (mu == null)
        return -1;
    long max = mu.getMax();
    long used = mu.getUsed();
    if (max < 0 || used < 0)
        return -1;
    return (int) (1000L - (1000L * used / max));
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 38 with MemoryUsage

use of java.lang.management.MemoryUsage in project knime-core by knime.

the class MemoryService method isMemoryLow.

/**
 * This is a stateful method return true in the low memory condition. Note,
 * this method only returns true at most once between two garbage
 * collections.
 *
 * @return True if memory is low.
 */
public boolean isMemoryLow() {
    if (m_waitForNextGC) {
        long thisCount = null != m_memPool ? m_gcBean.iterator().next().getCollectionCount() : Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        if (thisCount == m_lastCount) {
            return false;
        } else {
            m_waitForNextGC = false;
        }
    }
    MemoryUsage usage = null;
    if (m_useCollectionUsage) {
        usage = m_memPool.getCollectionUsage();
    }
    if (null == usage && null != m_memPool) {
        usage = m_memPool.getUsage();
    }
    if (null != usage) {
        boolean memoryIsLow = usage.getUsed() > m_threshold;
        if (memoryIsLow) {
            m_waitForNextGC = true;
            m_lastCount = m_gcBean.iterator().next().getCollectionCount();
            return true;
        } else {
            return false;
        }
    } else {
        long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        boolean memoryIsLow = used > m_threshold;
        if (memoryIsLow) {
            m_waitForNextGC = true;
            m_lastCount = used;
            return true;
        } else {
            return false;
        }
    }
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 39 with MemoryUsage

use of java.lang.management.MemoryUsage in project Payara by payara.

the class MemoryReporter method getMemoryPoolReport.

private String getMemoryPoolReport() {
    final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder());
    final long millis = rmbean.getUptime();
    final String uptime = sm.getString("uptime", JVMInformationCollector.millis2HoursMinutesSeconds(millis));
    sb.append(uptime);
    for (final MemoryPoolMXBean m : pools) {
        final String n = m.getName();
        sb.append(sm.getString("memory.pool.name", n));
        MemoryUsage mu = m.getUsage();
        sb.append(mu2String(mu));
    }
    return (sb.toString());
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 40 with MemoryUsage

use of java.lang.management.MemoryUsage 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)

Aggregations

MemoryUsage (java.lang.management.MemoryUsage)75 MemoryMXBean (java.lang.management.MemoryMXBean)15 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)15 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 RuntimeMXBean (java.lang.management.RuntimeMXBean)6 HashMap (java.util.HashMap)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)5 ThreadMXBean (java.lang.management.ThreadMXBean)4 Map (java.util.Map)4 IOException (java.io.IOException)3 MemoryType (java.lang.management.MemoryType)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)2 File (java.io.File)2 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)2 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)2 Date (java.util.Date)2 Properties (java.util.Properties)2