Example usage for java.lang.management ManagementFactory getRuntimeMXBean

List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getRuntimeMXBean.

Prototype

public static RuntimeMXBean getRuntimeMXBean() 

Source Link

Document

Returns the managed bean for the runtime system of the Java virtual machine.

Usage

From source file:com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *///from w w  w . j  av a2s .  c o m
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    setCpuCount("" + osBean.getAvailableProcessors());
    double usage = com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog
            .getCPUUsage(getSession());
    usage = Math.round(usage * 100) / 100;
    setCpuUsage("" + 100 * usage + "%");

    setLoadedClassesCount("" + classesBean.getLoadedClassCount());
    setUnloadedClassesCount("" + classesBean.getUnloadedClassCount());
    setTotalLoadedClassesCount("" + classesBean.getTotalLoadedClassCount());

    setThreadsCount("" + threadBean.getThreadCount());
    setThreadsStartedCount("" + threadBean.getTotalStartedThreadCount());
    setThreadsPeakCount("" + threadBean.getPeakThreadCount());
    setThreadsDaemonCount("" + threadBean.getDaemonThreadCount());

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

    setParamCloseLink(getJsp().link(
            "/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/cpu_and_threads.jsp"));

}

From source file:org.jumpmind.symmetric.util.SnapshotUtil.java

protected static void writeRuntimeStats(ISymmetricEngine engine, File tmpDir) {
    FileOutputStream fos = null;// w  w  w . j a  v a2  s.  c o  m
    try {
        fos = new FileOutputStream(new File(tmpDir, "runtime-stats.properties"));
        Properties runtimeProperties = new Properties();
        runtimeProperties.setProperty("engine.is.started", Boolean.toString(engine.isStarted()));
        runtimeProperties.setProperty("server.time", new Date().toString());
        runtimeProperties.setProperty("database.time",
                new Date(engine.getSymmetricDialect().getDatabaseTime()).toString());
        runtimeProperties.setProperty("unrouted.data.count",
                Long.toString(engine.getRouterService().getUnroutedDataCount()));
        runtimeProperties.setProperty("outgoing.errors.count",
                Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesInError()));
        runtimeProperties.setProperty("outgoing.tosend.count",
                Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesUnsent()));
        runtimeProperties.setProperty("incoming.errors.count",
                Long.toString(engine.getIncomingBatchService().countIncomingBatchesInError()));

        List<DataGap> gaps = engine.getDataService().findDataGaps();
        runtimeProperties.setProperty("data.gap.count", Long.toString(gaps.size()));
        if (gaps.size() > 0) {
            runtimeProperties.setProperty("data.gap.start.id", Long.toString(gaps.get(0).getStartId()));
            runtimeProperties.setProperty("data.gap.end.id",
                    Long.toString(gaps.get(gaps.size() - 1).getEndId()));

        }

        RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
        List<String> arguments = runtimeMxBean.getInputArguments();
        runtimeProperties.setProperty("jvm.arguments", arguments.toString());

        runtimeProperties.store(fos, "runtime-stats.properties");
    } catch (IOException e) {
        log.warn("Failed to export runtime-stats information", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:com.photon.phresco.util.Utility.java

public static boolean executeStreamconsumer(String command, String workingDir, String baseDir,
        String actionType) {/*from w  w w .j  a va 2s  .c  o m*/
    BufferedReader in = null;
    fillErrorIdentifiers();
    int ok = 0;
    try {
        final StringBuffer bufferErrBuffer = new StringBuffer();
        final StringBuffer bufferOutBuffer = new StringBuffer();
        Commandline commandLine = new Commandline(command);
        commandLine.setWorkingDirectory(workingDir);
        String processName = ManagementFactory.getRuntimeMXBean().getName();
        String[] split = processName.split("@");
        String processId = split[0].toString();
        Utility.writeProcessid(baseDir, actionType, processId);
        ok = CommandLineUtils.executeCommandLine(commandLine, new StreamConsumer() {
            public void consumeLine(String line) {
                System.out.println(line);
                status = true;
                if (isError(line)) {
                    bufferErrBuffer.append(line);
                }
                if (line.startsWith("[ERROR]")) {
                    status = false;
                }
                bufferOutBuffer.append(line);
            }
        }, new StreamConsumer() {
            public void consumeLine(String line) {
                System.out.println(line);
                bufferErrBuffer.append(line);
            }
        });
    } catch (CommandLineException e) {
        e.printStackTrace();
    } finally {
        if (ok != 0) {
            status = false;
        }
        Utility.closeStream(in);
    }
    return status;
}

From source file:com.l2jfree.L2Config.java

protected static void applicationLoaded(String appName, String[] versionInfo, boolean dumpHeap) {
    Util.printSection("Summary");
    for (String line : versionInfo)
        _log.info(line);/*from   w w w .  j a  v a  2  s .  co  m*/
    _log.info("Operating System: " + Util.getOSName() + " " + Util.getOSVersion() + " " + Util.getOSArch());
    _log.info("Available CPUs: " + Util.getAvailableProcessors());

    System.gc();
    System.runFinalization();

    for (String line : Util.getMemUsage())
        _log.info(line);

    _log.info("Server loaded in " + Util.formatNumber(ManagementFactory.getRuntimeMXBean().getUptime())
            + " milliseconds.");

    if (dumpHeap && !L2Config.LAUNCHED_FROM_IDE)
        L2System.dumpHeap(true);

    Util.printSection(appName);

    Startup.onStartup();
}

From source file:it.ldp.pingscheduler.PingSchedulerGUI.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    System.out.println("start");
    System.out.println("nameprocess:" + ManagementFactory.getRuntimeMXBean().getName());
    String pid = ManagementFactory.getRuntimeMXBean().getName();
    pid = StringUtils.substringBefore(pid, "@");
    Integer min = new Integer(jComboIntervallo.getSelectedItem().toString());

    String nping = jComboPing.getSelectedItem().toString();
    String loglevel = jComboLogLevel.getSelectedItem().toString();
    String periodo = jComboPeriodo.getSelectedItem().toString();

    PingJobScheduler.dowork(min, nping, loglevel, periodo);
    jLabel2.setText("ping scheduler started pid: " + pid);
}

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:de.nmichael.efa.Daten.java

public static void iniBase(int _applID) {
    if (Logger.isTraceOn(Logger.TT_CORE, 9) || Logger.isDebugLoggingActivatedByCommandLine()) {
        Logger.log(Logger.DEBUG, Logger.MSG_CORE_STARTUPINITIALIZATION, "iniBase(" + _applID + ")");
    }/*from  w w  w.j av a 2  s .  c  o  m*/
    project = null;
    fileSep = System.getProperty("file.separator");
    javaVersion = System.getProperty("java.version");
    jvmVersion = System.getProperty("java.vm.version");
    osName = System.getProperty("os.name");
    osVersion = System.getProperty("os.version");
    userHomeDir = System.getProperty("user.home");
    if (userHomeDir == null) {
        userHomeDir = "";
    }
    if (!userHomeDir.endsWith(fileSep)) {
        userHomeDir += fileSep;
    }
    userName = System.getProperty("user.name");
    applID = _applID;
    switch (applID) {
    case APPL_EFABASE:
        applName = APPLNAME_EFA;
        break;
    case APPL_EFABH:
        applName = APPLNAME_EFADIREKT;
        break;
    case APPL_CLI:
        applName = APPLNAME_CLI;
        break;
    case APPL_DRV:
        applName = APPLNAME_DRV;
        break;
    case APPL_EMIL:
        applName = APPLNAME_EMIL;
        break;
    case APPL_ELWIZ:
        applName = APPLNAME_ELWIZ;
        break;
    case APPL_EDDI:
        applName = APPLNAME_EDDI;
        break;
    }
    efaStartTime = System.currentTimeMillis();

    try {
        // ManagementFactory.getRuntimeMXBean().getName() == "12345@localhost" or similar (not
        // guaranteed by VM Spec!)
        applPID = EfaUtil.int2String(EfaUtil.stringFindInt(ManagementFactory.getRuntimeMXBean().getName(), 0),
                5);
    } catch (Exception e) {
        applPID = "00000";
    }
}

From source file:net.ftb.util.OSUtils.java

/**
 *
 * @return pid of the running process. -1 if fail
 *//*from   w  w  w . j a  v  a2  s.c  o m*/
public static long getPID() {
    String name = ManagementFactory.getRuntimeMXBean().getName();
    String pid = name.split("@")[0];
    long numericpid = -1;
    try {
        numericpid = Long.parseLong(pid);
    } catch (Exception e) {
        numericpid = -1;
        Logger.logDebug("failed", e);
    }
    return numericpid;
}

From source file:com.datatorrent.stram.StreamingContainerManager.java

public final ContainerInfo getAppMasterContainerInfo() {
    ContainerInfo ci = new ContainerInfo();
    ci.id = System.getenv(ApplicationConstants.Environment.CONTAINER_ID.toString());
    String nmHost = System.getenv(ApplicationConstants.Environment.NM_HOST.toString());
    String nmPort = System.getenv(ApplicationConstants.Environment.NM_PORT.toString());
    String nmHttpPort = System.getenv(ApplicationConstants.Environment.NM_HTTP_PORT.toString());
    ci.state = "ACTIVE";
    ci.jvmName = ManagementFactory.getRuntimeMXBean().getName();
    ci.numOperators = 0;/*from  www  .  jav a2  s . c  o m*/
    YarnConfiguration conf = new YarnConfiguration();

    if (nmHost != null) {
        if (nmPort != null) {
            ci.host = nmHost + ":" + nmPort;
        }
        if (nmHttpPort != null) {
            String nodeHttpAddress = nmHost + ":" + nmHttpPort;
            if (allocatedMemoryMB == 0) {
                String url = ConfigUtils.getSchemePrefix(conf) + nodeHttpAddress + "/ws/v1/node/containers/"
                        + ci.id;
                WebServicesClient webServicesClient = new WebServicesClient();
                try {
                    String content = webServicesClient.process(url, String.class,
                            new WebServicesClient.GetWebServicesHandler<String>());
                    JSONObject json = new JSONObject(content);
                    int totalMemoryNeededMB = json.getJSONObject("container").getInt("totalMemoryNeededMB");
                    if (totalMemoryNeededMB > 0) {
                        allocatedMemoryMB = totalMemoryNeededMB;
                    } else {
                        LOG.warn(
                                "Could not determine the memory allocated for the streaming application master.  Node manager is reporting {} MB from {}",
                                totalMemoryNeededMB, url);
                    }
                } catch (Exception ex) {
                    LOG.warn("Could not determine the memory allocated for the streaming application master",
                            ex);
                }
            }
            ci.containerLogsUrl = ConfigUtils.getSchemePrefix(conf) + nodeHttpAddress + "/node/containerlogs/"
                    + ci.id + "/" + System.getenv(ApplicationConstants.Environment.USER.toString());
            ci.rawContainerLogsUrl = ConfigUtils.getRawContainerLogsUrl(conf, nodeHttpAddress,
                    plan.getLogicalPlan().getAttributes().get(LogicalPlan.APPLICATION_ID), ci.id);
        }
    }
    ci.memoryMBAllocated = allocatedMemoryMB;
    ci.memoryMBFree = ((int) (Runtime.getRuntime().freeMemory() / (1024 * 1024)));
    ci.lastHeartbeat = -1;
    ci.startedTime = startTime;
    ci.finishedTime = -1;
    return ci;
}

From source file:com.eurelis.opencms.admin.systeminformation.CmsMemoryOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *///  ww w. j  a v  a 2  s  .  com
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    for (java.lang.management.MemoryPoolMXBean item : ManagementFactory.getMemoryPoolMXBeans()) {
        java.lang.management.MemoryUsage mu = item.getUsage();
        String name = item.getName();

        if (name.toLowerCase().contains("perm")) {
            setMemPermMax("" + mu.getMax());
            setMemPermTotal("" + mu.getCommitted());
            setMemPermUsed("" + mu.getUsed());
        } else if (name.toLowerCase().contains("old")) {
            setMemOldMax("" + mu.getMax());
            setMemOldTotal("" + mu.getCommitted());
            setMemOldUsed("" + mu.getUsed());
        } else if (name.toLowerCase().contains("eden")) {
            setMemEdenMax("" + mu.getMax());
            setMemEdenTotal("" + mu.getCommitted());
            setMemEdenUsed("" + mu.getUsed());
        } else if (name.toLowerCase().contains("survivor")) {
            setMemSurvivorMax("" + mu.getMax());
            setMemSurvivorTotal("" + mu.getCommitted());
            setMemSurvivorUsed("" + mu.getUsed());
        } else {
            //LOG.debug("MemoryPoolMXBean name = " + name.toLowerCase());
        }
    }

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

    setParamCloseLink(getJsp()
            .link("/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/memory.jsp"));
}