...
|
...
|
@@ -58,8 +58,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
.addField("mobj_ip", statics.getString("mobj_ip"))
|
|
|
.addField("mobj_id", statics.getIntValue("mobj_id"))
|
|
|
.addField("mobj_port", statics.getString("mobj_port"))
|
|
|
.addField("start", statics.getLongValue("start"))
|
|
|
.addField("end", statics.getLongValue("end"))
|
|
|
.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);
|
|
|
|
...
|
...
|
@@ -101,8 +101,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
QueryResult.Series series = rel.getSeries().get(0);
|
|
|
|
|
|
Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
|
|
|
long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end")));
|
|
|
long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start_time")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end_time")));
|
|
|
long costTime = (endTime - startTime);
|
|
|
|
|
|
String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception"));
|
...
|
...
|
@@ -119,25 +119,76 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
javaApiStaticsModel.setStatus(1);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.warn("select latest java api info failed ", e);
|
|
|
}
|
|
|
return javaApiStaticsModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 批量查询
|
|
|
*
|
|
|
* @param influxDBName
|
|
|
* @param paramList
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) {
|
|
|
|
|
|
//TODO 后期改批量查询
|
|
|
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(" and api_id=" + api_id);
|
|
|
sb.append(" and mobj_id=" + mobj_id);
|
|
|
sb.append(" order by time desc limit 1;");
|
|
|
}
|
|
|
Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM);
|
|
|
|
|
|
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<>();
|
|
|
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
|
|
|
for (JavaApiStatusReq param : paramList) {
|
|
|
JavaApiStaticsModel model = selectlatestJavaApiStatics(influxDBName, param);
|
|
|
javaApiStaticsModels.add(model);
|
|
|
for (QueryResult.Result queryResult : result.getResults()) {
|
|
|
if (queryResult.getSeries() == null)
|
|
|
continue;
|
|
|
try {
|
|
|
QueryResult.Series series = queryResult.getSeries().get(0);
|
|
|
|
|
|
Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
|
|
|
long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start_time")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end_time")));
|
|
|
long costTime = (endTime - startTime);
|
|
|
|
|
|
int api_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue();
|
|
|
int mobj_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("mobj_id"))).intValue();
|
|
|
|
|
|
String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception"));
|
|
|
|
|
|
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
|
|
|
javaApiStaticsModel.setServiceId(api_id);
|
|
|
javaApiStaticsModel.setMObjectId(mobj_id);
|
|
|
javaApiStaticsModel.setStatus(0);
|
|
|
|
|
|
javaApiStaticsModel.setStartTime(DateFormatUtil.parseLongToTimeStr(startTime));
|
|
|
javaApiStaticsModel.setEndTime(DateFormatUtil.parseLongToTimeStr(endTime));
|
|
|
|
|
|
javaApiStaticsModel.setCostTime((int) costTime);
|
|
|
|
|
|
if (is_exception == true) {
|
|
|
javaApiStaticsModel.setStatus(0);
|
|
|
javaApiStaticsModel.setException(exception);
|
|
|
} else
|
|
|
javaApiStaticsModel.setStatus(1);
|
|
|
|
|
|
javaApiStaticsModels.add(javaApiStaticsModel);
|
|
|
} catch (Exception e) {
|
|
|
log.warn("batch select latest java api info failed ", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return javaApiStaticsModels;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -189,8 +240,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
for (int i = 0; i < size; i++) {
|
|
|
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
|
|
|
Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception"));
|
|
|
long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end")));
|
|
|
long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start_time")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end_time")));
|
|
|
long costTime = (endTime - startTime);
|
|
|
|
|
|
|
...
|
...
|
|