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


Java OperatingSystemMXBean.getProcessCpuLoad方法代碼示例

本文整理匯總了Java中com.sun.management.OperatingSystemMXBean.getProcessCpuLoad方法的典型用法代碼示例。如果您正苦於以下問題:Java OperatingSystemMXBean.getProcessCpuLoad方法的具體用法?Java OperatingSystemMXBean.getProcessCpuLoad怎麽用?Java OperatingSystemMXBean.getProcessCpuLoad使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.management.OperatingSystemMXBean的用法示例。


在下文中一共展示了OperatingSystemMXBean.getProcessCpuLoad方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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.getProcessCpuLoad();
        if((load<0.0 || load>1.0) && load != -1.0) {
            throw new RuntimeException("getProcessCpuLoad() returns " + load
                   +   " which is not in the [0.0,1.0] interval");
        }
        try {
            Thread.sleep(200);
        } catch(InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:aducode,項目名稱:openjdk-source-code-learn,代碼行數:18,代碼來源:GetProcessCpuLoad.java

示例2: getSystemStats

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
Map<String, Object> getSystemStats() {
    Map<String, Object> stats = new HashMap<>();
    OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
    double cpuUsage = osBean.getProcessCpuLoad() < 0 ? 0 : osBean.getProcessCpuLoad() * 100.0;

    stats.put("javaVersion", System.getProperty("java.version"));
    stats.put("osName", System.getProperty("os.name"));
    stats.put("osArch", System.getProperty("os.arch"));
    stats.put("osVersion", System.getProperty("os.version"));
    stats.put("maxMemory", Runtime.getRuntime().maxMemory());
    stats.put("totalMemory", Runtime.getRuntime().totalMemory());
    stats.put("freeMemory", Runtime.getRuntime().freeMemory());
    stats.put("cores", Long.parseLong(String.valueOf(Runtime.getRuntime().availableProcessors()))); // Is this really necessary?
    stats.put("cpuUsage", Math.min(round(cpuUsage), 100.0));

    return stats;
}
 
開發者ID:MinecraftMarket,項目名稱:MinecraftMarket-Plugin,代碼行數:18,代碼來源:MCMarketStats.java

示例3: 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

示例4: getJvmCpuLoadGauge

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
@Override
protected Gauge<Double> getJvmCpuLoadGauge(final OperatingSystemMXBean operatingSystemMXBean) {
    return new Gauge<Double>() {
        @Override
        public Double getValue() {
            return operatingSystemMXBean.getProcessCpuLoad();
        }
    };
}
 
開發者ID:masonmei,項目名稱:apm-agent,代碼行數:10,代碼來源:EnhancedCpuLoadMetricSet.java

示例5: collectOperatingSystemMetrics

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
private MetricFamilySamples collectOperatingSystemMetrics() {
    OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    MetricFamilySamples.Sample cpuLoad = new MetricFamilySamples.Sample("process_cpu_load", new ArrayList<>(), new ArrayList<>(), operatingSystemMXBean.getProcessCpuLoad());
    return new MetricFamilySamples(cpuLoad.name, Type.GAUGE, "recent cpu usage for the whole system", Arrays.asList(cpuLoad));
}
 
開發者ID:fstab,項目名稱:promagent,代碼行數:6,代碼來源:JmxCollector.java

示例6: 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

示例7: getCPULoad

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
public static Object getCPULoad() {
	OperatingSystemMXBean os = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
	double l = os.getProcessCpuLoad() * 100;
	return round(l);
}
 
開發者ID:NJDaeger,項目名稱:EssentialCommands,代碼行數:6,代碼來源:Server.java

示例8: getProcessCpuLoad

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
public static double getProcessCpuLoad() {
    OperatingSystemMXBean bean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
    return bean.getProcessCpuLoad();
}
 
開發者ID:waterguo,項目名稱:antsdb,代碼行數:5,代碼來源:UberUtil.java

示例9: addCpuData

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
private void addCpuData(JsonObject responseObject) {
    OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean)
            ManagementFactory.getOperatingSystemMXBean();
    double load = mbean.getProcessCpuLoad();
    responseObject.addProperty("cpuLoad", load);
}
 
開發者ID:nbsp-team,項目名稱:kurve-server,代碼行數:7,代碼來源:ServerStatusResponseSerializer.java

示例10: getCpuLoad

import com.sun.management.OperatingSystemMXBean; //導入方法依賴的package包/類
static public double getCpuLoad() {
  OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
  // What % CPU load this current JVM is taking, from 0.0-1.0
  return osBean.getProcessCpuLoad();
}
 
開發者ID:MyRobotLab,項目名稱:myrobotlab,代碼行數:6,代碼來源:Runtime.java


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