Example usage for java.lang.management BufferPoolMXBean getTotalCapacity

List of usage examples for java.lang.management BufferPoolMXBean getTotalCapacity

Introduction

In this page you can find the example usage for java.lang.management BufferPoolMXBean getTotalCapacity.

Prototype

long getTotalCapacity();

Source Link

Document

Returns an estimate of the total capacity of the buffers in this pool.

Usage

From source file:net.centro.rtb.monitoringcenter.metrics.system.jvm.BufferPoolMetricSet.java

BufferPoolMetricSet() {
    this.bufferPoolMXBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);

    List<BufferPoolStatus> bufferPoolStatuses = new ArrayList<>();
    Map<String, Metric> metricsByNames = new HashMap<>();

    for (final BufferPoolMXBean bufferPoolMXBean : bufferPoolMXBeans) {
        final String bufferPoolName = bufferPoolMXBean.getName();

        final Gauge<Long> sizeGauge = new Gauge<Long>() {
            @Override//from  w  w w .  j  av a 2s .c  o m
            public Long getValue() {
                return bufferPoolMXBean.getCount();
            }
        };
        metricsByNames.put(MetricNamingUtil.join(bufferPoolName, "size"), sizeGauge);

        final Gauge<Long> totalCapacityInBytesGauge = new Gauge<Long>() {
            @Override
            public Long getValue() {
                return bufferPoolMXBean.getTotalCapacity();
            }
        };
        metricsByNames.put(MetricNamingUtil.join(bufferPoolName, "totalCapacityInBytes"),
                totalCapacityInBytesGauge);

        final Gauge<Long> usedMemoryInBytesGauge;
        if (bufferPoolMXBean.getMemoryUsed() >= 0) {
            usedMemoryInBytesGauge = new Gauge<Long>() {
                @Override
                public Long getValue() {
                    return bufferPoolMXBean.getMemoryUsed();
                }
            };
            metricsByNames.put(MetricNamingUtil.join(bufferPoolName, "usedMemoryInBytes"),
                    usedMemoryInBytesGauge);
        } else {
            usedMemoryInBytesGauge = null;
        }

        bufferPoolStatuses.add(new BufferPoolStatus() {
            @Override
            public String getName() {
                return bufferPoolName;
            }

            @Override
            public Gauge<Long> getSizeGauge() {
                return sizeGauge;
            }

            @Override
            public Gauge<Long> getTotalCapacityInBytesGauge() {
                return totalCapacityInBytesGauge;
            }

            @Override
            public Gauge<Long> getUsedMemoryInBytesGauge() {
                return usedMemoryInBytesGauge;
            }
        });
    }

    this.bufferPoolStatuses = bufferPoolStatuses;
    this.metricsByNames = metricsByNames;
}

From source file:org.apache.flink.runtime.metrics.util.MetricUtils.java

private static void instantiateMemoryMetrics(MetricGroup metrics) {
    final MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean();
    MetricGroup heap = metrics.addGroup("Heap");
    heap.gauge("Used", new Gauge<Long>() {
        @Override// w w w  .j  av  a 2 s.  co  m
        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();
            }
        });
    }
}

From source file:org.apache.tajo.QueryTestCaseBase.java

@Before
public void printTestName() {
    /* protect a travis stalled build */
    BufferPoolMXBean direct = BufferPool.getDirectBufferPool();
    BufferPoolMXBean mapped = BufferPool.getMappedBufferPool();
    System.out.println(/*from  w w  w.j a  va  2  s  .  c  o  m*/
            String.format("Used heap: %s/%s, direct:%s/%s, mapped:%s/%s, Active Threads: %d, Run: %s.%s",
                    FileUtil.humanReadableByteCount(
                            Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(), false),
                    FileUtil.humanReadableByteCount(Runtime.getRuntime().maxMemory(), false),
                    FileUtil.humanReadableByteCount(direct.getMemoryUsed(), false),
                    FileUtil.humanReadableByteCount(direct.getTotalCapacity(), false),
                    FileUtil.humanReadableByteCount(mapped.getMemoryUsed(), false),
                    FileUtil.humanReadableByteCount(mapped.getTotalCapacity(), false), Thread.activeCount(),
                    getClass().getSimpleName(), name.getMethodName()));
}