本文整理匯總了Java中com.sun.management.UnixOperatingSystemMXBean.getFreePhysicalMemorySize方法的典型用法代碼示例。如果您正苦於以下問題:Java UnixOperatingSystemMXBean.getFreePhysicalMemorySize方法的具體用法?Java UnixOperatingSystemMXBean.getFreePhysicalMemorySize怎麽用?Java UnixOperatingSystemMXBean.getFreePhysicalMemorySize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.management.UnixOperatingSystemMXBean
的用法示例。
在下文中一共展示了UnixOperatingSystemMXBean.getFreePhysicalMemorySize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: freePhysicalMemorySize
import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
public static long freePhysicalMemorySize() {
if (oracleJVMAndUnix) {
UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
return unix.getFreePhysicalMemorySize();
}else {
return -1;
}
}
示例2: hydrateSystemHealth
import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
public SystemHealth hydrateSystemHealth() {
Runtime rt = Runtime.getRuntime();
rt.gc();
long memUsage = (rt.totalMemory() - rt.freeMemory());
long usedMB = memUsage / 1024 / 1024;
setJvmMemoryUsage(memUsage);
setJvmMemoryUsageMb(usedMB);
setDiskFreeAppDirectory(new File(Settings.instance().getTargetFolder()).getUsableSpace());
setDiskFreeDataDirectory(new File(Settings.instance().getDataDirectory()).getUsableSpace());
setDiskFreeDataDirectoryMb(new File(Settings.instance().getDataDirectory()).getUsableSpace() / 1024 / 1024);
File logFile = new File(Settings.instance().getLogFile());
if (logFile.getParentFile().exists()) {
setDiskFreeLogDirectory(logFile.getParentFile().getUsableSpace());
}
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
if(os instanceof UnixOperatingSystemMXBean){
UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) os;
// get system load
// get process CPU load
// Get free memory
memorySwapSize = unixBean.getTotalSwapSpaceSize();
memorySwapFree = unixBean.getFreeSwapSpaceSize();
memoryPhysicalSize = unixBean.getTotalPhysicalMemorySize();
setMemoryPhysicalFree(unixBean.getFreePhysicalMemorySize());
long totalRamFree = unixBean.getFreeSwapSpaceSize() + unixBean.getFreePhysicalMemorySize();
long totalRam = unixBean.getTotalPhysicalMemorySize() + unixBean.getTotalSwapSpaceSize();
setMemoryPercentFree(new Double(totalRamFree) / new Double(totalRam));
setFileHandlesOpen(unixBean.getOpenFileDescriptorCount());
setFileHandlesMax(unixBean.getMaxFileDescriptorCount());
setFileHandlesAvailable(unixBean.getMaxFileDescriptorCount() - unixBean.getOpenFileDescriptorCount());
setCpusAvailable(unixBean.getAvailableProcessors());
setCpuAppUsage(unixBean.getProcessCpuLoad());
setCpuSystemUsage(unixBean.getSystemLoadAverage());
}
setCpuRollingAppUsage(HealthTracker.instance().getAverageAppCpuLoad());
setCpuRollingSystemUsage(HealthTracker.instance().getAverageSystemCpuLoad());
setSwapPagingRate(HealthTracker.instance().getSwapPages());
setSslExpiresDate(HealthTracker.instance().getSslExpires());
setSslExpiresWithin21Days(HealthTracker.instance().getSslExpiresIn21());
setSslExpiresWithin7Days(HealthTracker.instance().getSslExpiresIn7());
return this;
}