List of usage examples for java.lang.management BufferPoolMXBean getName
String getName();
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 a va 2 s . 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/*from www. j av a 2s . c o 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.pulsar.common.stats.JvmMetrics.java
public static long getJvmDirectMemoryUsed() { if (directMemoryUsage != null) { try {/*from ww w . j a va2s . com*/ return ((AtomicLong) directMemoryUsage.get(null)).get(); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Failed to get netty-direct-memory used count {}", e.getMessage()); } } } List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); for (BufferPoolMXBean pool : pools) { if (pool.getName().equals("direct")) { return pool.getMemoryUsed(); } } // Couldnt get direct memory usage return -1; }