List of usage examples for java.lang.management ManagementFactory getMemoryMXBean
public static MemoryMXBean getMemoryMXBean()
From source file:com.blm.orc.MemoryManager.java
/** * Create the memory manager./*from ww w.ja va 2 s. com*/ * @param conf use the configuration to find the maximum size of the memory * pool. */ MemoryManager(Configuration conf) { HiveConf.ConfVars poolVar = HiveConf.ConfVars.HIVE_ORC_FILE_MEMORY_POOL; double maxLoad = conf.getFloat(poolVar.varname, poolVar.defaultFloatVal); totalMemoryPool = Math.round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * maxLoad); }
From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java
/** * Add JVM heap metrics.//from w w w . j a va2 s .c o m * * @param result * the result */ protected void addHeapMetrics(Collection<Metric<?>> result) { MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); result.add(new Metric<Long>("heap.committed", memoryUsage.getCommitted() / 1024)); result.add(new Metric<Long>("heap.init", memoryUsage.getInit() / 1024)); result.add(new Metric<Long>("heap.used", memoryUsage.getUsed() / 1024)); result.add(new Metric<Long>("heap", memoryUsage.getMax() / 1024)); }
From source file:com.hs.mail.container.simple.SimpleSpringContainer.java
private static void startPerformanceMonitor(String interval) { int period = Integer.parseInt(interval); Timer timer = new Timer(); TimerTask memoryTask = new TimerTask() { ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); @Override//from w w w. jav a 2 s . c o m public void run() { int threadCount = threadBean.getThreadCount(); int peakThreadCount = threadBean.getPeakThreadCount(); MemoryUsage heap = memoryBean.getHeapMemoryUsage(); MemoryUsage nonHeap = memoryBean.getNonHeapMemoryUsage(); System.out.println(sdf.format(System.currentTimeMillis()) + "\t threads=" + threadCount + ";peakThreads=" + peakThreadCount + ";heap=" + heap + ";non-heap=" + nonHeap); } }; timer.schedule(memoryTask, 0, period * 1000); }
From source file:de.otto.mongodb.profiler.web.PageInterceptor.java
protected void addFooterViewModel(ModelAndView modelAndView, Locale locale) { final MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); final FooterViewModel model = new FooterViewModel(heap, runningSince, locale); modelAndView.addObject(FOOTER_VIEW_MODEL_ATTRIBUTE, model); }
From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java
/** * Add JVM heap metrics./*from w w w.ja va 2 s .c o m*/ * * @param result * the result */ protected void addNoHeapMetrics(Collection<Metric<?>> result) { MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage(); result.add(new Metric<Long>("noheap.committed", memoryUsage.getCommitted() / 1024)); result.add(new Metric<Long>("noheap.init", memoryUsage.getInit() / 1024)); result.add(new Metric<Long>("noheap.used", memoryUsage.getUsed() / 1024)); result.add(new Metric<Long>("noheap", memoryUsage.getMax() / 1024)); }
From source file:org.soitoolkit.commons.mule.util.MiscUtil.java
private static void printMemUsage() { int mb = 1024 * 1024; MemoryMXBean mxb = ManagementFactory.getMemoryMXBean(); MemoryUsage hm = mxb.getHeapMemoryUsage(); MemoryUsage nhm = mxb.getNonHeapMemoryUsage(); // int finalizable = mxb.getObjectPendingFinalizationCount(); logger.trace("Heap Memory: init/used/committed/max=" + hm.getInit() / mb + "/" + hm.getUsed() / mb + "/" + hm.getCommitted() / mb + "/" + hm.getMax() / mb); logger.trace("Non-Heap Mem: init/used/committed/max=" + nhm.getInit() / mb + "/" + nhm.getUsed() / mb + "/" + nhm.getCommitted() / mb + "/" + nhm.getMax() / mb); // logger.trace("finalizable: " + finalizable); //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); logger.trace("Used/Free/Total/Max:" //Print used memory + (runtime.totalMemory() - runtime.freeMemory()) / mb + "/" //Print free memory + runtime.freeMemory() / mb + "/" //Print total available memory + runtime.totalMemory() / mb + "/" //Print Maximum available memory + runtime.maxMemory() / mb); }
From source file:com.facebook.hive.orc.MemoryManager.java
/** * Create the memory manager./*from www . j a va 2s . c o m*/ * @param conf use the configuration to find the maximum size of the memory * pool. */ MemoryManager(Configuration conf) { double maxLoad = OrcConf.getFloatVar(conf, OrcConf.ConfVars.HIVE_ORC_FILE_MEMORY_POOL); totalMemoryPool = Math.round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * maxLoad); minAllocation = OrcConf.getLongVar(conf, OrcConf.ConfVars.HIVE_ORC_FILE_MIN_MEMORY_ALLOCATION); lowMemoryMode = OrcConf.getBoolVar(conf, OrcConf.ConfVars.HIVE_ORC_FILE_ENABLE_LOW_MEMORY_MODE); }
From source file:ch.admin.suis.msghandler.servlet.PingServlet.java
private String calcHeapSpace() { MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long max = heap.getMax(); long used = heap.getUsed(); int percent = (int) Math.round(100.0 * used / max); return used + ":" + max + ":" + percent; }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin//from w ww . j ava 2s. 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:ch.admin.suis.msghandler.servlet.PingServlet.java
private String calcPermSpace() { MemoryUsage nonHeap = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage(); long max = nonHeap.getMax(); long used = nonHeap.getUsed(); int percent = (int) Math.round(100.0 * used / max); return used + ":" + max + ":" + percent; }