コード例 #1
0
 public static void getServerCpuInfo(Sigar sigar, ServerStatus status) {
   try {
     CpuInfo infos[] = sigar.getCpuInfoList();
     CpuPerc cpuList[] = sigar.getCpuPercList();
     double totalUse = 0L;
     for (int i = 0; i < infos.length; i++) {
       CpuPerc perc = cpuList[i];
       ServerStatus.CpuInfoVo cpuInfo = new ServerStatus.CpuInfoVo();
       cpuInfo.setId(infos[i].hashCode() + "");
       cpuInfo.setCacheSize(infos[i].getCacheSize());
       cpuInfo.setModel(infos[i].getModel());
       cpuInfo.setUsed(CpuPerc.format(perc.getCombined()));
       cpuInfo.setUsedOrigVal(perc.getCombined());
       cpuInfo.setIdle(CpuPerc.format(perc.getIdle()));
       cpuInfo.setTotalMHz(infos[i].getMhz());
       cpuInfo.setVendor(infos[i].getVendor());
       status.getCpuInfos().add(cpuInfo);
       totalUse += perc.getCombined();
     }
     String cpuu = CpuPerc.format(totalUse / status.getCpuInfos().size());
     cpuu = cpuu.substring(0, cpuu.length() - 1);
     status.setCpuUsage(cpuu);
   } catch (Exception e) {
   }
 }
コード例 #2
0
 private void output(CpuPerc cpu) {
   println("User Time....." + CpuPerc.format(cpu.getUser())); // 用户使用率
   println("Sys Time......" + CpuPerc.format(cpu.getSys())); // 系统CPU使用率
   println("Idle Time....." + CpuPerc.format(cpu.getIdle())); // 当前空闲率
   println("Wait Time....." + CpuPerc.format(cpu.getWait())); // 当前等待率
   println("Nice Time....." + CpuPerc.format(cpu.getNice()));
   println("Combined......" + CpuPerc.format(cpu.getCombined())); // 总的使用率
   println("Irq Time......" + CpuPerc.format(cpu.getIrq()));
   println("");
 }