Example usage for java.lang.management RuntimeMXBean getSpecVendor

List of usage examples for java.lang.management RuntimeMXBean getSpecVendor

Introduction

In this page you can find the example usage for java.lang.management RuntimeMXBean getSpecVendor.

Prototype

public String getSpecVendor();

Source Link

Document

Returns the Java virtual machine specification vendor.

Usage

From source file:net.risesoft.soa.asf.web.controller.SystemController.java

private List<SysInfo> getVMInfo() {
    List list = new ArrayList();
    String group = "3. VM ?";
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    list.add(new SysInfo("BootClassPath", rt.getBootClassPath(), group));
    list.add(new SysInfo("ClassPath", rt.getClassPath(), group));
    list.add(new SysInfo("LibraryPath", rt.getLibraryPath(), group));
    list.add(new SysInfo("ManagementSpecVersion", rt.getManagementSpecVersion(), group));
    list.add(new SysInfo("Name", rt.getName(), group));
    list.add(new SysInfo("SpecName", rt.getSpecName(), group));
    list.add(new SysInfo("SpecVendor", rt.getSpecVendor(), group));
    list.add(new SysInfo("SpecVersion", rt.getSpecVersion(), group));
    list.add(new SysInfo("VmName", rt.getVmName(), group));
    list.add(new SysInfo("VmVendor", rt.getVmVendor(), group));
    list.add(new SysInfo("VmVersion", rt.getVmVersion(), group));
    list.add(new SysInfo("StartTime", DateFormat.getDateTimeInstance().format(new Date(rt.getStartTime())),
            group));/*from  w  ww  . j a va 2s.  c o  m*/

    list.add(new SysInfo("UpTime", this.helper.getUpTimeStr(rt.getUptime()), group));
    list.add(new SysInfo("InputArguments", rt.getInputArguments(), group));

    group = "6. ?";
    Map<String, String> sysProps = rt.getSystemProperties();
    for (Map.Entry entry : sysProps.entrySet()) {
        list.add(new SysInfo((String) entry.getKey(), entry.getValue(), group));
    }
    Collections.sort(list, new Comparator() {
        public int compare(SystemController.SysInfo o1, SystemController.SysInfo o2) {
            String key1 = o1.getKey();
            String key2 = o2.getKey();
            return key1.compareToIgnoreCase(key2);
        }
    });
    return list;
}

From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java

private void runtimeInfo(RuntimeMXBean runtimeMXBean, InformationStringBuilder builder) {
    builder.addSection("Runtime information");
    builder.append(String.format("Name - %s\n", runtimeMXBean.getName()));

    long uptime = runtimeMXBean.getUptime();
    long uptimeInSeconds = uptime / 1000;
    long numberOfHours = uptimeInSeconds / (60 * 60);
    long numberOfMinutes = (uptimeInSeconds / 60) - (numberOfHours * 60);
    long numberOfSeconds = uptimeInSeconds % 60;

    builder.append(String.format("Uptime - %s [About %s hours, %s minutes, %s seconds]\n", uptime,
            numberOfHours, numberOfMinutes, numberOfSeconds));
    builder.append(String.format("Spec Name - %s\n", runtimeMXBean.getSpecName()));
    builder.append(String.format("Spec Vendor - %s\n", runtimeMXBean.getSpecVendor()));
    builder.append(String.format("Spec Version - %s\n", runtimeMXBean.getSpecVersion()));
    builder.addSubSection("Input Arguments")
            .append(asIndentedMultilineValues(runtimeMXBean.getInputArguments()));
    builder.addSubSection("System Properties")
            .append(asIndentedMultilineValues(runtimeMXBean.getSystemProperties()));
    builder.addSubSection("Classpath").append(prettyClassPath(runtimeMXBean.getClassPath()));
    builder.addSubSection("Boot Classpath").append(prettyClassPath(runtimeMXBean.getBootClassPath()));
}

From source file:org.apache.hadoop.hbase.io.TestHeapSize.java

@BeforeClass
public static void beforeClass() throws Exception {
    // Print detail on jvm so we know what is different should below test fail.
    RuntimeMXBean b = ManagementFactory.getRuntimeMXBean();
    LOG.info("name=" + b.getName());
    LOG.info("specname=" + b.getSpecName());
    LOG.info("specvendor=" + b.getSpecVendor());
    LOG.info("vmname=" + b.getVmName());
    LOG.info("vmversion=" + b.getVmVersion());
    LOG.info("vmvendor=" + b.getVmVendor());
    Map<String, String> p = b.getSystemProperties();
    LOG.info("properties=" + p);
}

From source file:org.craftercms.commons.monitoring.VersionMonitor.java

@SuppressWarnings("unchecked")
private void initRuntime() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    java_version = runtime.getSpecVersion();
    java_vendor = runtime.getSpecVendor();
    java_runtime = runtime.getSpecName();
    java_vm = runtime.getVmName();/*  w  ww.ja  v a 2s.  com*/
    jvm_input_arguments = StringUtils.join(runtime.getInputArguments());
    jvm_implementation_version = runtime.getVmVersion();
    jvm_vendor = runtime.getVmVendor();
    jvm_version = runtime.getSpecVersion();
}

From source file:org.fluentd.jvmwatcher.data.JvmWatchState.java

/**
 * @param clientPrixy/*w w  w. j a  va  2  s.c  o  m*/
 * @return
 */
public static JvmWatchState makeJvmWatchState(JvmClientProxy clientProxy) {
    // null check
    if (null == clientProxy) {
        return null;
    }
    if (null == clientProxy.getLocalJvmInfo()) {
        return null;
    }

    // create data object
    JvmWatchState ret = new JvmWatchState();

    // set Local JVM Information
    ret.commandLine_ = clientProxy.getLocalJvmInfo().getCommandLine_();
    ret.displayName_ = clientProxy.getLocalJvmInfo().getDisplayName();
    ret.jvmId_ = clientProxy.getLocalJvmInfo().getJvmid();
    ret.shortName_ = clientProxy.getLocalJvmInfo().getShortName();

    // create log line array
    ret.stateLog_ = new ArrayList<JvmStateLog>();

    // set JVM information
    try {
        // CompilationMXBean
        CompilationMXBean compilationBean = clientProxy.getCompilationMXBean();
        if (null != compilationBean) {
            ret.jitName_ = compilationBean.getName();
        }

        // OperatingSystemMXBean
        OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean();
        if (null != OpeSysBean) {
            ret.osArch_ = OpeSysBean.getArch();
            ret.osName_ = OpeSysBean.getName();
            ret.osVersion_ = OpeSysBean.getVersion();
        }

        // RuntimeMXBean
        RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean();
        if (null != runtimeBean) {
            ret.jvmStartTime_ = runtimeBean.getStartTime();
            ret.jvmRuntimeName_ = runtimeBean.getName();
            ret.vmName_ = runtimeBean.getVmName();
            ret.vmVender_ = runtimeBean.getVmVendor();
            ret.vmVersion_ = runtimeBean.getVmVersion();
            ret.specName_ = runtimeBean.getSpecName();
            ret.specVender_ = runtimeBean.getSpecVendor();
            ret.specVersion_ = runtimeBean.getSpecVersion();
        }
    } catch (IOException ex) {
        log.error("get MXBean error.", ex);
        // close JvmClientProxy
        clientProxy.disconnect();
    } catch (Exception ex) {
        log.error("get MXBean error.", ex);
        // close JvmClientProxy
        clientProxy.disconnect();
    }

    return ret;
}

From source file:org.jwebsocket.plugins.system.SystemPlugIn.java

private void getJVMInfo(WebSocketConnector aConnector, Token aToken) {
    // check if user is allowed to run 'getjvminfo' command
    if (!hasAuthority(aConnector, NS_SYSTEM + ".getjvminfo")) {
        sendToken(aConnector, aConnector, createAccessDenied(aToken));
        return;/*from  w  w  w  .j  av a2s.com*/
    }

    Token lResponse = createResponse(aToken);
    RuntimeMXBean lBean = ManagementFactory.getRuntimeMXBean();
    MemoryMXBean lMemory = ManagementFactory.getMemoryMXBean();
    OperatingSystemMXBean lOS = ManagementFactory.getOperatingSystemMXBean();

    lResponse.setMap("data", new MapAppender().append("inputArguments", lBean.getInputArguments())
            .append("libraryPath", lBean.getLibraryPath())
            .append("managementSpecVersion", lBean.getManagementSpecVersion()).append("name", lBean.getName())
            .append("specName", lBean.getSpecName()).append("specVendor", lBean.getSpecVendor())
            .append("specVersion", lBean.getSpecVersion()).append("startTime", lBean.getStartTime())
            .append("systemProperties", lBean.getSystemProperties()).append("uptime", lBean.getUptime())
            .append("vmName", lBean.getVmName()).append("vmVendor", lBean.getVmVendor())
            .append("vmVersion", lBean.getVmVersion()).append("classPath", lBean.getClassPath())
            .append("osArch", lOS.getArch()).append("osAvailableProcessors", lOS.getAvailableProcessors())
            .append("osName", lOS.getName()).append("osVersion", lOS.getVersion())
            .append("osLoadAverage", lOS.getSystemLoadAverage())
            .append("heapMemoryUsed", lMemory.getHeapMemoryUsage().getUsed())
            .append("heapMemoryMax", lMemory.getHeapMemoryUsage().getMax())
            .append("heapMemoryInit", lMemory.getHeapMemoryUsage().getInit())
            .append("nonheapMemoryInit", lMemory.getNonHeapMemoryUsage().getInit())
            .append("nonheapMemoryMax", lMemory.getNonHeapMemoryUsage().getMax())
            .append("nonheapMemoryUsed", lMemory.getNonHeapMemoryUsage().getUsed()).getMap());

    sendToken(aConnector, lResponse);
}

From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java

public String runCommand(long userId, long companyId, String mode, String command) {
    String response = "";
    Date startDate = new Date();
    if ("server".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\t\tShow this help message\n"
                    + "version\t\t Display the version of the Liferay Portal\n"
                    + "date\t\t\tDisplay the date and time of the database server\n"
                    + "uptime\t\t  Display the uptime of the portal\n" + "adduser\t\t Add a new user";
        } else if ("version".equalsIgnoreCase(command)) {
            response = ReleaseInfo.getReleaseInfo() + " running on "
                    + StringUtil.upperCaseFirstLetter(ServerDetector.getServerId());
        } else if ("date".equalsIgnoreCase(command)) {
            response = new Date().toString();
        } else if ("uptime".equalsIgnoreCase(command)) {
            response = getUptime(PortalUtil.getUptime().getTime());
        } else if (command.toLowerCase().startsWith("adduser")) {
            response = handleAddUser(userId, companyId, command);
        }//  ww w .ja va 2 s .co  m
    } else if ("db".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\t\tShow this help message\n"
                    + "version\t\t Display the version of the database\n"
                    + "date\t\t\tDisplay the date and time of the database server\n"
                    + "<sql query>\t Display result of any SQL query";
        } else if ("date".equalsIgnoreCase(command)) {
            response = runSQLQuery("select now() \"\"");
        } else if ("version".equalsIgnoreCase(command)) {
            response = runSQLQuery(
                    "select '" + DBFactoryUtil.getDBFactory().getDB().getType() + "' as '', version() ''");
        } else
            response = runSQLQuery(command);
    } else if ("jvm".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\tShow this help message\n"
                    + "mem\t\t Display memory usage of the JVM\n"
                    + "osinfo\t  Display operating system info of the running JVM\n"
                    + "vminfo\t  Display VM info";
        } else if ("mem".equalsIgnoreCase(command)) {
            MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
            response = "Heap        : " + mem.getHeapMemoryUsage().toString();
            response += "\nNon Heap    : " + mem.getNonHeapMemoryUsage().toString();
            response += "\nFinalization: " + mem.getObjectPendingFinalizationCount() + " objects pending";
        } else if ("osinfo".equalsIgnoreCase(command)) {
            OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
            response = os.getName() + "[" + os.getArch() + "] " + os.getVersion() + " ("
                    + os.getAvailableProcessors() + " processors)";
            response += "\nLoad Average: " + os.getSystemLoadAverage();
        } else if ("vminfo".equalsIgnoreCase(command)) {
            RuntimeMXBean vm = ManagementFactory.getRuntimeMXBean();
            response = vm.getVmName() + " " + vm.getVmVersion() + " by " + vm.getVmVendor();
            response += "\n" + vm.getSpecName() + " " + vm.getSpecVersion() + " by " + vm.getSpecVendor();
            response += "\nStarted at: " + DateFormat.getInstance().format(new Date(vm.getStartTime()));
            response += "\nUptime    : " + getUptime(vm.getStartTime());
        } else {
            response = UNRECOGNIZED_COMMAND;
        }
    }
    // save command to database if it is not 'help'
    if (!command.startsWith("help")) {
        try {
            // add to history
            Date endDate = new Date();
            long id = CounterLocalServiceUtil.increment(CommandHistory.class.getName());
            CommandHistory history = CommandHistoryLocalServiceUtil.createCommandHistory(id);
            history.setCommand(command);
            history.setExecutionDate(startDate);
            history.setExecutionTime(endDate.getTime() - startDate.getTime());
            history.setMode(mode);
            history.setUserId(userId);
            CommandHistoryLocalServiceUtil.updateCommandHistory(history);
            // TODO: delete the oldest entry > MAX_HISTORY_SIZE
            // get the history size
            long historySize = 100;
            List<CommandHistory> historyList = CommandHistoryLocalServiceUtil
                    .findCommandHistoryByUserId(userId);
            if (historyList.size() >= historySize) {
                CommandHistoryLocalServiceUtil.deleteCommandHistory(historyList.get(0));
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
    return response;
}