Authored by wangning

update

... ... @@ -13,6 +13,8 @@ import java.util.Map;
public interface ServiceAccessMapper {
Map<String,NewJavaApiInfoRep> getBaseDataByContext(NewJavaApiInfoReq req);
Map<String,Integer> getTimeoutCount(NewJavaApiInfoReq req);
Map<String,List<String>> getTimeoutInfo(NewJavaApiInfoReq req);
Map<String,List> getJavaApiGraphByServiceType(String context);
... ... @@ -21,6 +23,8 @@ public interface ServiceAccessMapper {
List<NewJavaApiDetailInfoRep> getDataByContextAndIP(NewJavaApiInfoReq req);
Map<String,Integer> getTimeoutCountByContextAndIp(NewJavaApiInfoReq req);
Map<String,List<String>> getTimeoutInfoByContextAndIp(NewJavaApiInfoReq req);
Map<String,NewJavaApiInfoRep> getDataByContextAndApiName(NewJavaApiInfoReq req);
... ...
... ... @@ -9,12 +9,16 @@ import java.util.Map;
* Created by yoho on 2016/10/20.
*/
public interface ServiceServerExceptionMapper {
Map<String,Integer> getErrorCount(NewJavaApiInfoReq req);
Map<String,List<String>> getErrorDataByContext(NewJavaApiInfoReq req);
Map<String,List> getJavaApiGraphByServiceType(String context);
Map<String,List> getServiceNameJavaApiGraph(String source);
Map<String,Integer> getErrorCountByContextAndIp(NewJavaApiInfoReq req);
Map<String,List<String>> getErrorDataByContextAndIp(NewJavaApiInfoReq req);
//根据context获取错误信息列表
... ...
... ... @@ -62,7 +62,36 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
return map;
}
@Override
public Map<String,Integer> getTimeoutCount(NewJavaApiInfoReq req) {
Map<String,Integer> map = new HashMap();
String sql = "";
if(req.getServiceType() == -1){
sql = String.format("select count(cost) from service_access where %s and cost > 200 and time > '%s' and time < '%s' group by hostAddress",contextFilter,req.getStartTime(),req.getEndTime());
}else{
sql = String.format("select count(cost) from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s' group by hostAddress",req.getServiceName(),req.getStartTime(),req.getEndTime());
}
map.putAll(getTimeoutCount(InfluxDBContants.AWS,sql));
map.putAll(getTimeoutCount(InfluxDBContants.Q_CLOUD,sql));
return map;
}
private Map<String,Integer> getTimeoutCount(String source,String sql) {
Map<String,Integer> 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);
map.put(hostAddress,count.intValue());
}
return map;
}
@Override
public Map<String,List<String>> getTimeoutInfo(NewJavaApiInfoReq req) {
... ... @@ -251,6 +280,35 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
@Override
public Map<String,Integer> getTimeoutCountByContextAndIp(NewJavaApiInfoReq req) {
String source = "";
String sql = "";
if (req.getCloudType() == 2) {
source = InfluxDBContants.Q_CLOUD;
} else {
source = InfluxDBContants.AWS;
}
if (req.getServiceType() == -1) {
if (StringUtils.isNotBlank(req.getIp())) {
sql = String.format("select count(cost) from service_access where %s and cost > 200 and time > '%s' and time < '%s' and ip = '%s' group by event", contextFilter, req.getStartTime(), req.getEndTime(), req.getIp());
} else {
sql = String.format("select count(cost) from service_access where %s and cost > 200 and time > '%s' and time < '%s' group by event", contextFilter, req.getStartTime(), req.getEndTime());
}
} else {
if (StringUtils.isNotBlank(req.getIp())) {
sql = String.format("select count(cost) from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s' and ip = '%s' group by event", req.getServiceName(), req.getStartTime(), req.getEndTime(), req.getIp());
} else {
sql = String.format("select count(cost) from service_access where context='%s' and cost > 200 and time > '%s' and time < '%s' group by event", req.getServiceName(), req.getStartTime(), req.getEndTime());
}
}
return getTimeoutCount(source,sql);
}
@Override
public Map<String,List<String>> getTimeoutInfoByContextAndIp(NewJavaApiInfoReq req) {
String source = "";
String sql = "";
... ...
... ... @@ -21,6 +21,42 @@ public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements S
private String contextFilter = "(context = 'gateway' or context = 'order' or context = 'promotion' or context = 'product' or context = 'message' or context = 'sns' or context = 'users' or context = 'resources' or context = 'brower')";
@Override
public Map<String,Integer> getErrorCount(NewJavaApiInfoReq req) {
Map<String,Integer> map = new HashMap();
String sql = "";
if(req.getServiceType() == -1){
sql = String.format("select count(cost) from service_server_exception where %s and time > '%s' and time < '%s' group by hostAddress",contextFilter,req.getStartTime(),req.getEndTime());
}else{
sql = String.format("select count(cost) from service_server_exception where context='%s' and time > '%s' and time < '%s' group by hostAddress",req.getServiceName(),req.getStartTime(),req.getEndTime());
}
map.putAll(getErrorCount(InfluxDBContants.AWS,sql));
map.putAll(getErrorCount(InfluxDBContants.Q_CLOUD,sql));
return map;
}
private Map<String,Integer> getErrorCount(String source,String sql) {
Map<String,Integer> map = new HashMap<>();
QueryResult queryResult = query(source, sql, InfluxDBContants.YOMO_MONITOR);
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);
map.put(hostAddress,count.intValue());
}
return map;
}
//根据context获取错误信息列表
@Override
public Map<String,List<String>> getErrorDataByContext(NewJavaApiInfoReq req) {
... ... @@ -162,6 +198,33 @@ public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements S
return resultMap;
}
@Override
public Map<String,Integer> getErrorCountByContextAndIp(NewJavaApiInfoReq req) {
Map<String,List<String>> map = new HashMap();
String source = "";
String sql = "";
if(req.getCloudType()==2){
source = InfluxDBContants.Q_CLOUD;
}else{
source = InfluxDBContants.AWS;
}
if(req.getServiceType() == -1){
if(StringUtils.isNotBlank(req.getIp())){
sql = String.format("select count(cost) from service_server_exception where %s and time > '%s' and time < '%s' and hostAddress = '%s' group by event",contextFilter,req.getStartTime(),req.getEndTime(),req.getIp());
}else{
sql = String.format("select count(cost) from service_server_exception where %s and time > '%s' and time < '%s' group by event",contextFilter,req.getStartTime(),req.getEndTime());
}
}else{
if(StringUtils.isNotBlank(req.getIp())){
sql = String.format("select count(cost) from service_server_exception where context='%s' and time > '%s' and time < '%s' and hostAddress = '%s' group by event",req.getServiceName(),req.getStartTime(),req.getEndTime(),req.getIp());
}else{
sql = String.format("select count(cost) from service_server_exception where context='%s' and time > '%s' and time < '%s' group by event",req.getServiceName(),req.getStartTime(),req.getEndTime());
}
}
return getErrorCount(source,sql);
}
@Override
public Map<String,List<String>> getErrorDataByContextAndIp(NewJavaApiInfoReq req) {
... ...
... ... @@ -131,7 +131,13 @@ public class NewJavaApiInfoCtrl {
//根据context和ip查询详细接口信息
@RequestMapping("/queryTimeoutInfoList")
@ResponseBody
public BaseResponse queryTimeoutInfoListByIp(@RequestBody NewJavaApiInfoReq req) {
return null;
}
... ...
... ... @@ -53,10 +53,11 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
//获取总请求次数和平均耗时
Map<String,NewJavaApiInfoRep> infoMap = serviceAccessMapper.getBaseDataByContext(req);
//获取超时数据
Map<String,List<String>> timeoutInfoMap = serviceAccessMapper.getTimeoutInfo(req);
//获取超时数量
// Map<String,List<String>> timeoutInfoMap = serviceAccessMapper.getTimeoutInfo(req);
Map<String,Integer> timeoutCountMap = serviceAccessMapper.getTimeoutCount(req);
//获取异常数据
Map<String,List<String>> errorInfoMap = serviceServerExceptionMapper.getErrorDataByContext(req);
Map<String,Integer> errorInfoCountMap = serviceServerExceptionMapper.getErrorCount(req);
//获取cpu、内存、带宽使用情况
Map vmInfoMap = vmInfoMapper.getVMInfo();
... ... @@ -73,9 +74,8 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
resp.setTotalCount(infoMap.get(ip) == null ? 0 : infoMap.get(ip).getTotalCount());
resp.setAvgCost(infoMap.get(ip) == null ? 0 : infoMap.get(ip).getAvgCost());
resp.setErrorCount(errorInfoMap.get(ip) == null ? 0 : errorInfoMap.get(ip).size());
resp.setErrorInfo(errorInfoMap.get(ip));
resp.setTimeoutInfo(timeoutInfoMap.get(ip));
resp.setErrorCount(errorInfoCountMap.get(ip) == null ? 0 : errorInfoCountMap.get(ip));
resp.setTimeoutCount(timeoutCountMap.get(ip));
if(req.getServiceType() == -1){
resp.setServiceNames(mObjectInfo.getMoName());
}
... ... @@ -254,20 +254,20 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
List<NewJavaApiDetailInfoRep> returnList = new ArrayList<>();
//获取总请求次数和平均耗时
List<NewJavaApiDetailInfoRep> dataList = serviceAccessMapper.getDataByContextAndIP(req);
//获取超时数据
Map<String,List<String>> timeoutInfoMap = serviceAccessMapper.getTimeoutInfoByContextAndIp(req);
//获取异常数据
Map<String,List<String>> exceptionMap = serviceServerExceptionMapper.getErrorDataByContextAndIp(req);
//获取超时总数
Map<String,Integer> timeoutCountMap = serviceAccessMapper.getTimeoutCountByContextAndIp(req);
//获取异常总数
Map<String,Integer> exceptionMap = serviceServerExceptionMapper.getErrorCountByContextAndIp(req);
for(NewJavaApiDetailInfoRep rep :dataList){
NewJavaApiDetailInfoRep returnRep = new NewJavaApiDetailInfoRep();
String apiName = rep.getApiName();
returnRep.setApiName(apiName);
returnRep.setServiceName(rep.getServiceName());
returnRep.setErrorInfo(exceptionMap.get(apiName));
returnRep.setErrorCount(exceptionMap.get(apiName));
returnRep.setTotalCount(rep.getTotalCount());
returnRep.setAvgCost(rep.getAvgCost());
returnRep.setErrorCount(exceptionMap.get(apiName) == null ? 0 : exceptionMap.get(apiName).size());
returnRep.setTimeoutInfo(timeoutInfoMap.get(apiName));
returnRep.setErrorCount(exceptionMap.get(apiName));
returnRep.setTimeoutCount(timeoutCountMap.get(apiName));
returnList.add(returnRep);
}
... ... @@ -319,4 +319,9 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
return returnList;
}
public void queryTimeoutInfoListByIp(NewJavaApiInfoReq req){
}
}
... ...
... ... @@ -8,8 +8,9 @@ import java.util.List;
public class NewJavaApiDetailInfoRep {
private Integer totalCount = 0;
private Integer errorCount = 0;
private List<String> errorInfo;
private List<String> timeoutInfo;
// private List<String> errorInfo;
// private List<String> timeoutInfo;
private Integer timeoutCount = 0;
private Integer avgCost = 0;
private String apiName;
... ... @@ -32,21 +33,21 @@ public class NewJavaApiDetailInfoRep {
this.errorCount = errorCount;
}
public List<String> getErrorInfo() {
return errorInfo;
}
// public List<String> getErrorInfo() {
// return errorInfo;
// }
public void setErrorInfo(List<String> errorInfo) {
this.errorInfo = errorInfo;
}
// public void setErrorInfo(List<String> errorInfo) {
// this.errorInfo = errorInfo;
// }
public List<String> getTimeoutInfo() {
return timeoutInfo;
}
// public List<String> getTimeoutInfo() {
// return timeoutInfo;
// }
public void setTimeoutInfo(List<String> timeoutInfo) {
this.timeoutInfo = timeoutInfo;
}
// public void setTimeoutInfo(List<String> timeoutInfo) {
// this.timeoutInfo = timeoutInfo;
// }
public Integer getAvgCost() {
return avgCost;
... ... @@ -71,4 +72,12 @@ public class NewJavaApiDetailInfoRep {
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public Integer getTimeoutCount() {
return timeoutCount;
}
public void setTimeoutCount(Integer timeoutCount) {
this.timeoutCount = timeoutCount;
}
}
... ...
... ... @@ -12,6 +12,7 @@ public class NewJavaApiInfoRep {
private Integer errorCount = 0;
private List<String> errorInfo;
private List<String> timeoutInfo;
private Integer timeoutCount = 0;
private Integer avgCost = 0;
private String cpuRate = "";
private String memoryRate = "";
... ... @@ -107,4 +108,12 @@ public class NewJavaApiInfoRep {
public void setServiceNames(String serviceNames) {
this.serviceNames = serviceNames;
}
public Integer getTimeoutCount() {
return timeoutCount;
}
public void setTimeoutCount(Integer timeoutCount) {
this.timeoutCount = timeoutCount;
}
}
... ...