當前位置: 首頁>>代碼示例>>Java>>正文


Java UnixOperatingSystemMXBean.getFreePhysicalMemorySize方法代碼示例

本文整理匯總了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;
        }
    }
 
開發者ID:advantageous,項目名稱:boon,代碼行數:11,代碼來源:Sys.java

示例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;
}
 
開發者ID:StallionCMS,項目名稱:stallion-core,代碼行數:44,代碼來源:SystemHealth.java


注:本文中的com.sun.management.UnixOperatingSystemMXBean.getFreePhysicalMemorySize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。