@Test public void testVMInfo() throws Exception { VMInfo vmInfo = VMInfo.getVmInfo(); Assert.assertTrue(vmInfo != null); System.out.println(vmInfo.toString()); vmInfo.getDelta(); int count = 0; while(count < 10) { long startTime = System.currentTimeMillis(); while (true) { if (System.currentTimeMillis() > startTime + 1000) { break; } } vmInfo.getDelta(); count++; Thread.sleep(1000); } vmInfo.getDelta(false); System.out.println(vmInfo.totalString()); }
private VMInfo() { osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans(); osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion(); jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion(); totalProcessorCount = osMXBean.getAvailableProcessors(); startPhyOSStatus = new PhyOSStatus(); LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName()); if (VMInfo.isSunOsMBean(osMXBean)) { { startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize"); startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize"); startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount"); startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount"); } } for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) { GCStatus gcStatus = new GCStatus(); gcStatus.name = garbage.getName(); processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus); } if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) { for (MemoryPoolMXBean pool : memoryPoolMXBeanList) { MemoryStatus memoryStatus = new MemoryStatus(); memoryStatus.name = pool.getName(); memoryStatus.initSize = pool.getUsage().getInit(); memoryStatus.maxSize = pool.getUsage().getMax(); processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus); } } }
VMInfo { private VMInfo() { osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans(); osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion(); jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion(); totalProcessorCount = osMXBean.getAvailableProcessors(); startPhyOSStatus = new PhyOSStatus(); LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName()); if (VMInfo.isSunOsMBean(osMXBean)) { { startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize"); startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize"); startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount"); startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount"); } } for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) { GCStatus gcStatus = new GCStatus(); gcStatus.name = garbage.getName(); processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus); } if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) { for (MemoryPoolMXBean pool : memoryPoolMXBeanList) { MemoryStatus memoryStatus = new MemoryStatus(); memoryStatus.name = pool.getName(); memoryStatus.initSize = pool.getUsage().getInit(); memoryStatus.maxSize = pool.getUsage().getMax(); processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus); } } } }
VMInfo { private VMInfo() { osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans(); osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion(); jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion(); totalProcessorCount = osMXBean.getAvailableProcessors(); startPhyOSStatus = new PhyOSStatus(); LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName()); if (VMInfo.isSunOsMBean(osMXBean)) { { startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize"); startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize"); startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount"); startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount"); } } for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) { GCStatus gcStatus = new GCStatus(); gcStatus.name = garbage.getName(); processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus); } if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) { for (MemoryPoolMXBean pool : memoryPoolMXBeanList) { MemoryStatus memoryStatus = new MemoryStatus(); memoryStatus.name = pool.getName(); memoryStatus.initSize = pool.getUsage().getInit(); memoryStatus.maxSize = pool.getUsage().getMax(); processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus); } } } private  VMInfo(); }
VMInfo { private VMInfo() { osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans(); osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion(); jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion(); totalProcessorCount = osMXBean.getAvailableProcessors(); startPhyOSStatus = new PhyOSStatus(); LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName()); if (VMInfo.isSunOsMBean(osMXBean)) { { startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize"); startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize"); startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount"); startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount"); } } for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) { GCStatus gcStatus = new GCStatus(); gcStatus.name = garbage.getName(); processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus); } if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) { for (MemoryPoolMXBean pool : memoryPoolMXBeanList) { MemoryStatus memoryStatus = new MemoryStatus(); memoryStatus.name = pool.getName(); memoryStatus.initSize = pool.getUsage().getInit(); memoryStatus.maxSize = pool.getUsage().getMax(); processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus); } } } private  VMInfo(); static VMInfo getVmInfo(); String toString(); String totalString(); void getDelta(); synchronized void getDelta(boolean print); static boolean isSunOsMBean(OperatingSystemMXBean operatingSystem); static long getLongFromOperatingSystem(OperatingSystemMXBean operatingSystem, String methodName); }
VMInfo { private VMInfo() { osMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); garbageCollectorMXBeanList = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans(); memoryPoolMXBeanList = java.lang.management.ManagementFactory.getMemoryPoolMXBeans(); osInfo = runtimeMXBean.getVmVendor() + " " + runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion(); jvmInfo = osMXBean.getName() + " " + osMXBean.getArch() + " " + osMXBean.getVersion(); totalProcessorCount = osMXBean.getAvailableProcessors(); startPhyOSStatus = new PhyOSStatus(); LOG.info("VMInfo# operatingSystem class => " + osMXBean.getClass().getName()); if (VMInfo.isSunOsMBean(osMXBean)) { { startPhyOSStatus.totalPhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getTotalPhysicalMemorySize"); startPhyOSStatus.freePhysicalMemory = VMInfo.getLongFromOperatingSystem(osMXBean, "getFreePhysicalMemorySize"); startPhyOSStatus.maxFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getMaxFileDescriptorCount"); startPhyOSStatus.currentOpenFileDescriptorCount = VMInfo.getLongFromOperatingSystem(osMXBean, "getOpenFileDescriptorCount"); } } for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) { GCStatus gcStatus = new GCStatus(); gcStatus.name = garbage.getName(); processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus); } if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) { for (MemoryPoolMXBean pool : memoryPoolMXBeanList) { MemoryStatus memoryStatus = new MemoryStatus(); memoryStatus.name = pool.getName(); memoryStatus.initSize = pool.getUsage().getInit(); memoryStatus.maxSize = pool.getUsage().getMax(); processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus); } } } private  VMInfo(); static VMInfo getVmInfo(); String toString(); String totalString(); void getDelta(); synchronized void getDelta(boolean print); static boolean isSunOsMBean(OperatingSystemMXBean operatingSystem); static long getLongFromOperatingSystem(OperatingSystemMXBean operatingSystem, String methodName); static Object lock; }