本文整理汇总了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;
}