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;
}
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();
}
}
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");
}
Aggregations