本文整理匯總了Java中com.sun.management.UnixOperatingSystemMXBean.getFreeSwapSpaceSize方法的典型用法代碼示例。如果您正苦於以下問題:Java UnixOperatingSystemMXBean.getFreeSwapSpaceSize方法的具體用法?Java UnixOperatingSystemMXBean.getFreeSwapSpaceSize怎麽用?Java UnixOperatingSystemMXBean.getFreeSwapSpaceSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.management.UnixOperatingSystemMXBean
的用法示例。
在下文中一共展示了UnixOperatingSystemMXBean.getFreeSwapSpaceSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: freeSwapSpaceSize
import com.sun.management.UnixOperatingSystemMXBean; //導入方法依賴的package包/類
public static long freeSwapSpaceSize() {
if (oracleJVMAndUnix) {
UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
return unix.getFreeSwapSpaceSize();
}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;
}