Search in sources :

Example 66 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project activemq-artemis by apache.

the class DeadLetterAddressTest method testLargeMessageFileLeak.

@Test
public void testLargeMessageFileLeak() throws Exception {
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    // only run this on *nix systems which will have the com.sun.management.UnixOperatingSystemMXBean (needed to check open file count)
    Assume.assumeTrue(os instanceof UnixOperatingSystemMXBean);
    long fdBaseline = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
    final int SIZE = 2 * 1024;
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    SimpleString adName = new SimpleString("ad1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
    SimpleString dlq = new SimpleString("DLQ1");
    clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(adName, qName, null, false);
    for (int i = 0; i < 10; i++) {
        ClientProducer producer = clientSession.createProducer(adName);
        ClientMessage clientFile = clientSession.createMessage(true);
        clientFile.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(SIZE));
        producer.send(clientFile);
        clientSession.start();
        ClientConsumer clientConsumer = clientSession.createConsumer(qName);
        ClientMessage m = clientConsumer.receive(500);
        m.acknowledge();
        Assert.assertNotNull(m);
        // force a cancel
        clientSession.rollback();
        m = clientConsumer.receiveImmediate();
        Assert.assertNull(m);
        clientConsumer.close();
    }
    assertTrue("File descriptors are leaking", ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount() - fdBaseline <= 0);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Test(org.junit.Test)

Example 67 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project OpenOLAT by OpenOLAT.

the class RuntimeWebService method getSystemSummaryVO.

/**
 * Return the statistics about runtime: uptime, classes loaded, memory
 * summary, threads count...
 *
 * @response.representation.200.qname {http://www.example.com}runtimeVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The version of the instance
 * @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_RUNTIMEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param request The HTTP request
 * @return The informations about runtime, uptime, classes loaded, memory summary...
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSystemSummaryVO() {
    RuntimeStatisticsVO stats = new RuntimeStatisticsVO();
    stats.setMemory(getMemoryStatisticsVO());
    stats.setThreads(getThreadStatisticsVO());
    stats.setClasses(getClasseStatisticsVO());
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    stats.setSystemLoadAverage(os.getSystemLoadAverage());
    stats.setStartTime(new Date(runtime.getStartTime()));
    stats.setUpTime(runtime.getUptime());
    return Response.ok(stats).build();
}
Also used : RuntimeStatisticsVO(org.olat.restapi.system.vo.RuntimeStatisticsVO) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Date(java.util.Date) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 68 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project OpenOLAT by OpenOLAT.

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 69 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project ffx by mjschnie.

the class Resources method logResources.

public static void logResources() {
    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        Runtime runtime = Runtime.getRuntime();
        runtime.runFinalization();
        runtime.gc();
        long MB = 1024 * 1024;
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        if (os instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixOS = (UnixOperatingSystemMXBean) os;
            // CPU Time and Average System Load.
            Long time = unixOS.getProcessCpuTime();
            sb.append(format("\n Total CPU time:         %6.2f (sec)", time * 1.0e-9));
            double systemLoadAve = unixOS.getSystemLoadAverage();
            if (systemLoadAve >= 0) {
                sb.append(format("\n System load average:    %6.2f", systemLoadAve));
            }
            // File handle use.
            long open = unixOS.getOpenFileDescriptorCount();
            long allowed = unixOS.getMaxFileDescriptorCount();
            sb.append(format("\n Open file handles:      %6d of %6d allowed", open, allowed));
            // System Memory.
            long freePhysical = unixOS.getFreePhysicalMemorySize() / MB;
            long totalPhysical = unixOS.getTotalPhysicalMemorySize() / MB;
            long freeSwap = unixOS.getFreeSwapSpaceSize() / MB;
            long totalSwap = unixOS.getTotalSwapSpaceSize() / MB;
            sb.append(format("\n System memory:          %6d MB free out of %6d MB", freePhysical, totalPhysical));
            sb.append(format("\n System swap space:      %6d MB free out of %6d MB", freeSwap, totalSwap));
        // Log CPU usage.
        // double sysCPULoad = unixOS.getSystemCpuLoad() * 100.0;
        // double procCPULoad = unixOS.getProcessCpuLoad() * 100.0;
        /**
         * if (procCPULoad >= 0) { sb.append(format("\n JVM CPU load:
         * %6.3f%%", procCPULoad)); } if (sysCPULoad >= 0) {
         * sb.append(format("\n System CPU load: %6.3f%%", sysCPULoad));
         * }
         */
        }
        // JVM Memory.
        sb.append(format("\n JVM memory:             %6d MB free out of %6d MB\n", runtime.freeMemory() / MB, runtime.totalMemory() / MB));
        logger.info(sb.toString());
    }
}
Also used : UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean)

Example 70 with OperatingSystemMXBean

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

the class SyncopeLogic method initSystemInfo.

private void initSystemInfo() {
    if (SYSTEM_INFO == null) {
        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        SYSTEM_INFO = new SystemInfo();
        try {
            SYSTEM_INFO.setHostname(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException e) {
            LOG.error("Could not get host name", e);
        }
        SYSTEM_INFO.setOs(operatingSystemMXBean.getName() + " " + operatingSystemMXBean.getVersion() + " " + operatingSystemMXBean.getArch());
        SYSTEM_INFO.setAvailableProcessors(operatingSystemMXBean.getAvailableProcessors());
        SYSTEM_INFO.setJvm(runtimeMXBean.getVmName() + " " + System.getProperty("java.version") + " " + runtimeMXBean.getVmVendor());
        SYSTEM_INFO.setStartTime(runtimeMXBean.getStartTime());
    }
}
Also used : SystemInfo(org.apache.syncope.common.lib.info.SystemInfo) UnknownHostException(java.net.UnknownHostException) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

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