Search in sources :

Example 16 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project ignite by apache.

the class GridManagerMxBeanIllegalArgumentHandleTest method setUp.

/** {@inheritDoc} Changes field to always failing mock */
@Override
public void setUp() throws Exception {
    super.setUp();
    try {
        final MemoryMXBean memoryMXBean = createAlwaysFailingMxBean();
        memMxBeanField = createAccessibleMemField();
        mxBeanToRestore = memMxBeanField.get(null);
        memMxBeanField.set(null, memoryMXBean);
        correctSetupOfTestPerformed = memMxBeanField.get(null) == memoryMXBean;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Example 17 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project karaf by apache.

the class EnvironmentDumpProvider method dumpGCInformation.

private void dumpGCInformation(final PrintWriter outPW) {
    final List<GarbageCollectorMXBean> mxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    if (null == mxBeans || mxBeans.isEmpty()) {
        return;
    }
    final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
    if (memoryMxBean != null) {
        outPW.printf(INDENT_KEY_VALUE_FORMAT, "pending objects", formatLong(memoryMxBean.getObjectPendingFinalizationCount())).println();
    }
    final String gcFormat = "'%1$s' collections: %2$s\ttime: %3$s";
    outPW.println();
    for (final GarbageCollectorMXBean mxBean : mxBeans) {
        if (null == mxBean) {
            continue;
        }
        outPW.printf(KEY_VALUE_FORMAT, "Garbage Collectors", String.format(gcFormat, mxBean.getName(), formatLong(mxBean.getCollectionCount()), printDuration(mxBean.getCollectionTime()))).println();
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean)

Example 18 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project karaf by apache.

the class InfoAction method execute.

@Override
public Object execute() throws Exception {
    int maxNameLen;
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    ThreadMXBean threads = ManagementFactory.getThreadMXBean();
    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
    //
    // print Karaf informations
    //
    maxNameLen = 25;
    System.out.println("Karaf");
    printValue("Karaf version", maxNameLen, System.getProperty("karaf.version"));
    printValue("Karaf home", maxNameLen, System.getProperty("karaf.home"));
    printValue("Karaf base", maxNameLen, System.getProperty("karaf.base"));
    String osgi = getOsgiFramework();
    if (osgi != null) {
        printValue("OSGi Framework", maxNameLen, osgi);
    }
    System.out.println();
    System.out.println("JVM");
    printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
    printValue("Version", maxNameLen, System.getProperty("java.version"));
    printValue("Vendor", maxNameLen, runtime.getVmVendor());
    printValue("Pid", maxNameLen, getPid());
    printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
    try {
        printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
    } catch (Throwable t) {
    }
    printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));
    System.out.println("Threads");
    printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
    printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
    printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
    printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));
    System.out.println("Memory");
    printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
    printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
    printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
    printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
    for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
        String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + printDuration(gc.getCollectionTime());
        printValue("Garbage collector", maxNameLen, val);
    }
    System.out.println("Classes");
    printValue("Current classes loaded", maxNameLen, printLong(cl.getLoadedClassCount()));
    printValue("Total classes loaded", maxNameLen, printLong(cl.getTotalLoadedClassCount()));
    printValue("Total classes unloaded", maxNameLen, printLong(cl.getUnloadedClassCount()));
    System.out.println("Operating system");
    printValue("Name", maxNameLen, os.getName() + " version " + os.getVersion());
    printValue("Architecture", maxNameLen, os.getArch());
    printValue("Processors", maxNameLen, Integer.toString(os.getAvailableProcessors()));
    try {
        printValue("Total physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalPhysicalMemorySize")));
        printValue("Free physical memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreePhysicalMemorySize")));
        printValue("Committed virtual memory", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getCommittedVirtualMemorySize")));
        printValue("Total swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getTotalSwapSpaceSize")));
        printValue("Free swap space", maxNameLen, printSizeInKb(getSunOsValueAsLong(os, "getFreeSwapSpaceSize")));
    } catch (Throwable t) {
    }
    //Display Information from external information providers.
    Map<String, Map<Object, Object>> properties = new HashMap<>();
    if (infoProviders != null) {
        // dump all properties to Map, KARAF-425
        for (InfoProvider provider : infoProviders) {
            if (!properties.containsKey(provider.getName())) {
                properties.put(provider.getName(), new Properties());
            }
            properties.get(provider.getName()).putAll(provider.getProperties());
        }
        List<String> sections = new ArrayList<>(properties.keySet());
        Collections.sort(sections);
        for (String section : sections) {
            List<Object> keys = new ArrayList<>(properties.get(section).keySet());
            if (keys.size() > 0) {
                System.out.println(section);
                keys.sort(Comparator.comparing(String::valueOf));
                for (Object key : keys) {
                    printValue(String.valueOf(key), maxNameLen, String.valueOf(properties.get(section).get(key)));
                }
            }
        }
    }
    return null;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) HashMap(java.util.HashMap) InfoProvider(org.apache.karaf.shell.commands.info.InfoProvider) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) Properties(java.util.Properties) MemoryMXBean(java.lang.management.MemoryMXBean) ClassLoadingMXBean(java.lang.management.ClassLoadingMXBean) HashMap(java.util.HashMap) Map(java.util.Map) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 19 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project Gargoyle by callakrsos.

the class CPUUsageTest method showMemory.

/*
	 * 메모리 사용량
	 */
public void showMemory() {
    MemoryMXBean membean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = membean.getHeapMemoryUsage();
    System.out.println("Heap Memory: " + heap.toString());
    MemoryUsage nonheap = membean.getNonHeapMemoryUsage();
    System.out.println("NonHeap Memory: " + nonheap.toString());
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 20 with MemoryMXBean

use of java.lang.management.MemoryMXBean in project storm by apache.

the class SystemBolt method prepare.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void prepare(final Map topoConf, TopologyContext context, OutputCollector collector) {
    if (_prepareWasCalled && !"local".equals(topoConf.get(Config.STORM_CLUSTER_MODE))) {
        throw new RuntimeException("A single worker should have 1 SystemBolt instance.");
    }
    _prepareWasCalled = true;
    int bucketSize = Utils.getInt(topoConf.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
    final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
    context.registerMetric("uptimeSecs", new IMetric() {

        @Override
        public Object getValueAndReset() {
            return jvmRT.getUptime() / 1000.0;
        }
    }, bucketSize);
    context.registerMetric("startTimeSecs", new IMetric() {

        @Override
        public Object getValueAndReset() {
            return jvmRT.getStartTime() / 1000.0;
        }
    }, bucketSize);
    context.registerMetric("newWorkerEvent", new IMetric() {

        boolean doEvent = true;

        @Override
        public Object getValueAndReset() {
            if (doEvent) {
                doEvent = false;
                return 1;
            } else
                return 0;
        }
    }, bucketSize);
    final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
    context.registerMetric("memory/heap", new MemoryUsageMetric(jvmMemRT::getHeapMemoryUsage), bucketSize);
    context.registerMetric("memory/nonHeap", new MemoryUsageMetric(jvmMemRT::getNonHeapMemoryUsage), bucketSize);
    for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) {
        context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""), new GarbageCollectorMetric(b), bucketSize);
    }
    registerMetrics(context, (Map<String, String>) topoConf.get(Config.WORKER_METRICS), bucketSize, topoConf);
    registerMetrics(context, (Map<String, String>) topoConf.get(Config.TOPOLOGY_WORKER_METRICS), bucketSize, topoConf);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) IMetric(org.apache.storm.metric.api.IMetric) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)38 MemoryUsage (java.lang.management.MemoryUsage)13 RuntimeMXBean (java.lang.management.RuntimeMXBean)10 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)7 ThreadMXBean (java.lang.management.ThreadMXBean)7 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Properties (java.util.Properties)3 NotificationEmitter (javax.management.NotificationEmitter)2 ObjectName (javax.management.ObjectName)2 MetricGroup (org.apache.flink.metrics.MetricGroup)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Function (com.google.common.base.Function)1 Description (com.google.gerrit.metrics.Description)1 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)1