Search in sources :

Example 6 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project gerrit by GerritCodeReview.

the class GetSummary method getJvmSummary.

private JvmSummaryInfo getJvmSummary() {
    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    JvmSummaryInfo jvmSummary = new JvmSummaryInfo();
    jvmSummary.vmVendor = runtimeBean.getVmVendor();
    jvmSummary.vmName = runtimeBean.getVmName();
    jvmSummary.vmVersion = runtimeBean.getVmVersion();
    jvmSummary.osName = osBean.getName();
    jvmSummary.osVersion = osBean.getVersion();
    jvmSummary.osArch = osBean.getArch();
    jvmSummary.user = System.getProperty("user.name");
    try {
        jvmSummary.host = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
    // Ignored
    }
    jvmSummary.currentWorkingDirectory = path(Paths.get(".").toAbsolutePath().getParent());
    jvmSummary.site = path(sitePath);
    return jvmSummary;
}
Also used : UnknownHostException(java.net.UnknownHostException) RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 7 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project adempiere by adempiere.

the class MSystem method info.

//	getDBInfoSQL
/**
	 * 	Print info
	 */
public void info() {
    if (!CLogMgt.isLevelFine())
        return;
    //	OS
    //	OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    //	log.fine(os.getName() + " " + os.getVersion() + " " + os.getArch() 
    //		+ " Processors=" + os.getAvailableProcessors());
    //	Runtime
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    //	Memory
    if (CLogMgt.isLevelFiner()) {
        List<MemoryPoolMXBean> list = ManagementFactory.getMemoryPoolMXBeans();
        Iterator<MemoryPoolMXBean> it = list.iterator();
        while (it.hasNext()) {
            MemoryPoolMXBean pool = (MemoryPoolMXBean) it.next();
        /*
				log.finer(pool.getName() + " " + pool.getType() 
					+ ": " + new CMemoryUsage(pool.getUsage()));
				*/
        }
    } else {
        MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    // log.fine("VM: " + new CMemoryUsage(memory.getNonHeapMemoryUsage()));
    // log.fine("Heap: " + new CMemoryUsage(memory.getHeapMemoryUsage()));
    }
    //	Thread
    ThreadMXBean th = ManagementFactory.getThreadMXBean();
/*
		log.fine("Threads=" + th.getThreadCount()
			+ ", Peak=" + th.getPeakThreadCount()
			+ ", Demons=" + th.getDaemonThreadCount()
			+ ", Total=" + th.getTotalStartedThreadCount()
		);
		*/
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryMXBean(java.lang.management.MemoryMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 8 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project adempiere by adempiere.

the class AdempiereMonitor method createLogMgtPage.

//	createSummaryPage
/**
	 * 	Add Log Management to page
	 *	@param bb body
	 */
private void createLogMgtPage(body bb) {
    bb.addElement(new hr());
    //	Ini Parameters
    table table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //
    Properties ctx = new Properties();
    MSystem system = MSystem.get(ctx);
    tr line = new tr();
    line.addElement(new th().addElement(system.getDBAddress()));
    line.addElement(new td().addElement(Ini.getAdempiereHome()));
    table.addElement(line);
    //	OS + Name
    line = new tr();
    String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
    String s = System.getProperty("sun.os.patch.level");
    if (s != null && s.length() > 0)
        info += " (" + s + ")";
    line.addElement(new th().addElement(info));
    info = system.getName();
    if (system.getCustomPrefix() != null)
        info += " (" + system.getCustomPrefix() + ")";
    line.addElement(new td().addElement(info));
    table.addElement(line);
    //	Java + email
    line = new tr();
    info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(system.getUserName()));
    table.addElement(line);
    //	DB + Instance
    line = new tr();
    CConnection cc = CConnection.get();
    AdempiereDatabase db = cc.getDatabase();
    info = db.getDescription();
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(cc.getConnectionURL()));
    //		line.addElement(new td().addElement(system.getDBInstance()));
    table.addElement(line);
    //	Processors/Support
    line = new tr();
    line.addElement(new th().addElement("Processor/Support"));
    line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
    table.addElement(line);
    //	Memory
    line = new tr();
    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    line.addElement(new th().addElement("VM Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
    table.addElement(line);
    line = new tr();
    line.addElement(new th().addElement("Heap Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
    table.addElement(line);
    //	Runtime
    line = new tr();
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    line.addElement(new th().addElement("Runtime " + rt.getName()));
    line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
    table.addElement(line);
    //	Threads
    line = new tr();
    ThreadMXBean th = ManagementFactory.getThreadMXBean();
    line.addElement(new th().addElement("Threads " + th.getThreadCount()));
    line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
    table.addElement(line);
    //Transactions
    Trx[] trxs = Trx.getActiveTransactions();
    for (Trx trx : trxs) {
        if (trx != null && trx.isActive()) {
            line = new tr();
            line.addElement(new th().addElement("Active Transaction "));
            line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
            table.addElement(line);
        }
    }
    //	Cache Reset
    line = new tr();
    line.addElement(new th().addElement(CacheMgt.get().toStringX()));
    line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
    table.addElement(line);
    //	Trace Level
    line = new tr();
    line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
    form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
    //	LogLevel Selection
    option[] options = new option[CLogMgt.LEVELS.length];
    for (int i = 0; i < options.length; i++) {
        options[i] = new option(CLogMgt.LEVELS[i].getName());
        options[i].addElement(CLogMgt.LEVELS[i].getName());
        if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
            options[i].setSelected(true);
    }
    select sel = new select("TraceLevel", options);
    myForm.addElement(sel);
    myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
    line.addElement(new td().addElement(myForm));
    table.addElement(line);
    //
    line = new tr();
    CLogFile fileHandler = CLogFile.get(true, null, false);
    line.addElement(new th().addElement("Trace File"));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
    table.addElement(line);
    //
    line = new tr();
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
    table.addElement(line);
    //
    bb.addElement(table);
    //	List Log Files
    p p = new p();
    p.addElement(new b("All Log Files: "));
    //	All in dir
    File logDir = fileHandler.getLogDirectory();
    if (logDir != null && logDir.isDirectory()) {
        File[] logs = logDir.listFiles();
        for (int i = 0; i < logs.length; i++) {
            // Skip if is not a file - teo_sarca [ 1726066 ]
            if (!logs[i].isFile())
                continue;
            if (i != 0)
                p.addElement(" - ");
            String fileName = logs[i].getAbsolutePath();
            a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
            p.addElement(link);
            int size = (int) (logs[i].length() / 1024);
            if (size < 1024)
                p.addElement(" (" + size + "k)");
            else
                p.addElement(" (" + size / 1024 + "M)");
        }
    }
    bb.addElement(p);
    //	Clients and Web Stores
    table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //	
    line = new tr();
    MClient[] clients = MClient.getAll(ctx);
    line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
    p = new p();
    for (int i = 0; i < clients.length; i++) {
        MClient client = clients[i];
        if (i > 0)
            p.addElement(" - ");
        p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
    }
    if (clients.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //	
    line = new tr();
    MStore[] wstores = MStore.getActive();
    line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
    p = new p();
    for (int i = 0; i < wstores.length; i++) {
        MStore store = wstores[i];
        if (i > 0)
            p.addElement(" - ");
        a a = new a(store.getWebContext(), store.getName());
        a.setTarget("t" + i);
        p.addElement(a);
    }
    if (wstores.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //
    bb.addElement(table);
}
Also used : org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) org.apache.ecs.xhtml.hr(org.apache.ecs.xhtml.hr) Properties(java.util.Properties) MClient(org.compiere.model.MClient) MemoryMXBean(java.lang.management.MemoryMXBean) Trx(org.compiere.util.Trx) MSystem(org.compiere.model.MSystem) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) ThreadMXBean(java.lang.management.ThreadMXBean) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) CLogFile(org.compiere.util.CLogFile) org.apache.ecs.xhtml.b(org.apache.ecs.xhtml.b) RuntimeMXBean(java.lang.management.RuntimeMXBean) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) CConnection(org.compiere.db.CConnection) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) AdempiereDatabase(org.compiere.db.AdempiereDatabase) org.apache.ecs.xhtml.th(org.apache.ecs.xhtml.th) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) CMemoryUsage(org.compiere.util.CMemoryUsage) MStore(org.compiere.model.MStore) CLogFile(org.compiere.util.CLogFile) File(java.io.File) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 9 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project lucene-solr by apache.

the class SystemInfoHandler method getJvmInfo.

/**
   * Get JVM Info - including memory info
   */
public static SimpleOrderedMap<Object> getJvmInfo() {
    SimpleOrderedMap<Object> jvm = new SimpleOrderedMap<>();
    final String javaVersion = System.getProperty("java.specification.version", "unknown");
    final String javaVendor = System.getProperty("java.specification.vendor", "unknown");
    final String javaName = System.getProperty("java.specification.name", "unknown");
    final String jreVersion = System.getProperty("java.version", "unknown");
    final String jreVendor = System.getProperty("java.vendor", "unknown");
    final String vmVersion = System.getProperty("java.vm.version", "unknown");
    final String vmVendor = System.getProperty("java.vm.vendor", "unknown");
    final String vmName = System.getProperty("java.vm.name", "unknown");
    // Summary Info
    jvm.add("version", jreVersion + " " + vmVersion);
    jvm.add(NAME, jreVendor + " " + vmName);
    // details
    SimpleOrderedMap<Object> java = new SimpleOrderedMap<>();
    java.add("vendor", javaVendor);
    java.add(NAME, javaName);
    java.add("version", javaVersion);
    jvm.add("spec", java);
    SimpleOrderedMap<Object> jre = new SimpleOrderedMap<>();
    jre.add("vendor", jreVendor);
    jre.add("version", jreVersion);
    jvm.add("jre", jre);
    SimpleOrderedMap<Object> vm = new SimpleOrderedMap<>();
    vm.add("vendor", vmVendor);
    vm.add(NAME, vmName);
    vm.add("version", vmVersion);
    jvm.add("vm", vm);
    Runtime runtime = Runtime.getRuntime();
    jvm.add("processors", runtime.availableProcessors());
    // not thread safe, but could be thread local
    DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ROOT));
    SimpleOrderedMap<Object> mem = new SimpleOrderedMap<>();
    SimpleOrderedMap<Object> raw = new SimpleOrderedMap<>();
    long free = runtime.freeMemory();
    long max = runtime.maxMemory();
    long total = runtime.totalMemory();
    long used = total - free;
    double percentUsed = ((double) (used) / (double) max) * 100;
    raw.add("free", free);
    mem.add("free", humanReadableUnits(free, df));
    raw.add("total", total);
    mem.add("total", humanReadableUnits(total, df));
    raw.add("max", max);
    mem.add("max", humanReadableUnits(max, df));
    raw.add("used", used);
    mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")");
    raw.add("used%", percentUsed);
    mem.add("raw", raw);
    jvm.add("memory", mem);
    // JMX properties -- probably should be moved to a different handler
    SimpleOrderedMap<Object> jmx = new SimpleOrderedMap<>();
    try {
        RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
        if (mx.isBootClassPathSupported()) {
            jmx.add("bootclasspath", mx.getBootClassPath());
        }
        jmx.add("classpath", mx.getClassPath());
        // the input arguments passed to the Java virtual machine
        // which does not include the arguments to the main method.
        jmx.add("commandLineArgs", getInputArgumentsRedacted(mx));
        jmx.add("startTime", new Date(mx.getStartTime()));
        jmx.add("upTimeMS", mx.getUptime());
    } catch (Exception e) {
        log.warn("Error getting JMX properties", e);
    }
    jvm.add("jmx", jmx);
    return jvm;
}
Also used : DecimalFormat(java.text.DecimalFormat) RuntimeMXBean(java.lang.management.RuntimeMXBean) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Date(java.util.Date) IOException(java.io.IOException)

Example 10 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project geode by apache.

the class ConfigCommandsDUnitTest method testDescribeConfig.

@Test
public void testDescribeConfig() throws Exception {
    setUpJmxManagerOnVm0ThenConnect(null);
    final String controllerName = "Member2";
    /*
     * Create properties for the controller VM
     */
    final Properties localProps = new Properties();
    localProps.setProperty(MCAST_PORT, "0");
    localProps.setProperty(LOG_LEVEL, "info");
    localProps.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    localProps.setProperty(ENABLE_TIME_STATISTICS, "true");
    localProps.setProperty(NAME, controllerName);
    localProps.setProperty(GROUPS, "G1");
    getSystem(localProps);
    Cache cache = getCache();
    int[] ports = getRandomAvailableTCPPorts(1);
    CacheServer cs = getCache().addCacheServer();
    cs.setPort(ports[0]);
    cs.setMaxThreads(10);
    cs.setMaxConnections(9);
    cs.start();
    try {
        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        List<String> jvmArgs = runtimeBean.getInputArguments();
        getLogWriter().info("#SB Actual JVM Args : ");
        for (String jvmArg : jvmArgs) {
            getLogWriter().info("#SB JVM " + jvmArg);
        }
        InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
        DistributionConfig config = system.getConfig();
        config.setArchiveFileSizeLimit(1000);
        String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName;
        CommandProcessor cmdProcessor = new CommandProcessor();
        cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
        CommandResult cmdResult = executeCommand(command);
        String resultStr = commandResultToString(cmdResult);
        getLogWriter().info("#SB Hiding the defaults\n" + resultStr);
        assertEquals(true, cmdResult.getStatus().equals(Status.OK));
        assertEquals(true, resultStr.contains("G1"));
        assertEquals(true, resultStr.contains(controllerName));
        assertEquals(true, resultStr.contains(ARCHIVE_FILE_SIZE_LIMIT));
        assertEquals(true, !resultStr.contains("copy-on-read"));
        cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS + "=false");
        resultStr = commandResultToString(cmdResult);
        getLogWriter().info("#SB No hiding of defaults\n" + resultStr);
        assertEquals(true, cmdResult.getStatus().equals(Status.OK));
        assertEquals(true, resultStr.contains("is-server"));
        assertEquals(true, resultStr.contains(controllerName));
        assertEquals(true, resultStr.contains("copy-on-read"));
    } finally {
        cs.stop();
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) CacheServer(org.apache.geode.cache.server.CacheServer) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) RuntimeMXBean(java.lang.management.RuntimeMXBean) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

RuntimeMXBean (java.lang.management.RuntimeMXBean)164 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)27 IOException (java.io.IOException)17 MemoryMXBean (java.lang.management.MemoryMXBean)16 ThreadMXBean (java.lang.management.ThreadMXBean)13 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 MemoryUsage (java.lang.management.MemoryUsage)8 Method (java.lang.reflect.Method)8 Map (java.util.Map)8 Properties (java.util.Properties)6 InputStream (java.io.InputStream)5 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Iterator (java.util.Iterator)5 File (java.io.File)4 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 Field (java.lang.reflect.Field)4 UnknownHostException (java.net.UnknownHostException)4