List of usage examples for java.lang Runtime totalMemory
public native long totalMemory();
From source file:onlinefrontlines.admin.web.ServerInfoAction.java
/** * Execute the action//from w w w. j a v a2 s . c om */ protected WebView execute() throws Exception { Runtime r = Runtime.getRuntime(); // Get stats date = new Date().toString(); committedMemory = r.totalMemory(); maxMemory = r.maxMemory(); usedMemory = committedMemory - r.freeMemory(); cpuCount = Runtime.getRuntime().availableProcessors(); os = System.getProperty("os.name") + " (" + System.getProperty("sun.os.patch.level") + ") " + System.getProperty("os.arch") + " " + System.getProperty("os.version"); jvm = System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + " " + System.getProperty("java.vm.name"); for (String s : DbConnectionPool.getInstance().getDataSources().keySet()) dataSourceStatus.put(s, getDataSourceStatus(s)); servletContainer = servletContext.getServerInfo(); return getSuccessView(); }
From source file:org.ktunaxa.referral.server.service.SystemService.java
@Scheduled(fixedRate = 2000) public void showLog() { int mb = 1024 * 1024; // Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); log.info("##### Heap utilization statistics [MB] #####"); // Print used memory log.info("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb); // Print free memory log.info("Free Memory:" + runtime.freeMemory() / mb); // Print total available memory log.info("Total Memory:" + runtime.totalMemory() / mb); // Print Maximum available memory log.info("Max Memory:" + runtime.maxMemory() / mb); }
From source file:MIDletProps.java
/** * Show the value of the properties//w ww.j a v a 2 s . com */ public void startApp() { Runtime runtime = Runtime.getRuntime(); runtime.gc(); long free = runtime.freeMemory(); long total = runtime.totalMemory(); propbuf = new StringBuffer(50); props = new Form("System Properties"); props.append("Free Memory = " + free + "\n"); props.append("Total Memory = " + total + "\n"); props.append(showProp("microedition.configuration")); props.append(showProp("microedition.platform")); props.append(showProp("microedition.locale")); props.append(showProp("microedition.encoding")); props.append(showProp("microedition.encodingClass")); props.append(showProp("microedition.http_proxy")); props.addCommand(exitCommand); props.setCommandListener(this); display.setCurrent(props); }
From source file:com.liferay.portal.events.LogMemoryUsageAction.java
public void run(HttpServletRequest req, HttpServletResponse res) throws ActionException { Runtime runtime = Runtime.getRuntime(); NumberFormat nf = NumberFormat.getInstance(); String freeMemory = nf.format(runtime.freeMemory()); String totalMemory = nf.format(runtime.totalMemory()); String maxMemory = nf.format(runtime.maxMemory()); _log.debug("Memory Usage:\t" + freeMemory + "\t" + totalMemory + "\t" + maxMemory); }
From source file:edu.umn.cs.spatialHadoop.util.MemoryReporter.java
@Override public void run() { Runtime runtime = Runtime.getRuntime(); while (true) { LOG.info(String.format("Free memory %s / Total memory %s", humanReadable(runtime.freeMemory()), humanReadable(runtime.totalMemory()))); try {//from w w w. j a v a 2s . c o m Thread.sleep(1000 * 60); } catch (InterruptedException e) { } } }
From source file:org.onosproject.ospf.controller.impl.Controller.java
public Map<String, Long> getMemory() { Map<String, Long> m = new HashMap<>(); Runtime runtime = Runtime.getRuntime(); m.put("total", runtime.totalMemory()); m.put("free", runtime.freeMemory()); return m;//from w w w . ja v a2s .c om }
From source file:ca.simplegames.micro.controllers.StatsController.java
public void execute(MicroContext context, Map configuration) throws ControllerException { Map<String, Object> systemInfo = new HashMap<String, Object>(); Map<String, Object> osMap = new HashMap<String, Object>(); MBeanServerConnection mbeanServer = ManagementFactory.getPlatformMBeanServer(); OperatingSystemMXBean sunOperatingSystemMXBean = null; try {// w ww . j a v a2s. co m sunOperatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(mbeanServer, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); } catch (IOException e) { throw new ControllerException(e.getMessage()); } Runtime rt = Runtime.getRuntime(); long totalMemory = rt.totalMemory() / MEGA_BYTE; long freeMemory = rt.freeMemory() / MEGA_BYTE; long usedMemory = totalMemory - freeMemory; final long p100 = (int) Math.round(((double) freeMemory / (double) totalMemory) * 100); Map<String, Long> memInfo = new HashMap<String, Long>(); memInfo.put("total", totalMemory); memInfo.put("used", usedMemory); memInfo.put("free", freeMemory); memInfo.put("percent_free", p100); systemInfo.put("memory", memInfo); systemInfo.put("powered_by", POWERED_BY_MICRO); //cpu usage in milli secs long currentCpuUsage = sunOperatingSystemMXBean.getProcessCpuTime() / 1000000; osMap.put("cpu_usage", currentCpuUsage); osMap.put("available_processors", sunOperatingSystemMXBean.getAvailableProcessors()); osMap.put("system_load_average", sunOperatingSystemMXBean.getSystemLoadAverage()); osMap.put("committed_virtual_memory_size", sunOperatingSystemMXBean.getCommittedVirtualMemorySize()); osMap.put("free_physical_memory_size", sunOperatingSystemMXBean.getFreePhysicalMemorySize()); osMap.put("total_physical_memory_size", sunOperatingSystemMXBean.getTotalPhysicalMemorySize()); osMap.put("free_swap_space_size", sunOperatingSystemMXBean.getFreeSwapSpaceSize()); osMap.put("total_swap_space_size", sunOperatingSystemMXBean.getTotalSwapSpaceSize()); systemInfo.put("os", osMap); List<GarbageCollectorMXBean> gc = ManagementFactory.getGarbageCollectorMXBeans(); List<Map> gcInfo = new ArrayList<Map>(); for (GarbageCollectorMXBean aGc : gc) { Map<String, Object> gcMap = new HashMap<String, Object>(); gcMap.put("name", aGc.getName()); gcMap.put("collection_count", aGc.getCollectionCount()); gcMap.put("collection_time", aGc.getCollectionTime()); gcInfo.add(gcMap); } systemInfo.put("gc", gcInfo); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); Map<String, Object> threadInfoMap = new HashMap<String, Object>(); // more to come ;) threadInfoMap.put("peak_thread_count", threadMXBean.getPeakThreadCount()); threadInfoMap.put("thread_count", threadMXBean.getThreadCount()); threadInfoMap.put("total_started_thread_count", threadMXBean.getTotalStartedThreadCount()); long[] deadlockedThreads = threadMXBean.findMonitorDeadlockedThreads(); threadInfoMap.put("dead_locked_thread_count", deadlockedThreads != null ? deadlockedThreads.length : 0); systemInfo.put("thread_info", threadInfoMap); JSONObject sysinfoJson = new JSONObject(Collections.singletonMap("system_info", systemInfo)); String sysinfoString = null; try { sysinfoString = context.getRequest().getParameter("pretty") != null ? sysinfoJson.toString(2) : sysinfoJson.toString(); } catch (JSONException e) { e.printStackTrace(); throw new ControllerException(e.getMessage()); } context.getRackResponse().withContentType(Mime.mimeType(JSON_TYPE)).withBody(sysinfoString) .withContentLength(sysinfoString.length()).with(Rack.MESSAGE_STATUS, HttpServletResponse.SC_OK); context.halt(); }
From source file:org.apache.pulsar.common.stats.JvmMetrics.java
public List<Metrics> generate() { Metrics m = createMetrics();/* w w w. j av a2 s . co m*/ Runtime r = Runtime.getRuntime(); m.put("jvm_heap_used", r.totalMemory() - r.freeMemory()); m.put("jvm_max_memory", r.maxMemory()); m.put("jvm_total_memory", r.totalMemory()); m.put("jvm_direct_memory_used", getJvmDirectMemoryUsed()); m.put("jvm_max_direct_memory", PlatformDependent.maxDirectMemory()); m.put("jvm_thread_cnt", getThreadCount()); this.gcLogger.logMetrics(m); long totalAllocated = 0; long totalUsed = 0; for (PoolArenaMetric arena : PooledByteBufAllocator.DEFAULT.directArenas()) { for (PoolChunkListMetric list : arena.chunkLists()) { for (PoolChunkMetric chunk : list) { int size = chunk.chunkSize(); int used = size - chunk.freeBytes(); totalAllocated += size; totalUsed += used; } } } m.put(this.componentName + "_default_pool_allocated", totalAllocated); m.put(this.componentName + "_default_pool_used", totalUsed); return Lists.newArrayList(m); }
From source file:org.ngrinder.operation.cotroller.StatisticsController.java
/** * Get current jvm stat/*from w ww . ja va 2s . c o m*/ * * @return map for jvm used/free/total/max */ private Map<String, Long> getJVMStat() { Runtime runtime = Runtime.getRuntime(); Map<String, Long> stat = new HashMap<String, Long>(); stat.put("used", runtime.totalMemory() - runtime.freeMemory()); stat.put("free", runtime.freeMemory()); stat.put("total", runtime.totalMemory()); stat.put("max", runtime.maxMemory()); return stat; }
From source file:com.betfair.tornjak.monitor.FreeMemoryMonitor.java
/** * Answers the amount of free memory in this runtime environment, as a percentage. *///from w ww .j a v a2 s .c o m @Override @ManagedAttribute() public int getFreeMemoryPercentage() { Runtime runtime = Runtime.getRuntime(); // 'totalMemory' is how much heap we have *currently* // - this may increase up to 'maxMemory' (and can decrease) long totalMemory = runtime.totalMemory(); // 'freeMemory' is 'totalMemory' - allocated) long freeMemory = runtime.freeMemory(); // Work out how much we have used long allocatedMemory = totalMemory - freeMemory; // 'maxMemory' is equivalent to the JVM option '-Xmx' long maxMemory = runtime.maxMemory(); // Work out the percentage used return (int) (100 - (allocatedMemory * 100 / maxMemory)); }