Search in sources :

Example 36 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project ignite by apache.

the class GridManagerMxBeanIllegalArgumentHandleTest method createAlwaysFailingMxBean.

/** MX bean which is always failing to respond with metrics */
@NotNull
private MemoryMXBean createAlwaysFailingMxBean() {
    final Answer<MemoryUsage> failingAnswer = new Answer<MemoryUsage>() {

        @Override
        public MemoryUsage answer(InvocationOnMock invocationOnMock) throws Throwable {
            throw new IllegalArgumentException("java.lang.IllegalArgumentException: committed = 5274103808 should be < max = 5274095616");
        }
    };
    final MemoryMXBean memoryMXBean = Mockito.mock(MemoryMXBean.class);
    when(memoryMXBean.getHeapMemoryUsage()).thenAnswer(failingAnswer);
    when(memoryMXBean.getNonHeapMemoryUsage()).thenAnswer(failingAnswer);
    return memoryMXBean;
}
Also used : Answer(org.mockito.stubbing.Answer) MemoryMXBean(java.lang.management.MemoryMXBean) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MemoryUsage(java.lang.management.MemoryUsage) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project karaf by apache.

the class EnvironmentDumpProvider method dumpMemoryInformation.

private void dumpMemoryInformation(final PrintWriter outPW) {
    final MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
    if (null == mxBean) {
        return;
    }
    final MemoryUsage heapMemoryUsage = mxBean.getHeapMemoryUsage();
    final MemoryUsage nonHeapMemoryUsage = mxBean.getNonHeapMemoryUsage();
    if (heapMemoryUsage != null) {
        outPW.println("HEAP Memory:");
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "commited", printMemory(heapMemoryUsage.getCommitted())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "init", printMemory(heapMemoryUsage.getInit())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "used", printMemory(heapMemoryUsage.getUsed())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "maximal", printMemory(heapMemoryUsage.getMax())).println();
    }
    if (nonHeapMemoryUsage != null) {
        outPW.println("NON-HEAP Memory:");
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "commited", printMemory(nonHeapMemoryUsage.getCommitted())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "init", printMemory(nonHeapMemoryUsage.getInit())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "used", printMemory(nonHeapMemoryUsage.getUsed())).println();
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "maximal", printMemory(nonHeapMemoryUsage.getMax())).println();
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 38 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project karaf by apache.

the class MemoryDumpProvider method writeDump.

@Override
protected void writeDump(OutputStreamWriter outputStream) throws Exception {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    outputStream.write("Number of objects waiting finalization: " + memoryMXBean.getObjectPendingFinalizationCount() + "\n\n");
    outputStream.write("Heap:\n");
    outputStream.write("\tInit:      " + memoryMXBean.getHeapMemoryUsage().getInit() + "\n");
    outputStream.write("\tUser:      " + memoryMXBean.getHeapMemoryUsage().getUsed() + "\n");
    outputStream.write("\tCommitted: " + memoryMXBean.getHeapMemoryUsage().getCommitted() + "\n");
    outputStream.write("\tMax:       " + memoryMXBean.getHeapMemoryUsage().getMax() + "\n");
    outputStream.write("Non-Heap: \n");
    outputStream.write("\tInit:      " + memoryMXBean.getNonHeapMemoryUsage().getInit() + "\n");
    outputStream.write("\tUser:      " + memoryMXBean.getNonHeapMemoryUsage().getUsed() + "\n");
    outputStream.write("\tCommitted: " + memoryMXBean.getNonHeapMemoryUsage().getCommitted() + "\n");
    outputStream.write("\tMax:       " + memoryMXBean.getNonHeapMemoryUsage().getMax() + "\n");
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)38 MemoryUsage (java.lang.management.MemoryUsage)13 RuntimeMXBean (java.lang.management.RuntimeMXBean)10 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)7 ThreadMXBean (java.lang.management.ThreadMXBean)7 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Properties (java.util.Properties)3 NotificationEmitter (javax.management.NotificationEmitter)2 ObjectName (javax.management.ObjectName)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Function (com.google.common.base.Function)1 Description (com.google.gerrit.metrics.Description)1 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)1