Authored by FengRuwei

优化状态查询,加快页面上刷新速度

... ... @@ -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"));
... ... @@ -126,28 +126,26 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
}
/**
* 批量查询
*
* @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 * 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() - 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);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
... ... @@ -159,8 +157,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
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")));
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);
int api_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue();
... ... @@ -242,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);
... ...
... ... @@ -36,7 +36,7 @@ public class RedisMapper extends InfluxDBQuery implements IRedisMapper {
.addField("role", redis.getRole())
.addField("connected_clients", redis.getConnected_clients())
.addField("is_slave", redis.getIs_slave())
.addField("used_memory_peak_human", redis.getUsed_memory_peak_human())
// .addField("used_memory_peak_human", redis.getUsed_memory_peak_human())
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
... ...
package com.monitor;
import com.alibaba.fastjson.JSON;
import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
import com.monitor.javaserver.common.JavaApiStatics;
import com.monitor.model.domain.JavaApiStaticsModel;
... ... @@ -51,19 +52,20 @@ public class JavaApiInfluxDBTest {
public void testBatchQuery() {
List<JavaApiStatusReq> listParam = new ArrayList<>();
JavaApiStatusReq param1 = new JavaApiStatusReq();
param1.setServiceId(21);
param1.setServiceId(43);
listParam.add(param1);
JavaApiStatusReq param2 = new JavaApiStatusReq();
param2.setServiceId(19);
param2.setServiceId(134);
for (int i = 0; i < 30; i++) {
JavaApiStatusReq param1 = new JavaApiStatusReq();
param1.setServiceId(19);
param1.setMObjectId(24);
listParam.add(param1);
}
listParam.add(param2);
long start = System.currentTimeMillis();
logger.info("############################################start...");
List<JavaApiStaticsModel> rel = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, listParam);
long end = System.currentTimeMillis();
logger.info("###########################################end... cost : {}", (end - start));
logger.info("############################################rel: {}", JSON.toJSON(rel));
logger.info(rel.toString());
}
... ...