...
|
...
|
@@ -397,31 +397,48 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc |
|
|
|
|
|
@Override
|
|
|
public List<Map> getAlarmData(Integer costThreshold){
|
|
|
String sql = String.format("select mean(cost) from service_access where %s and time > now() - 10s group by hostAddress,context",contextFilter);
|
|
|
String sql = String.format("select count(cost),mean(cost) from service_access where %s and time > now() - 10s group by hostAddress,context;select count(cost) from service_access where %s and time > now() - 10s and cost > %d group by hostAddress,context",contextFilter,contextFilter,costThreshold);
|
|
|
List<Map> list = new ArrayList<>();
|
|
|
list.addAll(getAlarmData(InfluxDBContants.AWS,sql,costThreshold));
|
|
|
list.addAll(getAlarmData(InfluxDBContants.Q_CLOUD,sql,costThreshold));
|
|
|
list.addAll(getAlarmData(InfluxDBContants.AWS,sql));
|
|
|
list.addAll(getAlarmData(InfluxDBContants.Q_CLOUD,sql));
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private List<Map> getAlarmData(String source,String sql,Integer costThreshold){
|
|
|
private List<Map> getAlarmData(String source,String sql){
|
|
|
|
|
|
List<Map> returnList = new ArrayList<>();
|
|
|
QueryResult queryResult = query(source, sql, InfluxDBContants.YOHO_EVENT);
|
|
|
QueryResult.Result rel = queryResult.getResults().get(0);
|
|
|
List<QueryResult.Series> listSeries = rel.getSeries();
|
|
|
if(listSeries == null)
|
|
|
QueryResult.Result rel1 = queryResult.getResults().get(0);
|
|
|
QueryResult.Result rel2 = queryResult.getResults().get(1);
|
|
|
List<QueryResult.Series> listSeries1 = rel1.getSeries();
|
|
|
List<QueryResult.Series> listSeries2 = rel2.getSeries();
|
|
|
if(listSeries1 == null || listSeries2 == null)
|
|
|
return returnList;
|
|
|
for(QueryResult.Series series : listSeries){
|
|
|
String hostAddress = series.getTags().get("hostAddress");
|
|
|
String serviceName = series.getTags().get("context");
|
|
|
Double mean = (Double)series.getValues().get(0).get(1);
|
|
|
if(mean > costThreshold){
|
|
|
Map map = new HashMap();
|
|
|
map.put("hostAddress",hostAddress);
|
|
|
map.put("serviceName",serviceName);
|
|
|
map.put("mean",mean);
|
|
|
returnList.add(map);
|
|
|
Map<String,QueryResult.Series> map1 = new HashMap();
|
|
|
for(QueryResult.Series series1 : listSeries1){
|
|
|
String hostAddress = series1.getTags().get("hostAddress");
|
|
|
String serviceName = series1.getTags().get("context");
|
|
|
map1.put(hostAddress+"_" + serviceName,series1);
|
|
|
}
|
|
|
|
|
|
|
|
|
for(QueryResult.Series series2 : listSeries2){
|
|
|
String hostAddress = series2.getTags().get("hostAddress");
|
|
|
String serviceName = series2.getTags().get("context");
|
|
|
Double count2 = (Double)series2.getValues().get(0).get(1);
|
|
|
QueryResult.Series series1 = map1.get(hostAddress+"_" + serviceName);
|
|
|
if(series1 != null){
|
|
|
Double count1 = (Double)series1.getValues().get(0).get(1);
|
|
|
Double mean = (Double)series1.getValues().get(0).get(2);
|
|
|
Double ratio = count2 / count1;
|
|
|
if(ratio >= 0.95){
|
|
|
Map map = new HashMap();
|
|
|
map.put("hostAddress",hostAddress);
|
|
|
map.put("serviceName",serviceName);
|
|
|
map.put("mean",mean);
|
|
|
map.put("ratio",ratio);
|
|
|
returnList.add(map);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return returnList;
|
...
|
...
|
|