健康检查
This commit is contained in:
@@ -37,6 +37,8 @@ public class HealthAction extends AdminAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
jsonObject.put("node", "1");
|
||||
|
||||
JSONObject cpuObject = new JSONObject();
|
||||
jsonObject.put("cpu", cpuObject);
|
||||
|
||||
@@ -60,9 +62,9 @@ public class HealthAction extends AdminAction {
|
||||
fileObject.put("space", root.getTotalSpace());
|
||||
fileObject.put("free", root.getFreeSpace());
|
||||
fileObject.put("usable", root.getUsableSpace());
|
||||
|
||||
JSONObject out = new JSONObject();
|
||||
out.put("node1", jsonObject);
|
||||
|
||||
JSONArray out = new JSONArray();
|
||||
out.add(jsonObject);
|
||||
RestResult result = RestResult.ok(out);
|
||||
setResponseContent(result, response);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public enum ErrorCode {
|
||||
ERROR_CODE_RECALL_TIME_EXPIRED(24, "time expired"),
|
||||
ERROR_CODE_CONFERENCE_ROOM_NOT_EXIST(60, "conference room not exist"),
|
||||
|
||||
ERROR_CODE_USER_NOT_PREPARED(238, "user not prepared"),
|
||||
ERROR_CODE_API_NOT_SIGNED(239, "api not signed or sign parameter not completion"),
|
||||
ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT(240, "group exceed max member count"),
|
||||
ERROR_CODE_GROUP_MUTED(241, "group is muted"),
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HealthCheckResult extends ArrayList<HealthCheckResult.Node>
|
||||
{
|
||||
public static class Node {
|
||||
public String node;
|
||||
public CPU cpu;
|
||||
public Memory memory;
|
||||
public Disk disk;
|
||||
}
|
||||
|
||||
public static class Memory {
|
||||
public long avail;
|
||||
public long max;
|
||||
public long free;
|
||||
}
|
||||
public static class Disk {
|
||||
public long usable;
|
||||
public long free;
|
||||
public long space;
|
||||
}
|
||||
public static class CPU {
|
||||
public int cores;
|
||||
public double load;
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,8 @@ public class GeneralAdmin {
|
||||
pojo.setValue(value);
|
||||
return AdminHttpUtils.httpJsonPost(path, pojo, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<HealthCheckResult> healthCheck() throws Exception {
|
||||
return AdminHttpUtils.httpGet(APIPath.Health, HealthCheckResult.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,6 +707,14 @@ public class Main {
|
||||
System.out.println("create channel failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<HealthCheckResult> health = GeneralAdmin.healthCheck();
|
||||
if(health != null && health.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println(health.result);
|
||||
} else {
|
||||
System.out.println("health check failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
static void testChatroom() throws Exception {
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@@ -34,7 +35,54 @@ public class AdminHttpUtils {
|
||||
httpClient = HttpClients.createDefault();
|
||||
}
|
||||
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
public static <T> IMResult<T> httpGet(String path, Class<T> clazz) throws Exception {
|
||||
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret)) {
|
||||
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!!!!");
|
||||
throw new Exception("SDK没有初始化");
|
||||
}
|
||||
|
||||
if (isNullOrEmpty(path)) {
|
||||
throw new Exception("路径缺失");
|
||||
}
|
||||
HttpGet get = null;
|
||||
try {
|
||||
get = new HttpGet(adminUrl + path);
|
||||
HttpResponse response = httpClient.execute(get);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
String content = null;
|
||||
if (response.getEntity().getContentLength() > 0) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line).append(NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
}
|
||||
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: " + statusCode + " error msg:" + content);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
} else {
|
||||
return fromJsonObject(content, clazz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
} finally {
|
||||
if(get != null) {
|
||||
get.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception {
|
||||
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret)) {
|
||||
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!!!!");
|
||||
throw new Exception("SDK没有初始化");
|
||||
|
||||
Reference in New Issue
Block a user