fix: NEZ-2142 nz-talon 修改os系统信息获取方式
This commit is contained in:
@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,18 +25,14 @@ public class OSHIController extends BaseController{
|
||||
public R getProcessInfo(HttpServletRequest request){
|
||||
|
||||
List<Map> result = OSHIUtils.getProcessInfo();
|
||||
HashMap<Object, Object> data = Tool.MapUtil.newHashMap();
|
||||
data.put("lsit" ,result);
|
||||
|
||||
return R.ok(data);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@GetMapping("/oshi/netstat")
|
||||
public R getNetstatInfo(HttpServletRequest request) throws UnknownHostException {
|
||||
List<Map> result = OSHIUtils.getNetInfo();
|
||||
HashMap<Object, Object> data = Tool.MapUtil.newHashMap();
|
||||
data.put("lsit" ,result);
|
||||
|
||||
return R.ok(data);
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ public class OSHIUtils {
|
||||
|
||||
HashMap<Object, Object> os = Tool.MapUtil.newHashMap();
|
||||
NetworkParams networkParams = operatingSystem.getNetworkParams();
|
||||
os.put("versionInfo",String.valueOf(operatingSystem));
|
||||
os.put("platform",System.getProperty("os.name").toLowerCase());
|
||||
os.put("versionInfo",operatingSystem.getVersionInfo().toString());
|
||||
os.put("platform",si.getCurrentPlatform());
|
||||
os.put("family",operatingSystem.getFamily());
|
||||
os.put("manufacturer",operatingSystem.getManufacturer());
|
||||
os.put("bitness",operatingSystem.getBitness());
|
||||
@@ -148,9 +148,13 @@ public class OSHIUtils {
|
||||
procsData.put("parentProcessID",proc.getParentProcessID());
|
||||
procsData.put("startTime",proc.getStartTime());
|
||||
procsData.put("priority",proc.getPriority());
|
||||
//cpu mem 百分比计算
|
||||
procsData.put("cpuUsage",Tool.NumberUtil.div(proc.getKernelTime() + proc.getUserTime(), proc.getUpTime()) * 100);
|
||||
procsData.put("memUsage",Tool.NumberUtil.div(proc.getResidentSetSize(), memory.getTotal()) * 100);
|
||||
/**
|
||||
* For per-Process CPU ticks, there is no "idle" counter available, so the calculation ends up being (active time / up time)
|
||||
* This interpretation matches the value displayed in ps or top on Unix-based operating systems
|
||||
* If you want per-Process CPU load to match the Windows Task Manager display, you should divide OSHI's calculation by the number of logical processors
|
||||
*/
|
||||
procsData.put("cpuUsage",Tool.NumberUtil.div(proc.getKernelTime() + proc.getUserTime(), proc.getUpTime()) * 100d);
|
||||
procsData.put("memUsage",Tool.NumberUtil.div(proc.getResidentSetSize(), memory.getTotal()) * 100d);
|
||||
procsData.put("state",proc.getState().toString());
|
||||
procsData.put("openFiles",proc.getOpenFiles());
|
||||
procsData.put("threadCount",proc.getThreadCount());
|
||||
|
||||
Reference in New Issue
Block a user