Search in sources :

Example 71 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project openj9 by eclipse.

the class TestManagementFactory method testGetOperatingSystemMXBean.

@Test
public final void testGetOperatingSystemMXBean() {
    OperatingSystemMXBean ob1 = ManagementFactory.getOperatingSystemMXBean();
    AssertJUnit.assertNotNull(ob1);
    // Verify that there is only instance of the this bean
    OperatingSystemMXBean ob2 = ManagementFactory.getOperatingSystemMXBean();
    AssertJUnit.assertNotNull(ob2);
    AssertJUnit.assertSame(ob1, ob2);
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.testng.annotations.Test)

Example 72 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project openj9 by eclipse.

the class TestManagementFactory method testOperatingSystemMXBeanProxy.

@Test
public void testOperatingSystemMXBeanProxy() {
    try {
        OperatingSystemMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=OperatingSystem", OperatingSystemMXBean.class);
        AssertJUnit.assertNotNull(proxy);
        AssertJUnit.assertNotNull(proxy.toString());
        AssertJUnit.assertEquals("java.lang:type=OperatingSystem", proxy.getObjectName().toString());
        AssertJUnit.assertEquals(proxy.getArch(), ManagementFactory.getOperatingSystemMXBean().getArch());
        AssertJUnit.assertEquals(proxy.getName(), ManagementFactory.getOperatingSystemMXBean().getName());
        AssertJUnit.assertEquals(proxy.getVersion(), ManagementFactory.getOperatingSystemMXBean().getVersion());
        AssertJUnit.assertEquals(proxy.getAvailableProcessors(), ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors());
    } catch (IOException e) {
        Assert.fail("Unexpected IOException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.testng.annotations.Test)

Example 73 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project rocketmq by apache.

the class StoreUtil method getTotalPhysicalMemorySize.

@SuppressWarnings("restriction")
public static long getTotalPhysicalMemorySize() {
    long physicalTotal = 1024 * 1024 * 1024 * 24L;
    OperatingSystemMXBean osmxb = ManagementFactory.getOperatingSystemMXBean();
    if (osmxb instanceof com.sun.management.OperatingSystemMXBean) {
        physicalTotal = ((com.sun.management.OperatingSystemMXBean) osmxb).getTotalPhysicalMemorySize();
    }
    return physicalTotal;
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 74 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project openolat by klemens.

the class SystemWebService method getEnvironnementXml.

/**
 * Return some informations about the environment.
 * @response.representation.200.qname {http://www.example.com}environmentVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc A short summary of the number of classes
 * @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_ENVVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param request The HTTP request
 * @return The informations about the environment
 */
@GET
@Path("environment")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getEnvironnementXml(@Context HttpServletRequest request) {
    if (!isAdminOrSystem(request)) {
        return null;
    }
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    EnvironmentInformationsVO vo = new EnvironmentInformationsVO(os, runtime);
    return Response.ok(vo).build();
}
Also used : EnvironmentInformationsVO(org.olat.restapi.system.vo.EnvironmentInformationsVO) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 75 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project vertigo by KleeGroup.

the class SystemMetricsProvider method getSystemMetrics.

@Metrics
public List<Metric> getSystemMetrics() {
    final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    final Runtime runtime = Runtime.getRuntime();
    // ---
    final Metric memoryUsed = buildMetric("memoryUsed", () -> Long.valueOf(runtime.totalMemory() / 1024 / 1024).doubleValue());
    final Metric memoryUsedPercent = buildMetric("memoryUsedPercent", () -> Long.valueOf(runtime.totalMemory()).doubleValue() / runtime.maxMemory() * 100);
    final Metric cpuUsage = buildMetric("cpuUsage", () -> operatingSystemMXBean.getSystemLoadAverage());
    // ---
    return Arrays.asList(memoryUsed, memoryUsedPercent, cpuUsage);
}
Also used : Metric(io.vertigo.commons.analytics.metric.Metric) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Metrics(io.vertigo.commons.analytics.metric.Metrics)

Aggregations

OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)89 RuntimeMXBean (java.lang.management.RuntimeMXBean)27 Method (java.lang.reflect.Method)20 IOException (java.io.IOException)15 MemoryMXBean (java.lang.management.MemoryMXBean)12 MemoryUsage (java.lang.management.MemoryUsage)8 ThreadMXBean (java.lang.management.ThreadMXBean)8 HashMap (java.util.HashMap)8 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)7 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 Status (com.alibaba.dubbo.common.status.Status)5 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 Test (org.testng.annotations.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 UnknownHostException (java.net.UnknownHostException)4 Date (java.util.Date)4 ExtendedOperatingSystemMXBeanImpl (com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl)3