Search in sources :

Example 71 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project openj9 by eclipse.

the class MXBeansGetterSanityTest method main.

public static void main(String[] args) {
    testMXBeanGetters(ManagementFactory.getClassLoadingMXBean());
    testMXBeanGetters(ManagementFactory.getCompilationMXBean());
    for (GarbageCollectorMXBean mxBean : ManagementFactory.getGarbageCollectorMXBeans()) {
        testMXBeanGetters(mxBean);
    }
    for (MemoryManagerMXBean mxBean : ManagementFactory.getMemoryManagerMXBeans()) {
        testMXBeanGetters(mxBean);
    }
    testMXBeanGetters(ManagementFactory.getMemoryMXBean());
    for (MemoryPoolMXBean mxBean : ManagementFactory.getMemoryPoolMXBeans()) {
        testMXBeanGetters(mxBean);
    }
    testMXBeanGetters(ManagementFactory.getOperatingSystemMXBean());
    testMXBeanGetters(ManagementFactory.getRuntimeMXBean());
    testMXBeanGetters(ManagementFactory.getThreadMXBean());
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryManagerMXBean(java.lang.management.MemoryManagerMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 72 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project tomcat70 by apache.

the class Diagnostics method getVMInfo.

/**
 * Retrieve a JVM information text formatted
 * using the given StringManager.
 *
 * @param requestedSm the StringManager to use
 * @return the formatted JVM information text
 */
private static String getVMInfo(StringManager requestedSm) {
    StringBuilder sb = new StringBuilder();
    synchronized (timeformat) {
        sb.append(timeformat.format(new Date()));
    }
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoRuntime"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "vmName: " + runtimeMXBean.getVmName() + CRLF);
    sb.append(INDENT1 + "vmVersion: " + runtimeMXBean.getVmVersion() + CRLF);
    sb.append(INDENT1 + "vmVendor: " + runtimeMXBean.getVmVendor() + CRLF);
    sb.append(INDENT1 + "specName: " + runtimeMXBean.getSpecName() + CRLF);
    sb.append(INDENT1 + "specVersion: " + runtimeMXBean.getSpecVersion() + CRLF);
    sb.append(INDENT1 + "specVendor: " + runtimeMXBean.getSpecVendor() + CRLF);
    sb.append(INDENT1 + "managementSpecVersion: " + runtimeMXBean.getManagementSpecVersion() + CRLF);
    sb.append(INDENT1 + "name: " + runtimeMXBean.getName() + CRLF);
    sb.append(INDENT1 + "startTime: " + runtimeMXBean.getStartTime() + CRLF);
    sb.append(INDENT1 + "uptime: " + runtimeMXBean.getUptime() + CRLF);
    sb.append(INDENT1 + "isBootClassPathSupported: " + runtimeMXBean.isBootClassPathSupported() + CRLF);
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoOs"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "name: " + operatingSystemMXBean.getName() + CRLF);
    sb.append(INDENT1 + "version: " + operatingSystemMXBean.getVersion() + CRLF);
    sb.append(INDENT1 + "architecture: " + operatingSystemMXBean.getArch() + CRLF);
    sb.append(INDENT1 + "availableProcessors: " + operatingSystemMXBean.getAvailableProcessors() + CRLF);
    sb.append(INDENT1 + "systemLoadAverage: " + operatingSystemMXBean.getSystemLoadAverage() + CRLF);
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoThreadMxBean"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "isCurrentThreadCpuTimeSupported: " + threadMXBean.isCurrentThreadCpuTimeSupported() + CRLF);
    sb.append(INDENT1 + "isThreadCpuTimeSupported: " + threadMXBean.isThreadCpuTimeSupported() + CRLF);
    sb.append(INDENT1 + "isThreadCpuTimeEnabled: " + threadMXBean.isThreadCpuTimeEnabled() + CRLF);
    sb.append(INDENT1 + "isObjectMonitorUsageSupported: " + threadMXBean.isObjectMonitorUsageSupported() + CRLF);
    sb.append(INDENT1 + "isSynchronizerUsageSupported: " + threadMXBean.isSynchronizerUsageSupported() + CRLF);
    sb.append(INDENT1 + "isThreadContentionMonitoringSupported: " + threadMXBean.isThreadContentionMonitoringSupported() + CRLF);
    sb.append(INDENT1 + "isThreadContentionMonitoringEnabled: " + threadMXBean.isThreadContentionMonitoringEnabled() + CRLF);
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoThreadCounts"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "daemon: " + threadMXBean.getDaemonThreadCount() + CRLF);
    sb.append(INDENT1 + "total: " + threadMXBean.getThreadCount() + CRLF);
    sb.append(INDENT1 + "peak: " + threadMXBean.getPeakThreadCount() + CRLF);
    sb.append(INDENT1 + "totalStarted: " + threadMXBean.getTotalStartedThreadCount() + CRLF);
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoStartup"));
    sb.append(":" + CRLF);
    for (String arg : runtimeMXBean.getInputArguments()) {
        sb.append(INDENT1 + arg + CRLF);
    }
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoPath"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "bootClassPath: " + runtimeMXBean.getBootClassPath() + CRLF);
    sb.append(INDENT1 + "classPath: " + runtimeMXBean.getClassPath() + CRLF);
    sb.append(INDENT1 + "libraryPath: " + runtimeMXBean.getLibraryPath() + CRLF);
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoClassLoading"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "loaded: " + classLoadingMXBean.getLoadedClassCount() + CRLF);
    sb.append(INDENT1 + "unloaded: " + classLoadingMXBean.getUnloadedClassCount() + CRLF);
    sb.append(INDENT1 + "totalLoaded: " + classLoadingMXBean.getTotalLoadedClassCount() + CRLF);
    sb.append(INDENT1 + "isVerbose: " + classLoadingMXBean.isVerbose() + CRLF);
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoClassCompilation"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "name: " + compilationMXBean.getName() + CRLF);
    sb.append(INDENT1 + "totalCompilationTime: " + compilationMXBean.getTotalCompilationTime() + CRLF);
    sb.append(INDENT1 + "isCompilationTimeMonitoringSupported: " + compilationMXBean.isCompilationTimeMonitoringSupported() + CRLF);
    sb.append(CRLF);
    for (MemoryManagerMXBean mbean : memoryManagerMXBeans) {
        sb.append(requestedSm.getString("diagnostics.vmInfoMemoryManagers", mbean.getName()));
        sb.append(":" + CRLF);
        sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
        sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF);
        String[] names = mbean.getMemoryPoolNames();
        Arrays.sort(names);
        for (String name : names) {
            sb.append(INDENT2 + name + CRLF);
        }
        sb.append(CRLF);
    }
    for (GarbageCollectorMXBean mbean : garbageCollectorMXBeans) {
        sb.append(requestedSm.getString("diagnostics.vmInfoGarbageCollectors", mbean.getName()));
        sb.append(":" + CRLF);
        sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
        sb.append(INDENT1 + "mbean.getMemoryPoolNames: " + CRLF);
        String[] names = mbean.getMemoryPoolNames();
        Arrays.sort(names);
        for (String name : names) {
            sb.append(INDENT2 + name + CRLF);
        }
        sb.append(INDENT1 + "getCollectionCount: " + mbean.getCollectionCount() + CRLF);
        sb.append(INDENT1 + "getCollectionTime: " + mbean.getCollectionTime() + CRLF);
        sb.append(CRLF);
    }
    sb.append(requestedSm.getString("diagnostics.vmInfoMemory"));
    sb.append(":" + CRLF);
    sb.append(INDENT1 + "isVerbose: " + memoryMXBean.isVerbose() + CRLF);
    sb.append(INDENT1 + "getObjectPendingFinalizationCount: " + memoryMXBean.getObjectPendingFinalizationCount() + CRLF);
    sb.append(formatMemoryUsage("heap", memoryMXBean.getHeapMemoryUsage()));
    sb.append(formatMemoryUsage("non-heap", memoryMXBean.getNonHeapMemoryUsage()));
    sb.append(CRLF);
    for (MemoryPoolMXBean mbean : memoryPoolMXBeans) {
        sb.append(requestedSm.getString("diagnostics.vmInfoMemoryPools", mbean.getName()));
        sb.append(":" + CRLF);
        sb.append(INDENT1 + "isValid: " + mbean.isValid() + CRLF);
        sb.append(INDENT1 + "getType: " + mbean.getType() + CRLF);
        sb.append(INDENT1 + "mbean.getMemoryManagerNames: " + CRLF);
        String[] names = mbean.getMemoryManagerNames();
        Arrays.sort(names);
        for (String name : names) {
            sb.append(INDENT2 + name + CRLF);
        }
        sb.append(INDENT1 + "isUsageThresholdSupported: " + mbean.isUsageThresholdSupported() + CRLF);
        try {
            sb.append(INDENT1 + "isUsageThresholdExceeded: " + mbean.isUsageThresholdExceeded() + CRLF);
        } catch (UnsupportedOperationException ex) {
        // IGNORE
        }
        sb.append(INDENT1 + "isCollectionUsageThresholdSupported: " + mbean.isCollectionUsageThresholdSupported() + CRLF);
        try {
            sb.append(INDENT1 + "isCollectionUsageThresholdExceeded: " + mbean.isCollectionUsageThresholdExceeded() + CRLF);
        } catch (UnsupportedOperationException ex) {
        // IGNORE
        }
        try {
            sb.append(INDENT1 + "getUsageThreshold: " + mbean.getUsageThreshold() + CRLF);
        } catch (UnsupportedOperationException ex) {
        // IGNORE
        }
        try {
            sb.append(INDENT1 + "getUsageThresholdCount: " + mbean.getUsageThresholdCount() + CRLF);
        } catch (UnsupportedOperationException ex) {
        // IGNORE
        }
        try {
            sb.append(INDENT1 + "getCollectionUsageThreshold: " + mbean.getCollectionUsageThreshold() + CRLF);
        } catch (UnsupportedOperationException ex) {
        // IGNORE
        }
        try {
            sb.append(INDENT1 + "getCollectionUsageThresholdCount: " + mbean.getCollectionUsageThresholdCount() + CRLF);
        } catch (UnsupportedOperationException ex) {
        // IGNORE
        }
        sb.append(formatMemoryUsage("current", mbean.getUsage()));
        sb.append(formatMemoryUsage("collection", mbean.getCollectionUsage()));
        sb.append(formatMemoryUsage("peak", mbean.getPeakUsage()));
        sb.append(CRLF);
    }
    sb.append(requestedSm.getString("diagnostics.vmInfoSystem"));
    sb.append(":" + CRLF);
    Map<String, String> props = runtimeMXBean.getSystemProperties();
    ArrayList<String> keys = new ArrayList<String>(props.keySet());
    Collections.sort(keys);
    for (String prop : keys) {
        sb.append(INDENT1 + prop + ": " + props.get(prop) + CRLF);
    }
    sb.append(CRLF);
    sb.append(requestedSm.getString("diagnostics.vmInfoLogger"));
    sb.append(":" + CRLF);
    List<String> loggers = loggingMXBean.getLoggerNames();
    Collections.sort(loggers);
    for (String logger : loggers) {
        sb.append(INDENT1 + logger + ": level=" + loggingMXBean.getLoggerLevel(logger) + ", parent=" + loggingMXBean.getParentLoggerName(logger) + CRLF);
    }
    sb.append(CRLF);
    return sb.toString();
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) MemoryManagerMXBean(java.lang.management.MemoryManagerMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) Date(java.util.Date)

Example 73 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project tomcat70 by apache.

the class StatusTransformer method writeVMState.

/**
 * Write the VM state. Mode 0 will generate HTML.
 * Mode 1 will generate XML.
 */
public static void writeVMState(PrintWriter writer, int mode) throws Exception {
    SortedMap<String, MemoryPoolMXBean> memoryPoolMBeans = new TreeMap<String, MemoryPoolMXBean>();
    for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
        String sortKey = mbean.getType() + ":" + mbean.getName();
        memoryPoolMBeans.put(sortKey, mbean);
    }
    if (mode == 0) {
        writer.print("<h1>JVM</h1>");
        writer.print("<p>");
        writer.print(" Free memory: ");
        writer.print(formatSize(Long.valueOf(Runtime.getRuntime().freeMemory()), true));
        writer.print(" Total memory: ");
        writer.print(formatSize(Long.valueOf(Runtime.getRuntime().totalMemory()), true));
        writer.print(" Max memory: ");
        writer.print(formatSize(Long.valueOf(Runtime.getRuntime().maxMemory()), true));
        writer.print("</p>");
        writer.write("<table border=\"0\"><thead><tr><th>Memory Pool</th><th>Type</th><th>Initial</th><th>Total</th><th>Maximum</th><th>Used</th></tr></thead><tbody>");
        for (MemoryPoolMXBean memoryPoolMBean : memoryPoolMBeans.values()) {
            MemoryUsage usage = memoryPoolMBean.getUsage();
            writer.write("<tr><td>");
            writer.print(memoryPoolMBean.getName());
            writer.write("</td><td>");
            writer.print(memoryPoolMBean.getType());
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getInit()), true));
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getCommitted()), true));
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getMax()), true));
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getUsed()), true));
            if (usage.getMax() > 0) {
                writer.write(" (" + (usage.getUsed() * 100 / usage.getMax()) + "%)");
            }
            writer.write("</td></tr>");
        }
        writer.write("</tbody></table>");
    } else if (mode == 1) {
        writer.write("<jvm>");
        writer.write("<memory");
        writer.write(" free='" + Runtime.getRuntime().freeMemory() + "'");
        writer.write(" total='" + Runtime.getRuntime().totalMemory() + "'");
        writer.write(" max='" + Runtime.getRuntime().maxMemory() + "'/>");
        for (MemoryPoolMXBean memoryPoolMBean : memoryPoolMBeans.values()) {
            MemoryUsage usage = memoryPoolMBean.getUsage();
            writer.write("<memorypool");
            writer.write(" name='" + filterXml(memoryPoolMBean.getName()) + "'");
            writer.write(" type='" + memoryPoolMBean.getType() + "'");
            writer.write(" usageInit='" + usage.getInit() + "'");
            writer.write(" usageCommitted='" + usage.getCommitted() + "'");
            writer.write(" usageMax='" + usage.getMax() + "'");
            writer.write(" usageUsed='" + usage.getUsed() + "'/>");
        }
        writer.write("</jvm>");
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) TreeMap(java.util.TreeMap) MemoryUsage(java.lang.management.MemoryUsage)

Example 74 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project micrometer by micrometer-metrics.

the class JvmMemoryMetrics method bindTo.

@Override
public void bindTo(MeterRegistry registry) {
    for (BufferPoolMXBean bufferPoolBean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
        Iterable<Tag> tagsWithId = Tags.concat(tags, "id", bufferPoolBean.getName());
        Gauge.builder("jvm.buffer.count", bufferPoolBean, BufferPoolMXBean::getCount).tags(tagsWithId).description("An estimate of the number of buffers in the pool").register(registry);
        Gauge.builder("jvm.buffer.memory.used", bufferPoolBean, BufferPoolMXBean::getMemoryUsed).tags(tagsWithId).description("An estimate of the memory that the Java virtual machine is using for this buffer pool").baseUnit("bytes").register(registry);
        Gauge.builder("jvm.buffer.total.capacity", bufferPoolBean, BufferPoolMXBean::getTotalCapacity).tags(tagsWithId).description("An estimate of the total capacity of the buffers in this pool").baseUnit("bytes").register(registry);
    }
    for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class)) {
        String area = MemoryType.HEAP.equals(memoryPoolBean.getType()) ? "heap" : "nonheap";
        Iterable<Tag> tagsWithId = Tags.concat(tags, "id", memoryPoolBean.getName(), "area", area);
        Gauge.builder("jvm.memory.used", memoryPoolBean, (mem) -> mem.getUsage().getUsed()).tags(tagsWithId).description("The amount of used memory").baseUnit("bytes").register(registry);
        Gauge.builder("jvm.memory.committed", memoryPoolBean, (mem) -> mem.getUsage().getCommitted()).tags(tagsWithId).description("The amount of memory in bytes that is committed for  the Java virtual machine to use").baseUnit("bytes").register(registry);
        Gauge.builder("jvm.memory.max", memoryPoolBean, (mem) -> mem.getUsage().getMax()).tags(tagsWithId).description("The maximum amount of memory in bytes that can be used for memory management").baseUnit("bytes").register(registry);
    }
}
Also used : BufferPoolMXBean(java.lang.management.BufferPoolMXBean) Tag(io.micrometer.core.instrument.Tag) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 75 with MemoryPoolMXBean

use of java.lang.management.MemoryPoolMXBean in project OpenOLAT by OpenOLAT.

the class JavaMemoryController method getMemoryInfos.

private String getMemoryInfos() {
    Runtime r = Runtime.getRuntime();
    StringBuilder sb = new StringBuilder();
    appendFormattedKeyValue(sb, "Processors", new Integer(r.availableProcessors()));
    appendFormattedKeyValue(sb, "Total Memory", Formatter.formatBytes(r.totalMemory()));
    appendFormattedKeyValue(sb, "Free Memory", Formatter.formatBytes(r.freeMemory()));
    appendFormattedKeyValue(sb, "Max Memory", Formatter.formatBytes(r.maxMemory()));
    sb.append("<br />Detailed Memory Information (Init/Used/Max)<br/> ");
    List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
    for (MemoryPoolMXBean item : pools) {
        String name = item.getName();
        MemoryType type = item.getType();
        appendFormattedKeyValue(sb, name, " Type: " + type);
        MemoryUsage usage = item.getUsage();
        appendFormattedKeyValue(sb, "Usage", Formatter.formatBytes(usage.getInit()) + "/" + Formatter.formatBytes(usage.getUsed()) + "/" + Formatter.formatBytes(usage.getMax()));
        MemoryUsage peak = item.getPeakUsage();
        appendFormattedKeyValue(sb, "Peak", Formatter.formatBytes(peak.getInit()) + "/" + Formatter.formatBytes(peak.getUsed()) + "/" + Formatter.formatBytes(peak.getMax()));
        MemoryUsage collections = item.getCollectionUsage();
        if (collections != null) {
            appendFormattedKeyValue(sb, "Collections", Formatter.formatBytes(collections.getInit()) + "/" + Formatter.formatBytes(collections.getUsed()) + "/" + Formatter.formatBytes(collections.getMax()));
        }
        sb.append("<hr/>");
    }
    return sb.toString();
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) MemoryType(java.lang.management.MemoryType)

Aggregations

MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)112 MemoryUsage (java.lang.management.MemoryUsage)46 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)16 ArrayList (java.util.ArrayList)15 MemoryMXBean (java.lang.management.MemoryMXBean)12 Test (org.testng.annotations.Test)11 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 ReflectionException (javax.management.ReflectionException)9 NotificationEmitter (javax.management.NotificationEmitter)8 MemoryType (java.lang.management.MemoryType)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 AttributeNotFoundException (javax.management.AttributeNotFoundException)7 IntrospectionException (javax.management.IntrospectionException)7 MBeanException (javax.management.MBeanException)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 Attribute (javax.management.Attribute)6 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)6 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)5 ThreadMXBean (java.lang.management.ThreadMXBean)5