|
@ -1,5 +1,7 @@
|
|
|
package com.yihu.hos.common.util;
|
|
|
|
|
|
import com.yihu.hos.core.log.Logger;
|
|
|
import com.yihu.hos.core.log.LoggerFactory;
|
|
|
import org.hyperic.sigar.*;
|
|
|
|
|
|
import java.net.InetAddress;
|
|
@ -132,8 +134,8 @@ public class SigarUtil {
|
|
|
memory.put("total", getDouble((double)mem.getTotal() / 1024L / 1024L / 1024L));
|
|
|
memory.put("used", getDouble((double)mem.getUsed() / 1024L / 1024L / 1024L));
|
|
|
memory.put("free", getDouble((double)mem.getFree() / 1024L / 1024L / 1024L));
|
|
|
memory.put("freePerc", getDouble(mem.getFreePercent() / 1024L / 1024L / 1024L));
|
|
|
memory.put("usedPerc", getDouble(mem.getUsedPercent() / 1024L / 1024L / 1024L));
|
|
|
memory.put("freePerc", getDouble(mem.getFreePercent()));
|
|
|
memory.put("usedPerc", getDouble(mem.getUsedPercent()));
|
|
|
//交换区
|
|
|
memory.put("swapTotal", getDouble((double)swap.getTotal() / 1024L / 1024L / 1024L));
|
|
|
memory.put("swapUsed", getDouble((double)swap.getUsed() / 1024L / 1024L / 1024L));
|
|
@ -147,32 +149,37 @@ public class SigarUtil {
|
|
|
* @return
|
|
|
* @throws SigarException
|
|
|
*/
|
|
|
public static Map<String, Object> cpu() throws SigarException {
|
|
|
public static Map<String, Object> cpu() {
|
|
|
Map<String, Object> cpuMap = new HashMap<>();
|
|
|
CpuInfo infos[] = sigar.getCpuInfoList();
|
|
|
CpuPerc cpuPerc = sigar.getCpuPerc();
|
|
|
CpuInfo info1 = infos[0];
|
|
|
//cpu信息
|
|
|
cpuMap.put("quantity", infos.length);
|
|
|
cpuMap.put("model", info1.getModel());
|
|
|
cpuMap.put("totalCores", info1.getTotalCores());
|
|
|
cpuMap.put("totalSockets", info1.getTotalSockets());
|
|
|
cpuMap.put("Mhz", info1.getMhz());
|
|
|
//cpu使用率
|
|
|
try {
|
|
|
CpuInfo infos[] = sigar.getCpuInfoList();
|
|
|
CpuPerc cpuPerc = sigar.getCpuPerc();
|
|
|
CpuInfo info1 = infos[0];
|
|
|
//cpu信息
|
|
|
cpuMap.put("quantity", infos.length);
|
|
|
cpuMap.put("model", info1.getModel());
|
|
|
cpuMap.put("totalCores", info1.getTotalCores());
|
|
|
cpuMap.put("totalSockets", info1.getTotalSockets());
|
|
|
cpuMap.put("Mhz", info1.getMhz());
|
|
|
//cpu使用率
|
|
|
|
|
|
String totalPerc = String.format("%.2f", cpuPerc.getCombined() * 100);
|
|
|
String userPerc = String.format("%.2f", cpuPerc.getUser() * 100);
|
|
|
String sysPerc = String.format("%.2f", cpuPerc.getSys() * 100);
|
|
|
String wait = String.format("%.2f", cpuPerc.getWait() * 100);
|
|
|
String nice = String.format("%.2f", cpuPerc.getNice() * 100);
|
|
|
String freePerc = String.format("%.2f", cpuPerc.getIdle() * 100);
|
|
|
|
|
|
String totalPerc = String.format("%.2f", cpuPerc.getCombined() * 100);
|
|
|
String userPerc = String.format("%.2f", cpuPerc.getUser() * 100);
|
|
|
String sysPerc = String.format("%.2f", cpuPerc.getSys() * 100);
|
|
|
String wait = String.format("%.2f", cpuPerc.getWait() * 100);
|
|
|
String nice = String.format("%.2f", cpuPerc.getNice() * 100);
|
|
|
String freePerc = String.format("%.2f", cpuPerc.getIdle() * 100);
|
|
|
cpuMap.put("totalPerc", getDouble(cpuPerc.getCombined() * 100));
|
|
|
cpuMap.put("userPerc", getDouble(cpuPerc.getUser() * 100));
|
|
|
cpuMap.put("sysPerc", getDouble(cpuPerc.getSys() * 100));
|
|
|
cpuMap.put("wait", getDouble(cpuPerc.getWait() * 100));
|
|
|
cpuMap.put("nice", getDouble(cpuPerc.getNice() * 100));
|
|
|
cpuMap.put("freePerc", getDouble(cpuPerc.getIdle() * 100));
|
|
|
|
|
|
cpuMap.put("totalPerc", getDouble(cpuPerc.getCombined() * 100));
|
|
|
cpuMap.put("userPerc", getDouble(cpuPerc.getUser() * 100));
|
|
|
cpuMap.put("sysPerc", getDouble(cpuPerc.getSys() * 100));
|
|
|
cpuMap.put("wait", getDouble(cpuPerc.getWait() * 100));
|
|
|
cpuMap.put("nice", getDouble(cpuPerc.getNice() * 100));
|
|
|
cpuMap.put("freePerc", getDouble(cpuPerc.getIdle() * 100));
|
|
|
}catch (SigarException e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return cpuMap;
|
|
|
}
|
|
|
|