Authored by simba

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

... ... @@ -39,29 +39,22 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
public void insertJavaApiStatics(String influxDBName, JSONObject statics) {
BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.APP_ALARM).retentionPolicy("default")
.build();
// BatchPoints batchPoints = BatchPoints
// .database(InfluxDBContants.APP_ALARM).retentionPolicy("default")
// .build();
Point.Builder pointBuilder = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI)
.tag("api_id", "api_id")
.tag("mobj_id", "mobj_id")
.tag("api_name", "api_name")
.tag("api_url", "api_url")
.tag("mobj_ip", "mobj_ip")
.tag("is_exception", "is_exception")
.addField("api_id", statics.getIntValue("api_id"))
.addField("api_name", statics.getString("api_name"))
.addField("api_type", statics.getIntValue("api_type"))
.tag("api_id", statics.getString("api_id"))
.tag("mobj_id", statics.getString("mobj_id"))
.tag("api_name", statics.getString("api_name"))
.addField("api_url", statics.getString("api_url"))
.tag("mobj_ip", statics.getString("mobj_ip"))
.tag("is_exception", statics.getString("is_exception"))
.addField("api_type", statics.getIntValue("api_type"))
.addField("mobj_name", statics.getString("mobj_name"))
.addField("mobj_ip", statics.getString("mobj_ip"))
.addField("mobj_id", statics.getIntValue("mobj_id"))
.addField("mobj_port", statics.getString("mobj_port"))
.addField("start_time", statics.getLongValue("start"))
.addField("end_time", statics.getLongValue("end"))
.addField("is_exception", statics.getBooleanValue("is_exception"))
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS);
if (statics.getBooleanValue("is_exception") == true) {
pointBuilder.addField("exception", statics.getString("exception"));
} else {
... ... @@ -69,10 +62,10 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
}
Point point = pointBuilder.build();
batchPoints.point(point);
// batchPoints.point(point);
inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
.write(batchPoints);
.write(InfluxDBContants.APP_ALARM, "default", point);
}
... ... @@ -81,14 +74,18 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
public JavaApiStaticsModel selectlatestJavaApiStatics(String influxDBName, JavaApiStatusReq param) {
int api_id = param.getServiceId();
int mobj_id = param.getMObjectId();
String sql = "select * from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 1h ";
String sql = "select * from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 10m ";
sql += " and api_id=" + api_id;
sql += " and mobj_id=" + mobj_id;
sql += " order by time desc limit 1";
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
QueryResult result = null;
try {
result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
} catch (Exception e) {
log.warn("influxdb query error ", e);
return null;
}
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
javaApiStaticsModel.setServiceId(api_id);
javaApiStaticsModel.setMObjectId(mobj_id);
... ... @@ -136,18 +133,47 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) {
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>();
// List<JavaApiStatusReq> splitReqList = new ArrayList<JavaApiStatusReq>();
// for (JavaApiStatusReq param : paramList) {
// splitReqList.add(param);
// if (splitReqList.size() >= 15) {
// javaApiStaticsModels.addAll(selectlatestJavaApiStaticsList_batch_split(influxDBName, splitReqList));
// splitReqList.clear();
// }
// }
// if (splitReqList.size() > 0) {
// javaApiStaticsModels.addAll(selectlatestJavaApiStaticsList_batch_split(influxDBName, splitReqList));
// }
// return javaApiStaticsModels;
return selectlatestJavaApiStaticsList_batch_split(influxDBName,paramList);
}
private List<JavaApiStaticsModel> selectlatestJavaApiStaticsList_batch_split(String influxDBName, List<JavaApiStatusReq> paramList) {
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>();
StringBuilder sb = new StringBuilder();
for (JavaApiStatusReq param : paramList) {
int api_id = param.getServiceId();
int mobj_id = param.getMObjectId();
sb.append("select api_id,mobj_id,start_time,end_time,is_exception,exception from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 1h ");
sb.append("select api_id,mobj_id,start_time,end_time,is_exception,exception from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 10m ");
sb.append(" and api_id=" + api_id);
sb.append(" and mobj_id=" + mobj_id);
sb.append(" order by time desc limit 1;");
}
log.info(sb.toString());
Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
QueryResult result = null;
try {
result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
} catch (Exception e) {
log.warn("influx db select error ,", e);
return javaApiStaticsModels;
}
for (QueryResult.Result queryResult : result.getResults()) {
if (queryResult.getSeries() == null)
... ... @@ -189,6 +215,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
return javaApiStaticsModels;
}
@Override
public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, JavaApiHisReq req) {
int api_id = req.getApiId();
... ... @@ -222,9 +249,14 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
log.info("sql:{}", sql);
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
QueryResult result = null;
List<JavaApiStaticsModel> list = new ArrayList<JavaApiStaticsModel>();
try {
result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
} catch (Exception e) {
log.warn("influxdb query error ", e);
return list;
}
QueryResult.Result rel = result.getResults().get(0);
... ... @@ -311,9 +343,13 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
QueryResult result = null;
try {
result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
} catch (Exception e) {
log.warn("influxdb query error ", e);
return 0;
}
return QueryResultUtil.getCount(result);
}
... ...
... ... @@ -181,7 +181,6 @@ public class JavaApiClient {
}
}
for (IJavaApiHadnler javaApiHadnler : javaApiHadnlerList) {
if (javaApiHadnler instanceof PreProcessJavaApiHandler)
continue;
... ...
... ... @@ -52,6 +52,7 @@ public class JavaAppInfoStaticsCtrl {
@RequestMapping("/query")
@ResponseBody
public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq[] req) {
log.info("get api status.");
BaseResponse rep = new BaseResponse();
try {
List<JavaApiStatusReq> list = Arrays.asList(req);
... ...
... ... @@ -3,6 +3,7 @@
influxdb.num=2
influxdb.name=test;alarm
influxdb.ip=http://192.168.102.162:8086;http://123.206.79.151:18086
#influxdb.ip=http://192.168.102.162:8086;http://192.168.99.100:32768
influxdb.user=yoho;root
influxdb.pwd=Yoho_9646;root
influxdb.connect.timeout=15;15
... ...