Java Code Examples for java.lang.management.ManagementFactory#getPlatformMXBeans()

The following examples show how to use java.lang.management.ManagementFactory#getPlatformMXBeans() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryUtil.java    From antsdb with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    for (BufferPoolMXBean pool:pools) {
        System.out.println(String.format(
                "%s %d/%d", 
                pool.getName(), 
                pool.getMemoryUsed(), 
                pool.getTotalCapacity()));
    }
    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    for (String arg:RuntimemxBean.getInputArguments()) {
        System.out.println(arg); 
    }
    HotSpotDiagnosticMXBean hsdiag = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
    for (VMOption i:hsdiag.getDiagnosticOptions()) {
        System.out.println(i.getName() + ":" + i.getValue());
    }
    System.out.println(hsdiag.getVMOption("MaxDirectMemorySize"));
    System.out.println(sun.misc.VM.maxDirectMemory());
    System.out.println(getDirectMemoryUsed());
}
 
Example 2
Source File: AbstractContainer.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
AbstractContainer(
        final Map<String, Object> attributes,
        SystemConfig parent)
{
    super(parent, attributes);
    _parent = parent;
    _eventLogger = parent.getEventLogger();
    _jvmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    BufferPoolMXBean bufferPoolMXBean = null;
    List<BufferPoolMXBean> bufferPoolMXBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    for(BufferPoolMXBean mBean : bufferPoolMXBeans)
    {
        if (mBean.getName().equals("direct"))
        {
            bufferPoolMXBean = mBean;
            break;
        }
    }
    _bufferPoolMXBean = bufferPoolMXBean;
    if(attributes.get(CONFIDENTIAL_CONFIGURATION_ENCRYPTION_PROVIDER) != null )
    {
        _confidentialConfigurationEncryptionProvider =
                String.valueOf(attributes.get(CONFIDENTIAL_CONFIGURATION_ENCRYPTION_PROVIDER));
    }

}
 
Example 3
Source File: ProactiveGcTask.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private MemoryPoolMXBean getOldGenMemoryPool() {
	String OLD = "old";
	String TENURED = "tenured";

	MemoryPoolMXBean oldGenMemoryPool = null;
	List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class);
	for (MemoryPoolMXBean memoryPool : memoryPoolMXBeans) {
		String name = memoryPool.getName().trim().toLowerCase();
		if (name.contains(OLD) || name.contains(TENURED)) {
			oldGenMemoryPool = memoryPool;
			break;
		}
	}

	return oldGenMemoryPool;
}
 
Example 4
Source File: ByteBufferMXBeanTest.java    From openjdk-systemtest with Apache License 2.0 6 votes vote down vote up
public void testByteBufferMXBeanMethods() {
	List<BufferPoolMXBean> byteBufferPools = 
		ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
	
	for (int counter = 0; counter < 10; counter++) {
	
		for (BufferPoolMXBean bean: byteBufferPools) {
			
			// Name should not be blank or null
			assertNotNull ("MXBean name is null", bean.getName());
			assertFalse ("MXBean name is blank", bean.getName().equalsIgnoreCase(""));
			// Total capacity should not be negative
			assertTrue (bean.getName() + "'s total capacity was not greater than zero", bean.getTotalCapacity() >= 0);
			// Likewise memoryUsed
			assertTrue (bean.getName() + "'s memory used was not greater than zero", bean.getMemoryUsed() >= 0);
			
			assertTrue (bean.getName() + "'s object name is null or blank", 
					bean.getObjectName() != null &&	bean.getObjectName().toString() != "");
		}
	}
}
 
Example 5
Source File: ProactiveGcTask.java    From vjtools with Apache License 2.0 6 votes vote down vote up
private MemoryPoolMXBean getOldGenMemoryPool() {
	String OLD = "old";
	String TENURED = "tenured";

	MemoryPoolMXBean oldGenMemoryPool = null;
	List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class);
	for (MemoryPoolMXBean memoryPool : memoryPoolMXBeans) {
		String name = memoryPool.getName().trim().toLowerCase();
		if (name.contains(OLD) || name.contains(TENURED)) {
			oldGenMemoryPool = memoryPool;
			break;
		}
	}

	return oldGenMemoryPool;
}
 
Example 6
Source File: GetVMOption.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example 7
Source File: TestMaxCachedBufferSize.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static BufferPoolMXBean getDirectPool() {
    final List<BufferPoolMXBean> pools =
              ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    for (BufferPoolMXBean pool : pools) {
        if (pool.getName().equals("direct")) {
            return pool;
        }
    }
    throw new Error("could not find direct pool");
}
 
Example 8
Source File: SetAllVMOptions.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    setAllVMOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    setAllVMOptions(mbean);
}
 
Example 9
Source File: AltBufferPoolMetricSet.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Metric> getMetrics() {
  final Map<String, Metric> metrics = new HashMap<>();
  List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
  for (final BufferPoolMXBean pool : pools) {
    String name = pool.getName();
    metrics.put(name + ".Count", (Gauge<Long>)() -> pool.getCount());
    metrics.put(name + ".MemoryUsed", (Gauge<Long>)() -> pool.getMemoryUsed());
    metrics.put(name + ".TotalCapacity", (Gauge<Long>)() -> pool.getTotalCapacity());
  }
  return metrics;
}
 
Example 10
Source File: GetVMOption.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example 11
Source File: GetVMOption.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example 12
Source File: SetAllVMOptions.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    setAllVMOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    setAllVMOptions(mbean);
}
 
Example 13
Source File: SetAllVMOptions.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    setAllVMOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    setAllVMOptions(mbean);
}
 
Example 14
Source File: DashboardCommand.java    From arthas with Apache License 2.0 5 votes vote down vote up
private static void addBufferPoolMemoryInfo(TableElement table) {
    try {
        @SuppressWarnings("rawtypes")
        Class bufferPoolMXBeanClass = Class.forName("java.lang.management.BufferPoolMXBean");
        @SuppressWarnings("unchecked")
        List<BufferPoolMXBean> bufferPoolMXBeans = ManagementFactory.getPlatformMXBeans(bufferPoolMXBeanClass);
        for (BufferPoolMXBean mbean : bufferPoolMXBeans) {
            long used = mbean.getMemoryUsed();
            long total = mbean.getTotalCapacity();
            new MemoryEntry(mbean.getName(), used, total, Long.MIN_VALUE).addTableRow(table);
        }
    } catch (ClassNotFoundException e) {
        // ignore
    }
}
 
Example 15
Source File: DremioTest.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public SystemManager(){
  memoryBean = ManagementFactory.getMemoryMXBean();
  BufferPoolMXBean localBean = null;
  List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
  for(BufferPoolMXBean b : pools){
    if(b.getName().equals("direct")){
      localBean = b;

    }
  }
  directBean = localBean;
}
 
Example 16
Source File: SetAllVMOptions.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    setAllVMOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    setAllVMOptions(mbean);
}
 
Example 17
Source File: GetVMOption.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example 18
Source File: GetDiagnosticOptions.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkDiagnosticOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkDiagnosticOptions(mbean);
}
 
Example 19
Source File: GetDiagnosticOptions.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkDiagnosticOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkDiagnosticOptions(mbean);
}
 
Example 20
Source File: MemoryIterator.java    From Bats with Apache License 2.0 5 votes vote down vote up
private BufferPoolMXBean getDirectBean() {
  List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
  for (BufferPoolMXBean b : pools) {
    if (b.getName().equals("direct")) {
      return b;
    }
  }
  throw new IllegalStateException("Unable to find direct buffer bean.  JVM must be too old.");
}