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 sonarqube by SonarSource.
the class JvmStateSectionTest method should_hide_attributes_without_values.
@Test
public void should_hide_attributes_without_values() {
MemoryMXBean memoryBean = mock(MemoryMXBean.class, Mockito.RETURNS_DEEP_STUBS);
when(memoryBean.getHeapMemoryUsage().getCommitted()).thenReturn(-1L);
JvmStateSection underTest = new JvmStateSection(PROCESS_NAME);
ProtobufSystemInfo.Section section = underTest.toProtobuf(memoryBean);
assertThat(section.getAttributesList()).extracting("key").isNotEmpty().doesNotContain("Heap Committed (MB)");
}
use of java.lang.management.MemoryMXBean in project Payara by payara.
the class WarCheck1 method call.
@Override
public HealthCheckResponse call() {
MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
long memUsed = memBean.getHeapMemoryUsage().getUsed();
long memMax = memBean.getHeapMemoryUsage().getMax();
return HealthCheckResponse.named(WarCheck1.class.getSimpleName() + " Liveness Check").withData("memory used", memUsed).withData("memory max", memMax).status(memUsed < memMax * 0.9).build();
}
use of java.lang.management.MemoryMXBean in project openremote by openremote.
the class JvmHealthStatusProvider method getHealthStatus.
@Override
public Object getHealthStatus() {
ObjectNode objectValue = ValueUtil.createJsonObject();
com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
objectValue.put("startTimeMillis", runtimeMXBean.getStartTime());
objectValue.put("upTimeMillis", runtimeMXBean.getUptime());
objectValue.put("processLoadPercentage", operatingSystemMXBean.getProcessCpuLoad() * 100);
objectValue.put("heapMemoryUsageMB", memoryMXBean.getHeapMemoryUsage().getUsed() / (1024F * 1024F));
objectValue.put("nonHeapMemoryUsageMB", memoryMXBean.getNonHeapMemoryUsage().getUsed() / (1024F * 1024F));
objectValue.put("peakThreadCount", threadMXBean.getPeakThreadCount());
objectValue.put("threadCount", threadMXBean.getThreadCount());
objectValue.put("daemonThreadCount", threadMXBean.getDaemonThreadCount());
return objectValue;
}
Aggregations