CpuInfo[] cpuinfo = null;
CpuPerc[] cpuPerc = null;
Mem mem = null;
FileSystem[] fs = null;
String[] netIf = null;
Uptime uptime = null;
double[] loadavg = null;
JSONObject json = new JSONObject();
try {
// CPU utilization
cpuinfo = sigar.getCpuInfoList();
cpuPerc = sigar.getCpuPercList();
JSONArray cpuList = new JSONArray();
for (int i = 0; i < cpuinfo.length; i++) {
JSONObject cpuMap = new JSONObject();
cpuMap.putAll(cpuinfo[i].toMap());
cpuMap.put("combined", cpuPerc[i].getCombined());
cpuMap.put("user", cpuPerc[i].getUser());
cpuMap.put("sys", cpuPerc[i].getSys());
cpuMap.put("idle", cpuPerc[i].getIdle());
cpuMap.put("wait", cpuPerc[i].getWait());
cpuMap.put("nice", cpuPerc[i].getNice());
cpuMap.put("irq", cpuPerc[i].getIrq());
cpuList.add(cpuMap);
}
sigar.getCpuPerc();
json.put("cpu", cpuList);
// Uptime
uptime = sigar.getUptime();
json.put("uptime", uptime.getUptime());
// Load Average
loadavg = sigar.getLoadAverage();
JSONArray load = new JSONArray();
load.add(loadavg[0]);