服务端
public void cpu() throws SigarException {
Sigar sigar = new Sigar();
CpuInfo infos[] = sigar.getCpuInfoList();
CpuPerc cpuList[] = sigar.getCpuPercList();
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
for (int i = 0, len = infos.length; i < len; i++) {// 不管是单块CPU还是多CPU都适用
CpuInfo info = infos[i];
JSONObject jso = new JSONObject();
jso.put("mhz", info.getMhz()); //CPU的总量MHz
jso.put("company", info.getVendor()); //CPU的厂商
jso.put("model", info.getModel()); //CPU型号类别
jso.put("cache_size", info.getCacheSize()); // 缓冲缓存数量
CpuPerc cpu = cpuList[i];
jso.put("freq_user", CpuPerc.format(cpu.getUser())); //CPU的用户使用率
jso.put("freq_sys", CpuPerc.format(cpu.getSys())); //CPU的系统使用率
jso.put("freq_wait", CpuPerc.format(cpu.getWait())); //CPU的当前等待率
jso.put("freq_nice", CpuPerc.format(cpu.getNice())); //CPU的当前错误率
jso.put("freq_idle", CpuPerc.format(cpu.getIdle()))