Example usage for java.lang.management RuntimeMXBean getVmName

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

Introduction

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

Prototype

public String getVmName();

Source Link

Document

Returns the Java virtual machine implementation name.

Usage

From source file:org.apache.hadoop.hbase.regionserver.MemStore.java

/**
 * Code to help figure if our approximation of object heap sizes is close
 * enough.  See hbase-900.  Fills memstores then waits so user can heap
 * dump and bring up resultant hprof in something like jprofiler which
 * allows you get 'deep size' on objects.
 * @param args main args//from   w w w .j  a va2 s  .com
 */
public static void main(String[] args) {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + runtime.getVmVendor() + ", vmVersion="
            + runtime.getVmVersion());
    LOG.info("vmInputArguments=" + runtime.getInputArguments());
    MemStore memstore1 = new MemStore();
    // TODO: x32 vs x64
    long size = 0;
    final int count = 10000;
    byte[] fam = Bytes.toBytes("col");
    byte[] qf = Bytes.toBytes("umn");
    byte[] empty = new byte[0];
    for (int i = 0; i < count; i++) {
        // Give each its own ts
        size += memstore1.add(new KeyValue(Bytes.toBytes(i), fam, qf, i, empty));
    }
    LOG.info("memstore1 estimated size=" + size);
    for (int i = 0; i < count; i++) {
        size += memstore1.add(new KeyValue(Bytes.toBytes(i), fam, qf, i, empty));
    }
    LOG.info("memstore1 estimated size (2nd loading of same data)=" + size);
    // Make a variably sized memstore.
    MemStore memstore2 = new MemStore();
    for (int i = 0; i < count; i++) {
        size += memstore2.add(new KeyValue(Bytes.toBytes(i), fam, qf, i, new byte[i]));
    }
    LOG.info("memstore2 estimated size=" + size);
    final int seconds = 30;
    LOG.info("Waiting " + seconds + " seconds while heap dump is taken");
    for (int i = 0; i < seconds; i++) {
        // Thread.sleep(1000);
    }
    LOG.info("Exiting.");
}

From source file:org.apache.syncope.core.logic.SyncopeLogic.java

private void initSystemInfo() {
    if (SYSTEM_INFO == null) {
        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

        SYSTEM_INFO = new SystemInfo();
        try {//from  w w  w  .java  2s  . c  om
            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());
    }
}

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();
    jvm_input_arguments = StringUtils.join(runtime.getInputArguments());
    jvm_implementation_version = runtime.getVmVersion();
    jvm_vendor = runtime.getVmVendor();//w ww. ja v a  2s  . c  o m
    jvm_version = runtime.getSpecVersion();
}

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

/**
 * @param clientPrixy/* w  w  w.j a va  2s .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.jahia.tools.jvm.ThreadMonitor.java

private void setDumpPrefix() {
    RuntimeMXBean rmbean = ManagementFactory.getRuntimeMXBean();
    dumpPrefix += rmbean.getVmName() + " (" + rmbean.getVmVersion() + ")\n";
}

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;//  w  w w.j  a  va2s .  c  om
    }

    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);
        }/*from  w  ww .  jav a 2 s  .c om*/
    } 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;
}

From source file:org.novelang.outfit.shell.JavaShellTest.java

private static String queryJvmName(final JavaShell javaShell) throws IOException, InterruptedException {
    final RuntimeMXBean runtimeMXBean = javaShell.getManagedBean(RuntimeMXBean.class,
            JavaShellTools.RUNTIME_MX_BEAN_OBJECTNAME);
    final String virtualMachineName = runtimeMXBean.getVmName();
    return virtualMachineName;
}