当前位置: 首页>>代码示例>>Java>>正文


Java OperatingSystemMXBean.getSystemCpuLoad方法代码示例

本文整理汇总了Java中com.sun.management.OperatingSystemMXBean.getSystemCpuLoad方法的典型用法代码示例。如果您正苦于以下问题:Java OperatingSystemMXBean.getSystemCpuLoad方法的具体用法?Java OperatingSystemMXBean.getSystemCpuLoad怎么用?Java OperatingSystemMXBean.getSystemCpuLoad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.management.OperatingSystemMXBean的用法示例。


在下文中一共展示了OperatingSystemMXBean.getSystemCpuLoad方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
    OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean)
        ManagementFactory.getOperatingSystemMXBean();
    double load;
    for(int i=0; i<10; i++) {
        load = mbean.getSystemCpuLoad();
        if((load<0.0 || load>1.0) && load != -1.0) {
            throw new RuntimeException("getSystemCpuLoad() returns " + load
                   +  " which is not in the [0.0,1.0] interval");
        }
        try {
            Thread.sleep(200);
        } catch(InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:GetSystemCpuLoad.java

示例2: refresh

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
public void refresh() {
    OperatingSystemMXBean bean= (OperatingSystemMXBean ) ManagementFactory.getOperatingSystemMXBean();
    maxFileDescriptorCount = invoke(bean,"getMaxFileDescriptorCount");
    openFileDescriptorCount = invoke(bean, "getOpenFileDescriptorCount");
    PhysicalMemoryAvaliable = bean.getFreePhysicalMemorySize();
    PhysicalMemoryTotal = bean.getTotalPhysicalMemorySize();
    systemCpuLoad = (float) bean.getSystemCpuLoad();
    processCpuTime = bean.getProcessCpuTime();
    processCpuLoad = bean.getProcessCpuLoad();

    File[] roots = File.listRoots();
    long diskAvaliable=0,diskTotal=0;
    for(File file:roots){
        diskAvaliable += file.getFreeSpace();
        diskTotal += file.getTotalSpace();
    }
    DiskAvaliable = diskAvaliable;
    DiskTotal = diskTotal;
    if(isLinux()) {
        try {
            availableMem =(LinuxInfoUtil.getAvailableMemKB()*1024l);
            cpuLoadAverages = LinuxInfoUtil.getCpuLoadAverage();
        } catch (Throwable e) {
            logger.warn("get linux info failed!");
        }
    }

}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:30,代码来源:HostInfo.java

示例3: getSystemCpuLoadGauge

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
protected Gauge<Double> getSystemCpuLoadGauge(final OperatingSystemMXBean operatingSystemMXBean) {
    return new Gauge<Double>() {
        @Override
        public Double getValue() {
            return operatingSystemMXBean.getSystemCpuLoad();
        }
    };
}
 
开发者ID:masonmei,项目名称:apm-agent,代码行数:10,代码来源:EnhancedCpuLoadMetricSet.java

示例4: PerformanceStatus

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
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();
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:48,代码来源:PerformanceStatus.java

示例5: getSystemCpuLoad

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public static double getSystemCpuLoad() {
    OperatingSystemMXBean bean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
    return bean.getSystemCpuLoad();
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:5,代码来源:UberUtil.java

示例6: read

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Scheduled(fixedDelay = 30000)
public void read() {
    OperatingSystemMXBean mxBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
    double cpu = mxBean.getSystemCpuLoad() * 100;
    metricDataService.create((int) cpu, 2L);
}
 
开发者ID:matheusmessora,项目名称:nursery,代码行数:7,代码来源:CPUMonitor.java


注:本文中的com.sun.management.OperatingSystemMXBean.getSystemCpuLoad方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。