Authored by FengRuwei

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

@@ -58,8 +58,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -58,8 +58,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
58 .addField("mobj_ip", statics.getString("mobj_ip")) 58 .addField("mobj_ip", statics.getString("mobj_ip"))
59 .addField("mobj_id", statics.getIntValue("mobj_id")) 59 .addField("mobj_id", statics.getIntValue("mobj_id"))
60 .addField("mobj_port", statics.getString("mobj_port")) 60 .addField("mobj_port", statics.getString("mobj_port"))
61 - .addField("start", statics.getLongValue("start"))  
62 - .addField("end", statics.getLongValue("end")) 61 + .addField("start_time", statics.getLongValue("start"))
  62 + .addField("end_time", statics.getLongValue("end"))
63 .addField("is_exception", statics.getBooleanValue("is_exception")) 63 .addField("is_exception", statics.getBooleanValue("is_exception"))
64 .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS); 64 .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS);
65 65
@@ -101,8 +101,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -101,8 +101,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
101 QueryResult.Series series = rel.getSeries().get(0); 101 QueryResult.Series series = rel.getSeries().get(0);
102 102
103 Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception")); 103 Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
104 - long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start")));  
105 - long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end"))); 104 + long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start_time")));
  105 + long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end_time")));
106 long costTime = (endTime - startTime); 106 long costTime = (endTime - startTime);
107 107
108 String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception")); 108 String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception"));
@@ -126,28 +126,26 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -126,28 +126,26 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
126 } 126 }
127 127
128 128
  129 + /**
  130 + * 批量查询
  131 + *
  132 + * @param influxDBName
  133 + * @param paramList
  134 + * @return
  135 + */
129 @Override 136 @Override
130 public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) { 137 public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) {
131 138
132 - //TODO 后期改批量查询  
133 -  
134 List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>(); 139 List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>();
135 -  
136 -  
137 StringBuilder sb = new StringBuilder(); 140 StringBuilder sb = new StringBuilder();
138 -  
139 for (JavaApiStatusReq param : paramList) { 141 for (JavaApiStatusReq param : paramList) {
140 -  
141 int api_id = param.getServiceId(); 142 int api_id = param.getServiceId();
142 int mobj_id = param.getMObjectId(); 143 int mobj_id = param.getMObjectId();
143 - sb.append("select * from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 1h "); 144 + sb.append("select api_id,mobj_id,start_time,end_time,is_exception,exception from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 1h ");
144 sb.append(" and api_id=" + api_id); 145 sb.append(" and api_id=" + api_id);
145 sb.append(" and mobj_id=" + mobj_id); 146 sb.append(" and mobj_id=" + mobj_id);
146 sb.append(" order by time desc limit 1;"); 147 sb.append(" order by time desc limit 1;");
147 -  
148 -  
149 } 148 }
150 -  
151 Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM); 149 Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM);
152 150
153 QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query); 151 QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
@@ -159,8 +157,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -159,8 +157,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
159 QueryResult.Series series = queryResult.getSeries().get(0); 157 QueryResult.Series series = queryResult.getSeries().get(0);
160 158
161 Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception")); 159 Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
162 - long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start")));  
163 - long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end"))); 160 + long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start_time")));
  161 + long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end_time")));
164 long costTime = (endTime - startTime); 162 long costTime = (endTime - startTime);
165 163
166 int api_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue(); 164 int api_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue();
@@ -242,8 +240,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -242,8 +240,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
242 for (int i = 0; i < size; i++) { 240 for (int i = 0; i < size; i++) {
243 JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel(); 241 JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
244 Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception")); 242 Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception"));
245 - long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start")));  
246 - long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end"))); 243 + long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start_time")));
  244 + long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end_time")));
247 long costTime = (endTime - startTime); 245 long costTime = (endTime - startTime);
248 246
249 247
@@ -36,7 +36,7 @@ public class RedisMapper extends InfluxDBQuery implements IRedisMapper { @@ -36,7 +36,7 @@ public class RedisMapper extends InfluxDBQuery implements IRedisMapper {
36 .addField("role", redis.getRole()) 36 .addField("role", redis.getRole())
37 .addField("connected_clients", redis.getConnected_clients()) 37 .addField("connected_clients", redis.getConnected_clients())
38 .addField("is_slave", redis.getIs_slave()) 38 .addField("is_slave", redis.getIs_slave())
39 - .addField("used_memory_peak_human", redis.getUsed_memory_peak_human()) 39 +// .addField("used_memory_peak_human", redis.getUsed_memory_peak_human())
40 .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS) 40 .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
41 .build(); 41 .build();
42 inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB() 42 inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
1 package com.monitor; 1 package com.monitor;
2 2
  3 +import com.alibaba.fastjson.JSON;
3 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; 4 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
4 import com.monitor.javaserver.common.JavaApiStatics; 5 import com.monitor.javaserver.common.JavaApiStatics;
5 import com.monitor.model.domain.JavaApiStaticsModel; 6 import com.monitor.model.domain.JavaApiStaticsModel;
@@ -51,19 +52,20 @@ public class JavaApiInfluxDBTest { @@ -51,19 +52,20 @@ public class JavaApiInfluxDBTest {
51 public void testBatchQuery() { 52 public void testBatchQuery() {
52 53
53 List<JavaApiStatusReq> listParam = new ArrayList<>(); 54 List<JavaApiStatusReq> listParam = new ArrayList<>();
54 - JavaApiStatusReq param1 = new JavaApiStatusReq();  
55 - param1.setServiceId(21);  
56 - param1.setServiceId(43);  
57 - listParam.add(param1);  
58 - JavaApiStatusReq param2 = new JavaApiStatusReq();  
59 - param2.setServiceId(19);  
60 - param2.setServiceId(134); 55 + for (int i = 0; i < 30; i++) {
  56 + JavaApiStatusReq param1 = new JavaApiStatusReq();
  57 + param1.setServiceId(19);
  58 + param1.setMObjectId(24);
  59 + listParam.add(param1);
  60 + }
61 61
62 62
63 - listParam.add(param2);  
64 - 63 + long start = System.currentTimeMillis();
  64 + logger.info("############################################start...");
65 List<JavaApiStaticsModel> rel = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, listParam); 65 List<JavaApiStaticsModel> rel = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, listParam);
66 - 66 + long end = System.currentTimeMillis();
  67 + logger.info("###########################################end... cost : {}", (end - start));
  68 + logger.info("############################################rel: {}", JSON.toJSON(rel));
67 logger.info(rel.toString()); 69 logger.info(rel.toString());
68 70
69 } 71 }