List of usage examples for java.lang.management MemoryPoolMXBean getName
public String getName();
From source file:org.craftercms.commons.monitoring.MemoryMonitor.java
/** * Query all register MemoryPools to get information and create a {@link MemoryMonitor} Pojo * @return List with all the memory usage stats. *//*from w w w. j a v a2 s . c om*/ public static List<MemoryMonitor> getMemoryStats() { ArrayList<MemoryMonitor> memoryPoolInformation = new ArrayList<>(); MemoryUsage heapMem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); memoryPoolInformation.add(new MemoryMonitor(HEAP_MEMORY, heapMem)); MemoryUsage nonHeapMen = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage(); memoryPoolInformation.add(new MemoryMonitor(NON_HEAP_MEMORY, nonHeapMen)); for (MemoryPoolMXBean memMXBean : ManagementFactory.getMemoryPoolMXBeans()) { memoryPoolInformation.add(new MemoryMonitor(memMXBean.getName(), memMXBean.getUsage())); } return Collections.unmodifiableList(memoryPoolInformation); }
From source file:org.infoglue.deliver.applications.actions.ViewApplicationStateAction.java
private void addPermGenStatistics(List states) { Iterator iter1 = ManagementFactory.getMemoryPoolMXBeans().iterator(); while (iter1.hasNext()) { MemoryPoolMXBean item = (MemoryPoolMXBean) iter1.next(); long used = item.getUsage().getUsed() / 1024 / 1024; long max = item.getUsage().getMax() / 1024 / 1024; long usedDivided = used; long maxDivided = max; if (max > 100) { usedDivided = used / 10;//from w w w . j ava 2s. com maxDivided = max / 10; } states.add(getList("" + item.getName(), "" + used + " / " + max + "<div style='border: 1px solid #ccc; background-color: green; height: 10px; width: " + maxDivided + "px;'><div style='margin-top: 2px; background-color: red; height: 6px; width: " + usedDivided + "px;'></div></div>")); } long max = Runtime.getRuntime().maxMemory() / 1024 / 1024; long used = ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024); long usedDivided = used; long maxDivided = max; if (max > 100) { usedDivided = used / 10; maxDivided = max / 10; } states.add(getList("Heap summary", "" + used + " / " + max + "<div style='border: 1px solid #ccc; background-color: green; height: 10px; width: " + maxDivided + "px;'><div style='margin-top: 2px; background-color: red; height: 6px; width: " + usedDivided + "px;'></div></div>")); }
From source file:org.jahia.bin.errors.ErrorFileDumper.java
public static void outputSystemInfo(PrintWriter strOut, boolean systemProperties, boolean environmentVariables, boolean jahiaSettings, boolean memory, boolean caches, boolean threads, boolean deadlocks, boolean loadAverage) { if (systemProperties) { // now let's output the system properties. strOut.println();//from ww w . ja va2s. c o m strOut.println("System properties:"); strOut.println("-------------------"); Map<Object, Object> orderedProperties = new TreeMap<Object, Object>(System.getProperties()); Iterator<Map.Entry<Object, Object>> entrySetIter = orderedProperties.entrySet().iterator(); while (entrySetIter.hasNext()) { Map.Entry<Object, Object> curEntry = entrySetIter.next(); String curPropertyName = (String) curEntry.getKey(); String curPropertyValue = (String) curEntry.getValue(); strOut.println(" " + curPropertyName + " : " + curPropertyValue); } } if (environmentVariables) { // now let's output the environment variables. strOut.println(); strOut.println("Environment variables:"); strOut.println("-------------------"); Map<String, String> orderedProperties = new TreeMap<String, String>(System.getenv()); Iterator<Map.Entry<String, String>> entrySetIter = orderedProperties.entrySet().iterator(); while (entrySetIter.hasNext()) { Map.Entry<String, String> curEntry = entrySetIter.next(); String curPropertyName = curEntry.getKey(); String curPropertyValue = curEntry.getValue(); strOut.println(" " + curPropertyName + " : " + curPropertyValue); } } if (jahiaSettings) { strOut.println(); if (SettingsBean.getInstance() != null) { strOut.append("Server configuration (").append(Jahia.getFullProductVersion()).append(" - ") .append(Jahia.getBuildDate()).append("):"); strOut.println(); strOut.println("---------------------"); SettingsBean settings = SettingsBean.getInstance(); Map<Object, Object> jahiaOrderedProperties = new TreeMap<Object, Object>( settings.getPropertiesFile()); Iterator<Map.Entry<Object, Object>> jahiaEntrySetIter = jahiaOrderedProperties.entrySet() .iterator(); while (jahiaEntrySetIter.hasNext()) { Map.Entry<Object, Object> curEntry = jahiaEntrySetIter.next(); String curPropertyName = (String) curEntry.getKey(); String curPropertyValue = null; if (curEntry.getValue() == null) { curPropertyValue = null; } else if (curEntry.getValue() instanceof String) { curPropertyValue = (String) curEntry.getValue(); } else { curPropertyValue = curEntry.getValue().toString(); } if (curPropertyName.toLowerCase().indexOf("password") == -1 && (!"mail_server".equals(curPropertyName) || !StringUtils.contains(curPropertyValue, "&password=") && !StringUtils.contains(curPropertyValue, "?password="))) { strOut.println(" " + curPropertyName + " = " + curPropertyValue); } } } } if (memory) { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); printMemoryUsage(MemoryType.HEAP.toString(), memoryUsage, strOut); memoryUsage = memoryMXBean.getNonHeapMemoryUsage(); printMemoryUsage(MemoryType.NON_HEAP.toString(), memoryUsage, strOut); strOut.println("--------------"); strOut.println("Memory pool details"); strOut.println("--------------"); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean bean : memoryPoolMXBeans) { printMemoryUsage("Memory Pool \"" + bean.getName() + "\" (" + bean.getType().toString() + ")", bean.getUsage(), strOut); } } if (caches) { strOut.println(); DecimalFormat percentFormat = new DecimalFormat("###.##"); if (SpringContextSingleton.getInstance().isInitialized() && (ServicesRegistry.getInstance().getCacheService() != null)) { strOut.println("Cache status:"); strOut.println("--------------"); // non Ehcaches SortedSet<String> sortedCacheNames = new TreeSet<>( ServicesRegistry.getInstance().getCacheService().getNames()); for (String sortedCacheName : sortedCacheNames) { final Cache<Object, Object> objectCache = ServicesRegistry.getInstance().getCacheService() .getCache(sortedCacheName); if (objectCache != null && !(((Cache<?, ?>) objectCache).getCacheImplementation() instanceof EhCacheImpl)) { String efficiencyStr = "0"; if (!Double.isNaN(objectCache.getCacheEfficiency())) { efficiencyStr = percentFormat.format(objectCache.getCacheEfficiency()); } strOut.println(sortedCacheName + ": size=" + objectCache.size() + ", successful hits=" + objectCache.getSuccessHits() + ", total hits=" + objectCache.getTotalHits() + ", efficiency=" + efficiencyStr + "%"); } } } // Ehcaches List<CacheManager> cacheManagers = CacheManager.ALL_CACHE_MANAGERS; for (CacheManager ehcacheManager : cacheManagers) { String[] ehcacheNames = ehcacheManager.getCacheNames(); java.util.Arrays.sort(ehcacheNames); for (String ehcacheName : ehcacheNames) { Ehcache ehcache = ehcacheManager.getEhcache(ehcacheName); strOut.append(ehcacheName).append(": "); if (ehcache != null) { StatisticsGateway ehcacheStats = ehcache.getStatistics(); String efficiencyStr = "0"; if (ehcacheStats.cacheHitCount() + ehcacheStats.cacheMissCount() > 0) { efficiencyStr = percentFormat.format(ehcacheStats.cacheHitCount() * 100f / (ehcacheStats.cacheHitCount() + ehcacheStats.cacheMissCount())); } strOut.append("size=" + ehcacheStats.getSize() + ", successful hits=" + ehcacheStats.cacheHitCount() + ", total hits=" + (ehcacheStats.cacheHitCount() + ehcacheStats.cacheMissCount()) + ", efficiency=" + efficiencyStr + "%"); strOut.println(); } } } } ThreadMonitor threadMonitor = null; if (threads) { strOut.println(); strOut.println("Thread status:"); strOut.println("--------------"); threadMonitor = ThreadMonitor.getInstance(); threadMonitor.generateThreadInfo(strOut); } if (deadlocks) { strOut.println(); strOut.println("Deadlock status:"); threadMonitor = threadMonitor != null ? threadMonitor : ThreadMonitor.getInstance(); ; String deadlock = threadMonitor.findDeadlock(); strOut.println(deadlock != null ? deadlock : "none"); } if (loadAverage) { strOut.println(); strOut.println("Request load average:"); strOut.println("---------------------"); RequestLoadAverage info = RequestLoadAverage.getInstance(); if (info != null) { strOut.println("Over one minute=" + info.getOneMinuteLoad() + " Over five minute=" + info.getFiveMinuteLoad() + " Over fifteen minute=" + info.getFifteenMinuteLoad()); } else { strOut.println("not available"); } strOut.println(); } strOut.flush(); }
From source file:org.mifos.framework.ApplicationInitializer.java
private void printMemoryPool() { logger.info("Memory MXBean"); logger.info("Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()); logger.info("Non-Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()); logger.info("-----Memory Pool MXBeans------"); Iterator<MemoryPoolMXBean> iter = ManagementFactory.getMemoryPoolMXBeans().iterator(); while (iter.hasNext()) { MemoryPoolMXBean item = iter.next(); logger.info("Name: " + item.getName()); logger.info("Type: " + item.getType()); logger.info("Usage: " + item.getUsage()); logger.info("Peak Usage: " + item.getPeakUsage()); logger.info("Collection Usage: " + item.getCollectionUsage()); logger.info("+++++++++++++++++++"); }//from w ww.j ava 2s.com }
From source file:org.rhq.enterprise.agent.promptcmd.GCPromptCommand.java
private void printCurrentMemoryUsage(PrintWriter out) { final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean(); printGlobalMemoryUsage(out, memoryMxBean); List<MemoryPoolMXBean> poolMxBeans = ManagementFactory.getMemoryPoolMXBeans(); if (poolMxBeans != null) { for (MemoryPoolMXBean bean : poolMxBeans) { if (bean.isValid()) { String name = bean.getName(); MemoryType type = bean.getType(); MemoryUsage usage = bean.getUsage(); printMemoryUsage(out, name, type, usage); }/*w ww . ja v a 2s .co m*/ } } return; }
From source file:org.toobsframework.management.MemoryMonitor.java
private void init() { MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); ((NotificationBroadcaster) mem).addNotificationListener(listener, null, null); for (MemoryPoolMXBean memPool : ManagementFactory.getMemoryPoolMXBeans()) { if (memPool.isUsageThresholdSupported()) { memPools.put(memPool.getName(), memPool); log.info("Putting Pool " + memPool.getName()); setUsageThreshold(memPool, 0.7); }/*from ww w .ja v a2 s. c om*/ } }