List of usage examples for java.lang.management ManagementFactory getMemoryMXBean
public static MemoryMXBean getMemoryMXBean()
From source file:MemoryUtil.java
private static MemoryMXBean getMemoryMXBean() { return ManagementFactory.getMemoryMXBean(); }
From source file:it.geosolutions.geobatch.ui.mvc.MemoryController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView("memory"); // jsp final MemoryMXBean mmxbean = ManagementFactory.getMemoryMXBean(); mav.addObject("objectPendingFinalizationCount", mmxbean.getObjectPendingFinalizationCount()); mav.addObject("nonHeapMemoryUsage", mmxbean.getNonHeapMemoryUsage()); mav.addObject("heapMemoryUsage", mmxbean.getHeapMemoryUsage()); mav.addObject("memoryPoolBeansList", ManagementFactory.getMemoryPoolMXBeans()); return mav;/*from ww w. ja va 2s. c om*/ }
From source file:com.gopivotal.cloudfoundry.test.core.MemoryUtils.java
/** * Creates an instance of the utility */ public MemoryUtils() { this(System.getenv(), ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()); }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
@Override public void appendInformation(InformationStringBuilder infoCollector) { osInfo(ManagementFactory.getOperatingSystemMXBean(), infoCollector); runtimeInfo(ManagementFactory.getRuntimeMXBean(), infoCollector); gcInfo(ManagementFactory.getGarbageCollectorMXBeans(), infoCollector); memoryInfo(ManagementFactory.getMemoryMXBean(), infoCollector); poolInfo(infoCollector);/* w ww.ja v a 2s . co m*/ threadInfo(ManagementFactory.getThreadMXBean(), infoCollector); }
From source file:ee.ria.xroad.common.util.SystemMetrics.java
/** * Initializes system metrics internals. *///from w w w . j a v a 2 s . c o m public static void init() { OperatingSystemMXBean osStatsBean = ManagementFactory.getOperatingSystemMXBean(); if (osStatsBean instanceof UnixOperatingSystemMXBean) { stats = ((UnixOperatingSystemMXBean) osStatsBean); } else { throw new RuntimeException("Unexpected OperatingSystemMXBean " + osStatsBean); } memoryStats = ManagementFactory.getMemoryMXBean(); }
From source file:com.chinamobile.bcbsp.comm.io.util.MemoryAllocator.java
/** Refresh memory status with current JVM status. */ private void refreshMemoryStatus() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); used = memoryUsage.getUsed();/*from w w w .ja v a 2s .com*/ committed = memoryUsage.getCommitted(); maxHeapSize = memoryUsage.getMax(); remain = maxHeapSize - used; }
From source file:com.chinamobile.bcbsp.comm.io.util.MemoryAllocator.java
/** Show the information of memory used. */ public void PrintMemoryInfo(Log LOG) { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); long usedNow = memoryUsage.getUsed(); long committedNow = memoryUsage.getCommitted(); long maxHeapSizeNow = memoryUsage.getMax(); long remainNow = maxHeapSize - used; LOG.info("Memory Usage **********************************************"); LOG.info("Memory Max ****************** " + maxHeapSizeNow); LOG.info("Memory Commit **************** " + committedNow + "-----Percents: " + committedNow * 1.0f / maxHeapSizeNow); LOG.info("Memory Used ****************** " + usedNow + "-----Percents: " + usedNow * 1.0f / maxHeapSizeNow); LOG.info("Memory Remain **************** " + remainNow + "-----Percents: " + remainNow * 1.0f / maxHeapSizeNow); }
From source file:it.damore.tomee.envmonitor.services.EnvMonitorService.java
@GET @Path("monitor") @Produces({ MediaType.APPLICATION_JSON }) public EnvironmentConfig getEnvConfig() throws IllegalAccessException, InvocationTargetException { logger.info("received a request..."); int mb = 1024 * 1024; //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); EnvironmentConfig b = new EnvironmentConfig(); b.setMaxMemory(runtime.maxMemory() / mb); b.setFreeMemory(runtime.freeMemory() / mb); b.setTotalMemory(runtime.totalMemory() / mb); b.setSystemProperties(System.getProperties()); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); LocalRuntimeMXBean myRuntimeMXBean = new LocalRuntimeMXBean(); BeanUtils.copyProperties(myRuntimeMXBean, runtimeMXBean); b.setRuntimeMXBean(myRuntimeMXBean); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); LocalMemoryMXBean myMemoryMXBean = new LocalMemoryMXBean(); myMemoryMXBean.setHeapMemoryUsage(memoryMXBean.getHeapMemoryUsage()); myMemoryMXBean.setNonHeapMemoryUsage(memoryMXBean.getNonHeapMemoryUsage()); myMemoryMXBean.setObjectPendingFinalizationCount(memoryMXBean.getObjectPendingFinalizationCount()); b.setMemoryMXBean(myMemoryMXBean);//w w w . j av a 2s. c om OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); LocalOperatingSystemMXBean myOperatingSystemMXBean = new LocalOperatingSystemMXBean(); BeanUtils.copyProperties(myOperatingSystemMXBean, operatingSystemMXBean); b.setOperatingSystemMXBean(myOperatingSystemMXBean); return b; }
From source file:com.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page.//from w ww .j av a 2 s . c o m */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); TemplateEngine.getInstance() .render(TemplateContext.builder().request(req).response(resp).template(TOOLS_TEMPLATE) .locale(req.getLocale()) .templateData(TemplateData.newTemplateData().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()) .put("totalBundles", bundles.length).put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryUsage.getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }
From source file:io.adeptj.runtime.servlet.ToolsServlet.java
/** * Renders tools page.// w w w . j av a2 s . c om */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { Bundle[] bundles = BundleContextHolder.getInstance().getBundleContext().getBundles(); long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); TemplateEngines.getDefault().render(TemplateContext.builder().request(req).response(resp) .template(TOOLS_TEMPLATE).locale(req.getLocale()) .contextObject(ContextObject.newContextObject().put("username", req.getRemoteUser()) .put("sysProps", System.getProperties().entrySet()).put("totalBundles", bundles.length) .put("bundles", bundles) .put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")") .put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")") .put("startTime", Date.from(Instant.ofEpochMilli(startTime))) .put("upTime", Times.format(startTime)) .put("maxMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getMax())) .put("usedMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getUsed())) .put("processors", Runtime.getRuntime().availableProcessors())) .build()); }