List of usage examples for java.lang.management MemoryPoolMXBean getType
public MemoryType getType();
From source file:mondrian.util.UtilCompatibleJdk15.java
private static MemoryPoolMXBean findTenuredGenPool() { for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { if (pool.getType() == MemoryType.HEAP) { return pool; }/* w ww . ja v a2s .co m*/ } throw new AssertionError("Could not find tenured space"); }
From source file:io.ecarf.core.utils.Utils.java
/** * Log memory usage//from ww w. j a v a 2 s .c om * @return */ public static long getMemoryUsage() { List<MemoryPoolMXBean> memoryPools = new ArrayList<MemoryPoolMXBean>( ManagementFactory.getMemoryPoolMXBeans()); long usedHeapMemoryAfterLastGC = 0; for (MemoryPoolMXBean memoryPool : memoryPools) { if (memoryPool.getType().equals(MemoryType.HEAP)) { MemoryUsage poolCollectionMemoryUsage = memoryPool.getCollectionUsage(); usedHeapMemoryAfterLastGC += poolCollectionMemoryUsage.getUsed(); } } return usedHeapMemoryAfterLastGC; }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
private void poolInfo(InformationStringBuilder builder) { builder.addSection("Memory pool information"); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) { builder.append(String.format("Name: %s, Type: %s\n%s\n", memoryPoolMXBean.getName(), memoryPoolMXBean.getType(), format(memoryPoolMXBean.getUsage()))); }//from w w w. j a v a 2s. co m }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin/*from w w w . j a v a2 s . c o m*/ @APIDescription("Gets the application system status") @Produces({ MediaType.APPLICATION_JSON }) @DataType(ApplicationStatus.class) @Path("/status") public Response getApplicationStatus() { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ApplicationStatus applicationStatus = new ApplicationStatus(); applicationStatus.setApplicationVersion(PropertiesManager.getApplicationVersion()); applicationStatus.setProcessorCount(operatingSystemMXBean.getAvailableProcessors()); applicationStatus.setSystemLoad(operatingSystemMXBean.getSystemLoadAverage()); applicationStatus.setSystemProperties(runtimeMXBean.getSystemProperties()); applicationStatus.getHeapMemoryStatus().setName("Heap"); applicationStatus.getHeapMemoryStatus().setDetails(memoryMXBean.getHeapMemoryUsage().toString()); applicationStatus.getHeapMemoryStatus() .setInitKb(memoryMXBean.getHeapMemoryUsage().getInit() != 0 ? memoryMXBean.getHeapMemoryUsage().getInit() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setUsedKb(memoryMXBean.getHeapMemoryUsage().getUsed() != 0 ? memoryMXBean.getHeapMemoryUsage().getUsed() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setMaxKb(memoryMXBean.getHeapMemoryUsage().getMax() != 0 ? memoryMXBean.getHeapMemoryUsage().getMax() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setCommitedKb(memoryMXBean.getHeapMemoryUsage().getCommitted() != 0 ? memoryMXBean.getHeapMemoryUsage().getCommitted() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus().setName("Non-Heap"); applicationStatus.getNonHeapMemoryStatus().setDetails(memoryMXBean.getNonHeapMemoryUsage().toString()); applicationStatus.getNonHeapMemoryStatus() .setInitKb(memoryMXBean.getNonHeapMemoryUsage().getInit() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getInit() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setUsedKb(memoryMXBean.getNonHeapMemoryUsage().getUsed() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getUsed() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setMaxKb(memoryMXBean.getNonHeapMemoryUsage().getMax() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getMax() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setCommitedKb(memoryMXBean.getNonHeapMemoryUsage().getCommitted() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getCommitted() / 1024 : 0); applicationStatus.setLiveThreadCount(threadMXBean.getThreadCount()); applicationStatus.setTotalThreadCount(threadMXBean.getTotalStartedThreadCount()); applicationStatus.setStartTime(new Date(runtimeMXBean.getStartTime())); applicationStatus.setUpTime(TimeUtil.millisToString(runtimeMXBean.getUptime())); for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { applicationStatus.getGarbageCollectionInfos() .add(TimeUtil.millisToString(garbageCollectorMXBean.getCollectionTime()) + " - (" + garbageCollectorMXBean.getCollectionCount() + ")"); } for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) { MemoryPoolStatus memoryPoolStatus = new MemoryPoolStatus(); memoryPoolStatus.setName(memoryPoolMXBean.getName() + " - " + memoryPoolMXBean.getType()); memoryPoolStatus.setDetails(memoryPoolMXBean.getUsage().toString()); memoryPoolStatus.setInitKb( memoryPoolMXBean.getUsage().getInit() != 0 ? memoryPoolMXBean.getUsage().getInit() / 1024 : 0); memoryPoolStatus.setUsedKb( memoryPoolMXBean.getUsage().getUsed() != 0 ? memoryPoolMXBean.getUsage().getUsed() / 1024 : 0); memoryPoolStatus.setMaxKb( memoryPoolMXBean.getUsage().getMax() != 0 ? memoryPoolMXBean.getUsage().getMax() / 1024 : 0); memoryPoolStatus.setCommitedKb(memoryPoolMXBean.getUsage().getCommitted() != 0 ? memoryPoolMXBean.getUsage().getCommitted() / 1024 : 0); applicationStatus.getMemoryPools().add(memoryPoolStatus); } return sendSingleEntityResponse(applicationStatus); }
From source file:org.apache.hadoop.hive.llap.daemon.impl.LlapDaemon.java
public static long getTotalHeapSize() { // runtime.getMax() gives a very different number from the actual Xmx sizing. // you can iterate through the // http://docs.oracle.com/javase/7/docs/api/java/lang/management/MemoryPoolMXBean.html // from java.lang.management to figure this out, but the hard-coded params in the llap run.sh // result in 89% usable heap (-XX:NewRatio=8) + a survivor region which is technically not // in the usable space. long total = 0; for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans()) { long sz = mp.getUsage().getMax(); if (mp.getName().contains("Survivor")) { sz *= 2; // there are 2 survivor spaces }// www .ja v a 2s . co m if (mp.getType().equals(MemoryType.HEAP)) { total += sz; } } // round up to the next MB total += (total % (1024 * 1024)); return total; }
From source file:org.apache.pig.impl.util.SpillableMemoryManager.java
private SpillableMemoryManager() { ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null); List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans(); long totalSize = 0; for (MemoryPoolMXBean pool : mpbeans) { log.debug("Found heap (" + pool.getName() + ") of type " + pool.getType()); if (pool.getType() == MemoryType.HEAP) { long size = pool.getUsage().getMax(); totalSize += size;/* w w w .j av a2s . c o m*/ // CMS Old Gen or "tenured" is the only heap that supports // setting usage threshold. if (pool.isUsageThresholdSupported()) { tenuredHeap = pool; } } } extraGCSpillSizeThreshold = (long) (totalSize * extraGCThresholdFraction); if (tenuredHeap == null) { throw new RuntimeException("Couldn't find heap"); } configureMemoryThresholds(MEMORY_THRESHOLD_FRACTION_DEFAULT, COLLECTION_THRESHOLD_FRACTION_DEFAULT, UNUSED_MEMORY_THRESHOLD_DEFAULT); }
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 w ww . jav a2s . c om 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("+++++++++++++++++++"); }//www.j av a2 s . c o m }
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); }//from w ww .jav a2 s . c om } } return; }