Search in sources :

Example 46 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project Payara by payara.

the class RuntimeInfo method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    report.setActionExitCode(SUCCESS);
    top = report.getTopMessagePart();
    logger = context.getLogger();
    boolean javaEnabledOnCmd = Boolean.parseBoolean(ctx.getArguments().getProperty("-debug"));
    javaConfig = config.getJavaConfig();
    jpdaEnabled = javaEnabledOnCmd || Boolean.parseBoolean(javaConfig.getDebugEnabled());
    int debugPort = parsePort(javaConfig.getDebugOptions());
    top.addProperty("debug", Boolean.toString(jpdaEnabled));
    top.addProperty("debugPort", Integer.toString(debugPort));
    final OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    top.addProperty("os.arch", osBean.getArch());
    top.addProperty("os.name", osBean.getName());
    top.addProperty("os.version", osBean.getVersion());
    top.addProperty("availableProcessorsCount", "" + osBean.getAvailableProcessors());
    // also if we are not on a sun jdk, we will not return this attribute.
    if (!OS.isAix()) {
        try {
            final Method jm = osBean.getClass().getMethod("getTotalPhysicalMemorySize");
            AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    if (!jm.isAccessible()) {
                        jm.setAccessible(true);
                    }
                    return null;
                }
            });
            top.addProperty("totalPhysicalMemorySize", "" + jm.invoke(osBean));
        } catch (Exception ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }
    RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
    top.addProperty("startTimeMillis", "" + rmxb.getStartTime());
    top.addProperty("pid", "" + rmxb.getName());
    checkDtrace();
    setDasName();
    top.addProperty("java.vm.name", System.getProperty("java.vm.name"));
    // setRestartable();
    reportMessage.append(Strings.get("runtime.info.debug", jpdaEnabled ? "enabled" : "not enabled"));
    report.setMessage(reportMessage.toString());
}
Also used : Method(java.lang.reflect.Method) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 47 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project Payara by payara.

the class SummaryReporter method getSummaryReport.

public String getSummaryReport() throws RuntimeException {
    try {
        final StringBuilderNewLineAppender sb = new StringBuilderNewLineAppender(new StringBuilder());
        final OperatingSystemMXBean os = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
        sb.append(getOSInfo(os));
        final RuntimeMXBean rt = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
        sb.append(getArguments(rt));
        sb.append(getVMInfo(rt));
        return (sb.toString(secretProperty));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 48 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project traccar by tananaev.

the class Main method logSystemInfo.

public static void logSystemInfo() {
    try {
        OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
        LOGGER.info("Operating system" + " name: " + operatingSystemBean.getName() + " version: " + operatingSystemBean.getVersion() + " architecture: " + operatingSystemBean.getArch());
        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        LOGGER.info("Java runtime" + " name: " + runtimeBean.getVmName() + " vendor: " + runtimeBean.getVmVendor() + " version: " + runtimeBean.getVmVersion());
        MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
        LOGGER.info("Memory limit" + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb" + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");
        LOGGER.info("Character encoding: " + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());
    } catch (Exception error) {
        LOGGER.warn("Failed to get system info");
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 49 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project pentaho-kettle by pentaho.

the class GetStatusServlet method getSystemInfo.

private static void getSystemInfo(SlaveServerStatus serverStatus) {
    OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean();
    RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean();
    int cores = Runtime.getRuntime().availableProcessors();
    long freeMemory = Runtime.getRuntime().freeMemory();
    long totalMemory = Runtime.getRuntime().totalMemory();
    String osArch = operatingSystemMXBean.getArch();
    String osName = operatingSystemMXBean.getName();
    String osVersion = operatingSystemMXBean.getVersion();
    double loadAvg = operatingSystemMXBean.getSystemLoadAverage();
    int threadCount = threadMXBean.getThreadCount();
    long allThreadsCpuTime = 0L;
    long[] threadIds = threadMXBean.getAllThreadIds();
    for (int i = 0; i < threadIds.length; i++) {
        allThreadsCpuTime += threadMXBean.getThreadCpuTime(threadIds[i]);
    }
    long uptime = runtimeMXBean.getUptime();
    serverStatus.setCpuCores(cores);
    serverStatus.setCpuProcessTime(allThreadsCpuTime);
    serverStatus.setUptime(uptime);
    serverStatus.setThreadCount(threadCount);
    serverStatus.setLoadAvg(loadAvg);
    serverStatus.setOsName(osName);
    serverStatus.setOsVersion(osVersion);
    serverStatus.setOsArchitecture(osArch);
    serverStatus.setMemoryFree(freeMemory);
    serverStatus.setMemoryTotal(totalMemory);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 50 with OperatingSystemMXBean

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

the class ReportController method logCPU.

private void logCPU(Report report) {
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    report.setNumberOfProcessors(bean.getAvailableProcessors());
    // NOI18N
    String unknown = "unknown";
    String str = // NOI18N
    System.getProperty("os.name", unknown) + ", " + System.getProperty("os.version", unknown) + // NOI18N
    ", " + // NOI18N
    System.getProperty("os.arch", unknown);
    report.setOs(str);
}
Also used : 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