Search in sources :

Example 81 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 82 with 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)");
}
Also used : ProtobufSystemInfo(org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo) MemoryMXBean(java.lang.management.MemoryMXBean) Test(org.junit.Test)

Example 83 with MemoryMXBean

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();
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Example 84 with MemoryMXBean

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;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryMXBean(java.lang.management.MemoryMXBean) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)84 MemoryUsage (java.lang.management.MemoryUsage)30 RuntimeMXBean (java.lang.management.RuntimeMXBean)18 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)12 IOException (java.io.IOException)11 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)11 ThreadMXBean (java.lang.management.ThreadMXBean)11 NotificationEmitter (javax.management.NotificationEmitter)10 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)7 ObjectName (javax.management.ObjectName)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Properties (java.util.Properties)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Notification (javax.management.Notification)5 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)4