当前位置: 首页>>代码示例>>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;未经允许,请勿转载。