添加健康检查功能
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.action.Action;
|
||||
@@ -46,7 +47,11 @@ abstract public class AdminAction extends Action {
|
||||
if (!mLimitCounter.isGranted("admin")) {
|
||||
return ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
||||
}
|
||||
|
||||
|
||||
if(APIPath.Health.equals(request.getUri())) {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
String nonce = request.getHeader("nonce");
|
||||
if (StringUtil.isNullOrEmpty(nonce)) {
|
||||
nonce = request.getHeader("Nonce");
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.OutputUserBlockStatusList;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
|
||||
import static java.lang.management.ManagementFactory.getOperatingSystemMXBean;
|
||||
|
||||
@Route(APIPath.Health)
|
||||
public class HealthAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
JSONObject cpuObject = new JSONObject();
|
||||
jsonObject.put("cpu", cpuObject);
|
||||
|
||||
JSONObject memoryObject = new JSONObject();
|
||||
jsonObject.put("memory", memoryObject);
|
||||
|
||||
|
||||
if (getOperatingSystemMXBean() instanceof OperatingSystemMXBean) {
|
||||
double load = getOperatingSystemMXBean().getSystemLoadAverage();
|
||||
cpuObject.put("load", load);
|
||||
}
|
||||
cpuObject.put("cores", Runtime.getRuntime().availableProcessors());
|
||||
|
||||
memoryObject.put("free", Runtime.getRuntime().freeMemory());
|
||||
memoryObject.put("max", Runtime.getRuntime().maxMemory());
|
||||
memoryObject.put("avail", Runtime.getRuntime().totalMemory());
|
||||
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonObject.put("file", jsonArray);
|
||||
for (File root : File.listRoots()) {
|
||||
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();
|
||||
out.put("node1", jsonObject);
|
||||
RestResult result = RestResult.ok(out);
|
||||
setResponseContent(result, response);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,8 @@ public interface APIPath {
|
||||
String Get_System_Setting = "/admin/system/get_setting";
|
||||
String Put_System_Setting = "/admin/system/put_setting";
|
||||
|
||||
String Health = "/admin/health";
|
||||
|
||||
String Conference_List = "/admin/conference/list";
|
||||
String Conference_List_Participant = "/admin/conference/list_participant";
|
||||
String Conference_Create = "/admin/conference/create";
|
||||
|
||||
Reference in New Issue
Block a user