DevOps读书DevOps之路DEVOPS

Java获取操作系统信息

2018-03-22  本文已影响23人  learningops

代码

    public static void main(String[] args) {
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        if (os instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixOs = (UnixOperatingSystemMXBean) os; //10240
            System.out.println(unixOs.getMaxFileDescriptorCount()); //37
            System.out.println(unixOs.getOpenFileDescriptorCount()); //8
            System.out.println(unixOs.getArch()); //x86_64
            System.out.println(unixOs.getAvailableProcessors()); //8
            System.out.println(unixOs.getName()); //Mac OS X
            System.out.println(unixOs.getObjectName()); //java.lang:type=OperatingSystem
            System.out.println(unixOs.getSystemLoadAverage()); //2.658203125
            System.out.println(unixOs.getVersion()); //10.13.3
            System.out.println(unixOs.getCommittedVirtualMemorySize()); //10345111552
            System.out.println(unixOs.getFreePhysicalMemorySize()); //2892271616
            System.out.println(unixOs.getProcessCpuLoad()); //0.0
            System.out.println(unixOs.getTotalSwapSpaceSize()); //8589934592
            System.out.println(unixOs.getTotalPhysicalMemorySize()); //17179869184
            System.out.println(unixOs.getSystemCpuLoad()); //0.0
        }
    }
上一篇下一篇

猜你喜欢

热点阅读