更新健康检查内容

This commit is contained in:
heavyrain2012
2021-08-13 15:06:09 +08:00
parent d241acf980
commit 2f195440cf
@@ -36,12 +36,15 @@ public class HealthAction extends AdminAction {
public boolean action(Request request, Response response) { public boolean action(Request request, Response response) {
if (request.getNettyRequest() instanceof FullHttpRequest) { if (request.getNettyRequest() instanceof FullHttpRequest) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
JSONObject cpuObject = new JSONObject(); JSONObject cpuObject = new JSONObject();
jsonObject.put("cpu", cpuObject); jsonObject.put("cpu", cpuObject);
JSONObject memoryObject = new JSONObject(); JSONObject memoryObject = new JSONObject();
jsonObject.put("memory", memoryObject); jsonObject.put("memory", memoryObject);
JSONObject fileObject = new JSONObject();
jsonObject.put("disk", fileObject);
if (getOperatingSystemMXBean() instanceof OperatingSystemMXBean) { if (getOperatingSystemMXBean() instanceof OperatingSystemMXBean) {
double load = getOperatingSystemMXBean().getSystemLoadAverage(); double load = getOperatingSystemMXBean().getSystemLoadAverage();
@@ -53,16 +56,11 @@ public class HealthAction extends AdminAction {
memoryObject.put("max", Runtime.getRuntime().maxMemory()); memoryObject.put("max", Runtime.getRuntime().maxMemory());
memoryObject.put("avail", Runtime.getRuntime().totalMemory()); memoryObject.put("avail", Runtime.getRuntime().totalMemory());
File root = new File("/");
JSONArray jsonArray = new JSONArray(); fileObject.put("space", root.getTotalSpace());
jsonObject.put("file", jsonArray); fileObject.put("free", root.getFreeSpace());
for (File root : File.listRoots()) { fileObject.put("usable", root.getUsableSpace());
JSONObject fObj = new JSONObject();
fObj.put("path", root.getPath());
fObj.put("space", root.getTotalSpace());
fObj.put("free", root.getFreeSpace());
fObj.put("usable", root.getUsableSpace());
}
JSONObject out = new JSONObject(); JSONObject out = new JSONObject();
out.put("node1", jsonObject); out.put("node1", jsonObject);
RestResult result = RestResult.ok(out); RestResult result = RestResult.ok(out);