...
|
...
|
@@ -22,16 +22,13 @@ import java.util.*; |
|
|
*/
|
|
|
@Component
|
|
|
public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAccessMapper {
|
|
|
Logger log = LoggerFactory.getLogger(ServiceAccessMapperImpl.class);
|
|
|
|
|
|
|
|
|
//根据context获取总响应次数和平均耗时
|
|
|
@Override
|
|
|
public Map<String,NewJavaApiInfoRep> getBaseDataByContext(String context,String startDateStr,String endDateStr) {
|
|
|
public Map<String,NewJavaApiInfoRep> getBaseDataByContext(NewJavaApiInfoReq req) {
|
|
|
|
|
|
Map<String,NewJavaApiInfoRep> map = new HashMap<>();
|
|
|
String sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' and time > '%s' and time < '%s' group by hostAddress",context,startDateStr,endDateStr);
|
|
|
// String sql = "select count(cost),mean(cost) from service_access group by hostAddress";
|
|
|
String sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' and time > '%s' and time < '%s' group by hostAddress",req.getServiceName(),req.getStartTime(),req.getEndTime());
|
|
|
|
|
|
map.putAll(getDataByContext(InfluxDBContants.AWS,sql));
|
|
|
map.putAll(getDataByContext(InfluxDBContants.Q_CLOUD,sql));
|
...
|
...
|
@@ -61,10 +58,9 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc |
|
|
|
|
|
|
|
|
@Override
|
|
|
public Map<String,List<String>> getTimeoutInfo(String context, String startDateStr, String endDateStr) {
|
|
|
public Map<String,List<String>> getTimeoutInfo(NewJavaApiInfoReq req) {
|
|
|
Map<String,List<String>> map = new HashMap();
|
|
|
String sql = String.format("select ip,stack from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s'",context,startDateStr,endDateStr);
|
|
|
// String sql = "select ip,stack from service_access where context='gateway' and cost > 200";
|
|
|
String sql = String.format("select ip,stack from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s'",req.getServiceName(),req.getStartTime(),req.getEndTime());
|
|
|
map.putAll(getTimeoutInfo(InfluxDBContants.AWS,sql));
|
|
|
map.putAll(getTimeoutInfo(InfluxDBContants.Q_CLOUD,sql));
|
|
|
return map;
|
...
|
...
|
@@ -103,7 +99,6 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc |
|
|
public Map<String,List> getGraphInfo(String context){
|
|
|
Map<String,List> map = new HashMap();
|
|
|
String sql = String.format("SELECT mean(cost) FROM service_access WHERE time > now() - 10m and context = '%s' GROUP BY hostAddress,time(1m) fill(null)",context);
|
|
|
// String sql = "select mean(cost) from service_access where time > '2016-10-20 02:25:00' and time < '2016-10-20 02:51:00' and context = 'gateway' GROUP BY hostAddress,time(1m) fill(null)";
|
|
|
map.putAll(getGraphInfo(InfluxDBContants.AWS,sql));
|
|
|
map.putAll(getGraphInfo(InfluxDBContants.Q_CLOUD,sql));
|
|
|
return map;
|
...
|
...
|
@@ -167,9 +162,9 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc |
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotBlank(req.getIp())){
|
|
|
sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' and hostAddress = '%s' group by event",req.getServiceName(),req.getIp());
|
|
|
sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' and hostAddress = '%s' and time > '%s' and time < '%s' group by event",req.getServiceName(),req.getIp(),req.getStartTime(),req.getEndTime());
|
|
|
}else{
|
|
|
sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' group by event",req.getServiceName());
|
|
|
sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' and time > '%s' and time < '%s' group by event",req.getServiceName(),req.getStartTime(),req.getEndTime());
|
|
|
}
|
|
|
|
|
|
QueryResult queryResult = query(source, sql, InfluxDBContants.YOHO_EVENT);
|
...
|
...
|
@@ -203,9 +198,9 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc |
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotBlank(req.getIp())){
|
|
|
sql = String.format("select event,stack from service_access where context='%s' and cost > 200 and ip = '%s'",req.getServiceName(),req.getIp());
|
|
|
sql = String.format("select event,stack from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s' and ip = '%s' ",req.getServiceName(),req.getStartTime(),req.getEndTime(),req.getIp());
|
|
|
}else{
|
|
|
sql = String.format("select event,stack from service_access where context='%s' and cost > 200 ",req.getServiceName());
|
|
|
sql = String.format("select event,stack from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s'",req.getServiceName(),req.getStartTime(),req.getEndTime());
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -236,4 +231,75 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc |
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public Map<String,NewJavaApiInfoRep> getDataByContextAndApiName(NewJavaApiInfoReq req) {
|
|
|
|
|
|
Map<String,NewJavaApiInfoRep> map = new HashMap<>();
|
|
|
String sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' and event = '%s' and time > '%s' and time < '%s' group by hostAddress",req.getServiceName(),req.getApiName(),req.getStartTime(),req.getEndTime());
|
|
|
|
|
|
map.putAll(getDataByContext(InfluxDBContants.AWS,sql));
|
|
|
map.putAll(getDataByContext(InfluxDBContants.Q_CLOUD,sql));
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
private Map<String,NewJavaApiInfoRep> getDataByContextAndApiName(String source,String sql) {
|
|
|
Map<String,NewJavaApiInfoRep> map = new HashMap<>();
|
|
|
QueryResult queryResult = query(source, sql, InfluxDBContants.YOHO_EVENT);
|
|
|
QueryResult.Result rel = queryResult.getResults().get(0);
|
|
|
List<QueryResult.Series> listSeries = rel.getSeries();
|
|
|
if(listSeries == null)
|
|
|
return map;
|
|
|
for(QueryResult.Series series : listSeries){
|
|
|
String hostAddress = series.getTags().get("hostAddress");
|
|
|
Double count = (Double)series.getValues().get(0).get(1);
|
|
|
Double mean = (Double)series.getValues().get(0).get(2);
|
|
|
NewJavaApiInfoRep newJavaApiInfoRep = new NewJavaApiInfoRep();
|
|
|
newJavaApiInfoRep.setTotalCount(count.intValue());
|
|
|
newJavaApiInfoRep.setAvgCost(mean.intValue());
|
|
|
map.put(hostAddress,newJavaApiInfoRep);
|
|
|
}
|
|
|
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public Map<String,List<String>> getTimeoutInfoByContextAndApiName(NewJavaApiInfoReq req) {
|
|
|
Map<String,List<String>> map = new HashMap();
|
|
|
String sql = String.format("select ip,stack from service_access where context='%s' and event = '%s' and cost > 200 and time > '%s' and time < '%s'",req.getServiceName(),req.getApiName(),req.getStartTime(),req.getEndTime());
|
|
|
map.putAll(getTimeoutInfoByContextAndApiName(InfluxDBContants.AWS,sql));
|
|
|
map.putAll(getTimeoutInfoByContextAndApiName(InfluxDBContants.Q_CLOUD,sql));
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
private Map<String,List<String>> getTimeoutInfoByContextAndApiName(String source,String sql) {
|
|
|
Map<String,List<String>> map = new HashMap();
|
|
|
QueryResult queryResult = query(source, sql, InfluxDBContants.YOHO_EVENT);
|
|
|
QueryResult.Result rel = queryResult.getResults().get(0);
|
|
|
List<QueryResult.Series> listSeries = rel.getSeries();
|
|
|
if(listSeries == null)
|
|
|
return map;
|
|
|
QueryResult.Series series = listSeries.get(0);
|
|
|
List<List<Object>> values = series.getValues();
|
|
|
|
|
|
for (List<Object> objects : values){
|
|
|
if(objects.get(1) == null || objects.get(2) == null)
|
|
|
continue;
|
|
|
String ip = (String)objects.get(1);
|
|
|
String stack = (String)objects.get(2);
|
|
|
List<String> stackList = map.get(ip);
|
|
|
if(stackList == null){
|
|
|
stackList = new ArrayList<>();
|
|
|
stackList.add(stack);
|
|
|
map.put(ip,stackList);
|
|
|
}else{
|
|
|
stackList.add(stack);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|