Search in sources :

Example 1 with BufferPoolMXBean

use of java.lang.management.BufferPoolMXBean in project flink by apache.

the class MetricUtils method instantiateMemoryMetrics.

private static void instantiateMemoryMetrics(MetricGroup metrics) {
    final MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
    MetricGroup heap = metrics.addGroup("Heap");
    heap.gauge("Used", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getHeapMemoryUsage().getUsed();
        }
    });
    heap.gauge("Committed", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getHeapMemoryUsage().getCommitted();
        }
    });
    heap.gauge("Max", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getHeapMemoryUsage().getMax();
        }
    });
    MetricGroup nonHeap = metrics.addGroup("NonHeap");
    nonHeap.gauge("Used", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getNonHeapMemoryUsage().getUsed();
        }
    });
    nonHeap.gauge("Committed", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getNonHeapMemoryUsage().getCommitted();
        }
    });
    nonHeap.gauge("Max", new Gauge<Long>() {

        @Override
        public Long getValue() {
            return mxBean.getNonHeapMemoryUsage().getMax();
        }
    });
    List<BufferPoolMXBean> bufferMxBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    for (final BufferPoolMXBean bufferMxBean : bufferMxBeans) {
        MetricGroup bufferGroup = metrics.addGroup(WordUtils.capitalize(bufferMxBean.getName()));
        bufferGroup.gauge("Count", new Gauge<Long>() {

            @Override
            public Long getValue() {
                return bufferMxBean.getCount();
            }
        });
        bufferGroup.gauge("MemoryUsed", new Gauge<Long>() {

            @Override
            public Long getValue() {
                return bufferMxBean.getMemoryUsed();
            }
        });
        bufferGroup.gauge("TotalCapacity", new Gauge<Long>() {

            @Override
            public Long getValue() {
                return bufferMxBean.getTotalCapacity();
            }
        });
    }
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) BufferPoolMXBean(java.lang.management.BufferPoolMXBean) MetricGroup(org.apache.flink.metrics.MetricGroup)

Example 2 with BufferPoolMXBean

use of java.lang.management.BufferPoolMXBean in project elasticsearch by elastic.

the class JvmStats method jvmStats.

public static JvmStats jvmStats() {
    MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
    long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
    long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
    long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
    memUsage = memoryMXBean.getNonHeapMemoryUsage();
    long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
    long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    List<MemoryPool> pools = new ArrayList<>();
    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        try {
            MemoryUsage usage = memoryPoolMXBean.getUsage();
            MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
            String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
            if (name == null) {
                // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
                continue;
            }
            pools.add(new MemoryPool(name, usage.getUsed() < 0 ? 0 : usage.getUsed(), usage.getMax() < 0 ? 0 : usage.getMax(), peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(), peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()));
        } catch (Exception ex) {
        /* ignore some JVMs might barf here with:
                 * java.lang.InternalError: Memory Pool not found
                 * we just omit the pool in that case!*/
        }
    }
    Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
    Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());
    List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
    GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
    for (int i = 0; i < collectors.length; i++) {
        GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
        collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()), gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
    }
    GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
    List<BufferPool> bufferPoolsList = Collections.emptyList();
    try {
        List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
        bufferPoolsList = new ArrayList<>(bufferPools.size());
        for (BufferPoolMXBean bufferPool : bufferPools) {
            bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(), bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
        }
    } catch (Exception e) {
    // buffer pools are not available
    }
    Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(), classLoadingMXBean.getUnloadedClassCount());
    return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads, garbageCollectors, bufferPoolsList, classes);
}
Also used : ArrayList(java.util.ArrayList) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryUsage(java.lang.management.MemoryUsage) IOException(java.io.IOException) BufferPoolMXBean(java.lang.management.BufferPoolMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 3 with BufferPoolMXBean

use of java.lang.management.BufferPoolMXBean in project neo4j by neo4j.

the class MemoryBuffersMetrics method start.

@Override
public void start() {
    for (final BufferPoolMXBean pool : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
        registry.register(name(MEMORY_BUFFER, prettifyName(pool.getName()), "count"), (Gauge<Long>) pool::getCount);
        registry.register(name(MEMORY_BUFFER, prettifyName(pool.getName()), "used"), (Gauge<Long>) pool::getMemoryUsed);
        registry.register(name(MEMORY_BUFFER, prettifyName(pool.getName()), "capacity"), (Gauge<Long>) pool::getTotalCapacity);
    }
}
Also used : BufferPoolMXBean(java.lang.management.BufferPoolMXBean)

Example 4 with BufferPoolMXBean

use of java.lang.management.BufferPoolMXBean in project jdk8u_jdk by JetBrains.

the class Basic method check.

// check counters
static void check(List<BufferPoolMXBean> pools, int minBufferCount, long minTotalCapacity) {
    int bufferCount = 0;
    long totalCap = 0;
    long totalMem = 0;
    for (BufferPoolMXBean pool : pools) {
        bufferCount += pool.getCount();
        totalCap += pool.getTotalCapacity();
        totalMem += pool.getMemoryUsed();
    }
    if (bufferCount < minBufferCount)
        throw new RuntimeException("Count less than expected");
    if (totalMem < minTotalCapacity)
        throw new RuntimeException("Memory usage less than expected");
    if (totalCap < minTotalCapacity)
        throw new RuntimeException("Total capacity less than expected");
}
Also used : BufferPoolMXBean(java.lang.management.BufferPoolMXBean)

Example 5 with BufferPoolMXBean

use of java.lang.management.BufferPoolMXBean in project jdk8u_jdk by JetBrains.

the class Leaky method main.

public static void main(String[] args) throws Exception {
    ThreadFactory threadFactory = new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            return t;
        }
    };
    AsynchronousChannelGroup group = AsynchronousChannelGroup.withFixedThreadPool(4, threadFactory);
    final int CONNECTION_COUNT = 10;
    Connection[] connections = new Connection[CONNECTION_COUNT];
    for (int i = 0; i < CONNECTION_COUNT; i++) {
        connections[i] = new Connection(group);
    }
    for (int i = 0; i < 1024; i++) {
        // initiate reads
        for (Connection conn : connections) {
            conn.startRead();
        }
        // write data so that the read can complete
        for (Connection conn : connections) {
            conn.write();
        }
        // complete read
        for (Connection conn : connections) {
            conn.finishRead();
        }
    }
    // print summary of buffer pool usage
    List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    for (BufferPoolMXBean pool : pools) System.out.format("         %8s             ", pool.getName());
    System.out.println();
    for (int i = 0; i < pools.size(); i++) System.out.format("%6s %10s %10s  ", "Count", "Capacity", "Memory");
    System.out.println();
    for (BufferPoolMXBean pool : pools) {
        System.out.format("%6d %10d %10d  ", pool.getCount(), pool.getTotalCapacity(), pool.getMemoryUsed());
    }
    System.out.println();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BufferPoolMXBean(java.lang.management.BufferPoolMXBean)

Aggregations

BufferPoolMXBean (java.lang.management.BufferPoolMXBean)10 MemoryUsage (java.lang.management.MemoryUsage)2 Metric (com.codahale.metrics.Metric)1 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)1 IOException (java.io.IOException)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1