List of usage examples for java.lang.management ManagementFactory getPlatformMXBeans
public static <T extends PlatformManagedObject> List<T> getPlatformMXBeans(Class<T> mxbeanInterface)
From source file:Test.java
public static void main(String[] args) { RuntimeMXBean mxBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); System.out.println("JVM Name: " + mxBean.getName()); System.out.println("JVM Specification Name: " + mxBean.getSpecName()); System.out.println("JVM Specification Version: " + mxBean.getSpecVersion()); System.out.println("JVM Implemenation Name: " + mxBean.getVmName()); System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor()); System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion()); // Using the getPlatformMXBeans method List<OperatingSystemMXBean> list = ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class); System.out.println("size: " + list.size()); for (OperatingSystemMXBean bean : list) { System.out.println("Operating System Name: " + bean.getName()); System.out.println("Operating System Architecture: " + bean.getArch()); System.out.println("Operating System Version: " + bean.getVersion()); }//from w ww . j a v a2s .c o m }
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/*w w w . java2 s.c om*/ 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//www . ja v a2s .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 w w w . j av a 2 s. 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; }