Java Code Examples for com.sun.management.OperatingSystemMXBean#getTotalSwapSpaceSize()

The following examples show how to use com.sun.management.OperatingSystemMXBean#getTotalSwapSpaceSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCpu.java    From Jpom with MIT License 5 votes vote down vote up
public static String getMemery() {
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    // 总的物理内存+虚拟内存
    long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();
    // 剩余的物理内存
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();

    Double compare = (1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100;
    return "内存已使用:" + compare.intValue() + "%";
}
 
Example 2
Source File: Mem.java    From zfile with MIT License 5 votes vote down vote up
public Mem() {
    OperatingSystemMXBean osb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    // 总的物理内存+虚拟内存
    long totalVirtualMemory = osb.getTotalSwapSpaceSize();
    // 剩余的物理内存
    long freePhysicalMemorySize = osb.getFreePhysicalMemorySize();
    this.total = totalVirtualMemory;
    this.free = freePhysicalMemorySize;
    this.used = totalVirtualMemory - freePhysicalMemorySize;
}
 
Example 3
Source File: WindowsInfoUtil.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
public static int getMemery() {
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    // 总的物理内存+虚拟内存
    long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();
    // 剩余的物理内存
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
    Double compare = (Double) (1 - freePhysicalMemorySize * 1.0
            / totalvirtualMemory) * 100;
    return compare.intValue();
}
 
Example 4
Source File: ScheduleTask.java    From Jantent with MIT License 5 votes vote down vote up
public static String getMemery() {

        OperatingSystemMXBean osmxb = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
        long totalvirtualMemory = osmxb.getTotalSwapSpaceSize(); // 剩余的物理内存
        long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
        Double compare = (Double) (1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100;
        String str = compare.intValue() + "%";
        return str;

    }
 
Example 5
Source File: GetSystemInfo.java    From csustRepo with MIT License 5 votes vote down vote up
/**
 * 获取内存使用率  
 * @return
 */
public static String getMemeryRate()  
{  
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();  
    // 总的物理内存+虚拟内存  
    long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();  
    // 剩余的物理内存  
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();  
    Double compare = (Double)(1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100;  
    String str = compare.intValue() + "%";  
    return str;  
}
 
Example 6
Source File: HostTask.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
private static HostInfo getHostInfo(MxBean mxBean) {
    OperatingSystemMXBean osBean = mxBean.getOsBean();
    ThreadMXBean threadBean = mxBean.getThreadBean();

    HostInfo hostInfo = new HostInfo();
    String osName = System.getProperty("os.name");
    int availableProcessors = Runtime.getRuntime().availableProcessors();
    String cpuLoadAverages = null;
    if (osName != null && osName.toLowerCase().contains("linux")) {
        try {
            File file = new File(LOADAVG_FILENAME);
            cpuLoadAverages = FileUtil.readFile(file);
        } catch (IOException e) {
            logger.error("get CPU Load Averages error", e);
        }
    }

    double systemLoadAverage = osBean.getSystemLoadAverage();
    // 可使用内存
    long totalMemory = Runtime.getRuntime().totalMemory() / KB;
    // 剩余内存
    long freeMemory = Runtime.getRuntime().freeMemory() / KB;
    // 最大可使用内存
    long maxMemory = Runtime.getRuntime().maxMemory() / KB;

    //总交换空间
    long totalSwapSpaceSize = osBean.getTotalSwapSpaceSize() / KB;
    //空闲交换空间
    long freeSwapSpaceSize = osBean.getFreeSwapSpaceSize() / KB;
    //总物理内存
    long totalPhysicalMemorySize = osBean.getTotalPhysicalMemorySize() / KB;
    //空闲物理内存
    long freePhysicalMemorySize = osBean.getFreePhysicalMemorySize() / KB;
    //系统CPU利用率
    double systemCpuLoad = osBean.getSystemCpuLoad();

    long totalThread = threadBean.getTotalStartedThreadCount();

    //获取磁盘信息
    getDiskInfo(hostInfo);

    hostInfo.setAvailableProcessors(availableProcessors);
    hostInfo.setSystemLoadAverage(systemLoadAverage);
    hostInfo.setCpuLoadAverages(Strings.nullToEmpty(cpuLoadAverages));
    hostInfo.setOsName(osName);
    hostInfo.setTotalMemory(totalMemory);
    hostInfo.setFreeMemory(freeMemory);
    hostInfo.setMaxMemory(maxMemory);
    hostInfo.setTotalSwapSpaceSize(totalSwapSpaceSize);
    hostInfo.setFreeSwapSpaceSize(freeSwapSpaceSize);
    hostInfo.setTotalPhysicalMemorySize(totalPhysicalMemorySize);
    hostInfo.setFreePhysicalMemorySize(freePhysicalMemorySize);
    hostInfo.setUsedMemory(totalPhysicalMemorySize - freePhysicalMemorySize);
    hostInfo.setTotalThread(totalThread);
    hostInfo.setCpuRatio(systemCpuLoad);
    return hostInfo;
}
 
Example 7
Source File: PerformanceStatus.java    From vi with Apache License 2.0 4 votes vote down vote up
public PerformanceStatus() {
    OperatingSystemMXBean bean= (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();

    MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
    heapMemoryUsage= memBean.getHeapMemoryUsage();
    nonHeapMemoryUsage = memBean.getNonHeapMemoryUsage();

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    currentThreadCount=threadBean.getThreadCount();
    daemonThreadCount= threadBean.getDaemonThreadCount();
    beanCreatedThreadCount= threadBean.getTotalStartedThreadCount();
    peakThreadCount = threadBean.getPeakThreadCount();

    ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
    loadedClassCount=classLoadingBean.getLoadedClassCount();
    totalLoadedClassCount=classLoadingBean.getTotalLoadedClassCount();
    unloadedClassCount=classLoadingBean.getUnloadedClassCount();
    committedVirtualMemorySize = (bean.getCommittedVirtualMemorySize());
    freePhysicalMemorySize =(bean.getFreePhysicalMemorySize());
    totalPhysicalMemorySize =(bean.getTotalPhysicalMemorySize());

    freeSwapSpaceSize =(bean.getFreeSwapSpaceSize());
    totalSwapSpaceSize =(bean.getTotalSwapSpaceSize());
    processCpuTime =(bean.getProcessCpuTime());
    availableProcessors =bean.getAvailableProcessors();
    processCpuLoad =bean.getProcessCpuLoad();

    systemCpuLoad =bean.getSystemCpuLoad();
    systemLoadAverage =bean.getSystemLoadAverage();
    appStartUpTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(runtimeBean.getStartTime()));
    runtime = (new Date().getTime() - runtimeBean.getStartTime())/1000;
    os = bean.getName()+" "+bean.getVersion();

    if(HostInfo.isLinux()){
        try {
            availableMemory = (LinuxInfoUtil.getAvailableMemKB()*1024l);
        } catch (Throwable ignored) {
        }
    }

    File[] roots = File.listRoots();
    for(File file:roots){
        rootFiles.add(new RootFile(file.getAbsolutePath(),file.getTotalSpace(),file.getFreeSpace()));
    }
    getGCStatus();
}
 
Example 8
Source File: VMSummary.java    From vi with Apache License 2.0 4 votes vote down vote up
public VMSummary(){
    MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
    MemoryUsage u = bean.getHeapMemoryUsage();
    heapCommitedMemory= (u.getCommitted());
    heapUsedMemory=(u.getUsed());
    heapMaxMemory=(u.getMax());

    u = bean.getNonHeapMemoryUsage();
    nonHeapCommitedMemory=(u.getCommitted());
    nonHeapUsedMemory=(u.getUsed());
    nonHeapMaxMemory=(u.getMax());

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    currentThreadCount=threadBean.getThreadCount();
    daemonThreadCount= threadBean.getDaemonThreadCount();
    totalStartedThreadCount= threadBean.getTotalStartedThreadCount();
    peakThreadCount = threadBean.getPeakThreadCount();

    ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
    loadedClassCount=classLoadingBean.getLoadedClassCount();
    totalLoadedClassCount=classLoadingBean.getTotalLoadedClassCount();
    unloadedClassCount=classLoadingBean.getUnloadedClassCount();
    getGCStatus();

    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    classPath = runtimeBean.getClassPath();
    libraryPath = runtimeBean.getLibraryPath();
    vmOptions = TextUtils.join(" ",runtimeBean.getInputArguments());
    bootClassPath = runtimeBean.getBootClassPath();
    upTime = runtimeBean.getUptime();

    vmName=runtimeBean.getVmName();
    vmVendor= runtimeBean.getVmVendor();


    OperatingSystemMXBean osBean= (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

    processCpuTime = osBean.getProcessCpuTime();

    jdkVersion=System.getProperty("java.version");
    jitCompiler=System.getProperty("java.vm.name");

    os = osBean.getName() + " "+osBean.getVersion();
    osArch = osBean.getArch();
    availableProcessors = osBean.getAvailableProcessors();

     commitedVirtualMemory = osBean.getCommittedVirtualMemorySize();
    freePhysicalMemorySize =(osBean.getFreePhysicalMemorySize());
    totalPhysicalMemorySize =(osBean.getTotalPhysicalMemorySize());

    freeSwapSpaceSize =(osBean.getFreeSwapSpaceSize());
    totalSwapSpaceSize =(osBean.getTotalSwapSpaceSize());

    List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
    gcInfos = new ArrayList<>(beans.size());
    for (GarbageCollectorMXBean b : beans) {
        GCBean gcBean = new GCBean();
        gcBean.name =b.getName();
        gcBean.gcCount = b.getCollectionCount();
        gcBean.gcTime = b.getCollectionTime();
        gcInfos.add(gcBean);
    }

}
 
Example 9
Source File: GetSystemInfo.java    From csustRepo with MIT License 4 votes vote down vote up
/**
 * 获取总共内存
 * @return
 */
public static Long getTotalMemery(){  
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();  
    // 总的物理内存+虚拟内存  
    return  osmxb.getTotalSwapSpaceSize();  
}