List of usage examples for java.lang Runtime freeMemory
public native long freeMemory();
From source file:com.joliciel.talismane.utils.LogUtils.java
/** * Log the available runtime memory.// w ww . j av a2 s . com */ public static void logMemory(Log logger) { if (logger.isTraceEnabled()) { //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); logger.trace("##### Heap utilization statistics [MB] #####"); //Print used memory logger.trace("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / MEGABYTE); //Print free memory logger.trace("Free Memory:" + runtime.freeMemory() / MEGABYTE); //Print total available memory logger.trace("Total Memory:" + runtime.totalMemory() / MEGABYTE); //Print Maximum available memory logger.trace("Max Memory:" + runtime.maxMemory() / MEGABYTE); } }
From source file:com.baasbox.service.storage.StatisticsService.java
public static ImmutableMap memory() { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); ImmutableMap response = null;/*from w w w .j a v a 2 s .c o m*/ if (BBConfiguration.getStatisticsSystemMemory()) { Runtime rt = Runtime.getRuntime(); long maxMemory = rt.maxMemory(); long freeMemory = rt.freeMemory(); long totalMemory = rt.totalMemory(); response = ImmutableMap.of("max_allocable_memory", maxMemory, "current_allocate_memory", totalMemory, "used_memory_in_the_allocate_memory", totalMemory - freeMemory, "free_memory_in_the_allocated_memory", freeMemory); } else { response = ImmutableMap.of("max_allocable_memory", 0, "current_allocate_memory", 0, "used_memory_in_the_allocate_memory", 0, "free_memory_in_the_allocated_memory", 0); } if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); return response; }
From source file:net.ymate.platform.core.util.RuntimeUtils.java
/** * //from w w w .j a v a 2s .c o m * * @return ?? */ public static long gc() { Runtime rt = Runtime.getRuntime(); long lastUsed = rt.totalMemory() - rt.freeMemory(); rt.gc(); return lastUsed - rt.totalMemory() + rt.freeMemory(); }
From source file:com.eryansky.utils.SigarUtil.java
/** * ??//from w w w.j a va2 s. co m * @throws Exception */ public static ServerStatus getServerStatus() throws Exception { ServerStatus status = new ServerStatus(); status.setServerTime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss")); status.setServerName(System.getenv().get("COMPUTERNAME")); Runtime rt = Runtime.getRuntime(); //status.setIp(InetAddress.getLocalHost().getHostAddress()); status.setJvmTotalMem(rt.totalMemory() / (1024 * 1024)); status.setJvmFreeMem(rt.freeMemory() / (1024 * 1024)); status.setJvmMaxMem(rt.maxMemory() / (1024 * 1024)); Properties props = System.getProperties(); status.setServerOs(props.getProperty("os.name") + " " + props.getProperty("os.arch") + " " + props.getProperty("os.version")); status.setJavaHome(props.getProperty("java.home")); status.setJavaVersion(props.getProperty("java.version")); status.setJavaTmpPath(props.getProperty("java.io.tmpdir")); Sigar sigar = new Sigar(); getServerCpuInfo(sigar, status); getServerDiskInfo(sigar, status); getServerMemoryInfo(sigar, status); return status; }
From source file:gridool.util.system.SystemUtils.java
public static long getFreeMemory() { final Runtime runtime = Runtime.getRuntime(); return runtime.freeMemory(); }
From source file:org.openkoala.koala.monitor.support.ServerStatusCollector.java
/** * ???/* ww w . j av a 2s . c o m*/ * @return */ public static void getServerBaseInfo(ServerStatusVo status) { status.setServerTime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss")); status.setServerName(System.getenv().get("COMPUTERNAME")); // status.setJavaServer(RuntimeContext.getContext().getServerName()); // status.setDeployPath(RuntimeContext.getContext().getDeployPath()); Runtime rt = Runtime.getRuntime(); status.setJvmTotalMem(rt.totalMemory() / (1024 * 1024)); status.setJvmFreeMem(rt.freeMemory() / (1024 * 1024)); Properties props = System.getProperties(); status.setServerOs(props.getProperty("os.name") + " " + props.getProperty("os.arch") + " " + props.getProperty("os.version")); status.setJavaHome(props.getProperty("java.home")); status.setJavaVersion(props.getProperty("java.version")); status.setJavaTmpPath(props.getProperty("java.io.tmpdir")); }
From source file:org.tranche.logs.LogUtil.java
/** * //from w w w. j a va 2 s.c o m * @return */ public static final String getEnvironmentDump() { StringBuffer buf = new StringBuffer(); buf.append("Build: @buildNumber" + "\n"); try { buf.append("Internet host/address: " + java.net.InetAddress.getLocalHost() + "\n"); } catch (Exception e) { } Runtime rt = Runtime.getRuntime(); long fm = rt.freeMemory(); long tm = rt.totalMemory(); long mm = rt.maxMemory(); buf.append("Memory: "); buf.append("\n"); buf.append(" Free: " + TextUtil.formatBytes(fm)); buf.append("\n"); buf.append(" Used: " + TextUtil.formatBytes(tm - fm)); buf.append("\n"); buf.append(" Total: " + TextUtil.formatBytes(tm)); buf.append("\n"); buf.append(" Maximum:" + TextUtil.formatBytes(mm)); buf.append("\n" + "\n" + "\n"); return buf.toString(); }
From source file:com.viettel.logistic.common.logs.KPILogger.java
public static void checkMemory(String functionName) { //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); int mb = 1024 * 1024; System.out.println("##### Heap utilization statistics [MB] #####"); //Print used memory System.out.println(functionName + " Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb); //Print free memory System.out.println(functionName + " Free Memory:" + runtime.freeMemory() / mb); //Print total available memory System.out.println(functionName + " Total Memory:" + runtime.totalMemory() / mb); //Print Maximum available memory System.out.println(functionName + " Max Memory:" + runtime.maxMemory() / mb); }
From source file:org.apache.flink.runtime.instance.HardwareDescriptionFactory.java
/** * Returns the size of free memory in bytes available to the JVM. * //from w w w . j a va2 s.c o m * @return the size of the free memory in bytes available to the JVM or <code>-1</code> if the size cannot be * determined */ private static long getSizeOfFreeMemory() { Runtime r = Runtime.getRuntime(); long available = r.maxMemory() - r.totalMemory() + r.freeMemory(); return available; }
From source file:com.dajodi.scandic.Util.java
public static void printMemory() { Runtime runtime = Runtime.getRuntime(); long maxMemory = runtime.maxMemory(); long allocatedMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); long totalFreeMemory = (freeMemory + (maxMemory - allocatedMemory)) / 1024; Log.d("free memory: " + freeMemory / 1024); Log.d("allocated memory: " + allocatedMemory / 1024); Log.d("max memory: " + maxMemory / 1024); Log.d("total free memory: " + totalFreeMemory); }