Authored by wangning

update

... ... @@ -23,6 +23,8 @@ import java.util.*;
@Component
public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAccessMapper {
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')";
//根据context获取总响应次数和平均耗时
@Override
public Map<String,NewJavaApiInfoRep> getBaseDataByContext(NewJavaApiInfoReq req) {
... ... @@ -30,7 +32,7 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
Map<String,NewJavaApiInfoRep> map = new HashMap<>();
String sql = "";
if(req.getServiceType() == -1){
sql = String.format("select count(cost),mean(cost) from service_access where time > '%s' and time < '%s' group by hostAddress",req.getStartTime(),req.getEndTime());
sql = String.format("select count(cost),mean(cost) from service_access where %s and time > '%s' and time < '%s' group by hostAddress",contextFilter,req.getStartTime(),req.getEndTime());
}else{
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());
}
... ... @@ -67,7 +69,7 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
Map<String,List<String>> map = new HashMap();
String sql = "";
if(req.getServiceType() == -1){
sql = String.format("select ip,stack from service_access where cost > 200 and time > '%s' and time < '%s'",req.getStartTime(),req.getEndTime());
sql = String.format("select ip,stack from service_access where %s and cost > 200 and time > '%s' and time < '%s'",contextFilter,req.getStartTime(),req.getEndTime());
}else{
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());
}
... ... @@ -161,7 +163,7 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
@Override
public Map<String,List> getServiceNameJavaApiGraph(String source){
String sql = "SELECT mean(cost) FROM service_access WHERE time > now() - 10m GROUP BY context,time(1m) fill(null)";
String sql = String.format("SELECT mean(cost) FROM service_access WHERE %s and time > now() - 10m GROUP BY context,time(1m) fill(null)",contextFilter);
Map<String,List> resultMap = new HashMap<>();
QueryResult queryResult = query(source, sql, InfluxDBContants.YOHO_EVENT);
... ... @@ -213,9 +215,9 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
}
if(req.getServiceType() == -1){
if(StringUtils.isNotBlank(req.getIp())){
sql = String.format("select count(cost),mean(cost) from service_access where hostAddress = '%s' and time > '%s' and time < '%s' group by event,context",req.getIp(),req.getStartTime(),req.getEndTime());
sql = String.format("select count(cost),mean(cost) from service_access where %s and hostAddress = '%s' and time > '%s' and time < '%s' group by event,context",contextFilter,req.getIp(),req.getStartTime(),req.getEndTime());
}else{
sql = String.format("select count(cost),mean(cost) from service_access where time > '%s' and time < '%s' group by event,context",req.getStartTime(),req.getEndTime());
sql = String.format("select count(cost),mean(cost) from service_access where %s and time > '%s' and time < '%s' group by event,context",contextFilter,req.getStartTime(),req.getEndTime());
}
}else{
if(StringUtils.isNotBlank(req.getIp())){
... ... @@ -259,9 +261,9 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
}
if(req.getServiceType() == -1){
if(StringUtils.isNotBlank(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());
sql = String.format("select event,stack from service_access where %s and context='%s' and cost > 200 and time > '%s' and time < '%s' and ip = '%s' ",contextFilter,req.getServiceName(),req.getStartTime(),req.getEndTime(),req.getIp());
}else{
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());
sql = String.format("select event,stack from service_access where %s and context='%s' and cost > 200 and time > '%s' and time < '%s'",contextFilter,req.getServiceName(),req.getStartTime(),req.getEndTime());
}
}else{
if(StringUtils.isNotBlank(req.getIp())){
... ...
... ... @@ -19,13 +19,15 @@ import java.util.*;
@Component
public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements ServiceServerExceptionMapper {
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')";
//根据context获取错误信息列表
@Override
public Map<String,List<String>> getErrorDataByContext(NewJavaApiInfoReq req) {
Map<String,List<String>> map = new HashMap();
String sql = "";
if(req.getServiceType() == -1){
sql = String.format("select ip,stack from service_server_exception where time > '%s' and time < '%s'",req.getStartTime(),req.getEndTime());
sql = String.format("select ip,stack from service_server_exception where %s and time > '%s' and time < '%s'",contextFilter,req.getStartTime(),req.getEndTime());
}else{
sql = String.format("select ip,stack from service_server_exception where context='%s' and time > '%s' and time < '%s'",req.getServiceName(),req.getStartTime(),req.getEndTime());
}
... ... @@ -123,7 +125,7 @@ public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements S
@Override
public Map<String,List> getServiceNameJavaApiGraph(String source){
Map<String,List> resultMap = new HashMap();
String sql = "select count(stack) from service_server_exception where time > now() - 10m GROUP BY context,time(1m) fill(null)";
String sql = String.format("select count(stack) from service_server_exception where %s and time > now() - 10m GROUP BY context,time(1m) fill(null)",contextFilter);
QueryResult queryResult = query(source, sql, InfluxDBContants.YOMO_MONITOR);
QueryResult.Result rel = queryResult.getResults().get(0);
List<QueryResult.Series> listSeries = rel.getSeries();
... ... @@ -174,9 +176,9 @@ public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements S
if(req.getServiceType() == -1){
if(StringUtils.isNotBlank(req.getIp())){
sql = String.format("select event,stack from service_server_exception where time > '%s' and time < '%s' and hostAddress = '%s'",req.getStartTime(),req.getEndTime(),req.getIp());
sql = String.format("select event,stack from service_server_exception where %s and time > '%s' and time < '%s' and hostAddress = '%s'",contextFilter,req.getStartTime(),req.getEndTime(),req.getIp());
}else{
sql = String.format("select event,stack from service_server_exception where time > '%s' and time < '%s'",req.getStartTime(),req.getEndTime());
sql = String.format("select event,stack from service_server_exception where %s and time > '%s' and time < '%s'",contextFilter,req.getStartTime(),req.getEndTime());
}
}else{
if(StringUtils.isNotBlank(req.getIp())){
... ...
... ... @@ -41,6 +41,8 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
@Autowired
private VMInfoMapper vmInfoMapper;
private String[] serviceNames = {"gateway","order","promotion","product","message","sns","users","resources","brower"};
@Override
public List<NewJavaApiInfoRep> getJavaApiStatus(NewJavaApiInfoReq req) {
... ... @@ -143,7 +145,7 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
@Override
public Map getServiceNameJavaApiGraph(NewJavaApiInfoReq req){
Map returnMap = new HashMap();
List<TypeInfo> typeInfoList = mTypeInfoMapper.getChildTypesInfoByAlias("java_app");
List<TypeInfo> typeInfoList = mTypeInfoMapper.getTypesInfoByAliasList(Arrays.asList(serviceNames));
if(CollectionUtils.isEmpty(typeInfoList)){
return null;
}
... ... @@ -192,7 +194,7 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
public List<String> getIPList(NewJavaApiInfoReq req){
List<MObjectInfo> objectInfoList = new ArrayList<>();
if(req.getServiceType() == -1){
List<TypeInfo> typeInfoList = mTypeInfoMapper.getChildTypesInfoByAlias("java_app");
List<TypeInfo> typeInfoList = mTypeInfoMapper.getTypesInfoByAliasList(Arrays.asList(serviceNames));
if(CollectionUtils.isEmpty(typeInfoList)){
return null;
}
... ... @@ -229,6 +231,7 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
private List<MObjectInfo> getMObjectInfoList(NewJavaApiInfoReq req){
//servicetype=-1表示查询全部 0表示gateway
if(req.getServiceType() == -1){
//筛选需要的9个服务
List<MObjectInfo> objectInfoList = mObjectInfoMapper.selectJavaDistinctHostIP();
return objectInfoList;
}
... ...
... ... @@ -22,6 +22,8 @@ public interface MTypeInfoMapper {
TypeInfo selectTypeInfoByName(String typeName);
List<TypeInfo> getChildTypesInfoByAlias(String alias);
// List<TypeInfo> getChildTypesInfoByAlias(String alias);
List<TypeInfo> getTypesInfoByAliasList(List<String> aliasList);
}
... ...
... ... @@ -70,8 +70,9 @@
<select id="selectJavaDistinctHostIP" resultType="com.model.MObjectInfo" resultMap="mobjectInfoMapper">
SELECT b.`host_ip`,GROUP_CONCAT(a.`alias`) alias FROM `type_info` a,`mobject_info` b
WHERE a.`id` = b.`type_id` AND a.`parent_id` = (SELECT id FROM `type_info` t WHERE t.`alias` = 'java_app') GROUP BY b.`host_ip`
SELECT b.`host_ip`,GROUP_CONCAT(a.`alias`) alias FROM `type_info` a,`mobject_info` b
WHERE a.`id` = b.`type_id` AND a.`alias` IN ('gateway','order','promotion','product','message','sns','users','resources','brower')
AND a.`parent_id` = (SELECT id FROM `type_info` t WHERE t.`alias` = 'java_app') GROUP BY b.`host_ip`
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -53,10 +53,20 @@
<select id="getChildTypesInfoByAlias" resultType="com.model.TypeInfo" resultMap="typeInfoMap">
<!--<select id="getChildTypesInfoByAlias" resultType="com.model.TypeInfo" resultMap="typeInfoMap">-->
<!--SELECT-->
<!--<include refid="Base_Column_List"/>-->
<!--FROM `type_info` tt WHERE tt.`parent_id` = (SELECT id FROM `type_info` t WHERE t.`alias` = #{alias})-->
<!--</select>-->
<select id="getTypesInfoByAliasList" resultType="com.model.TypeInfo" resultMap="typeInfoMap">
SELECT
<include refid="Base_Column_List"/>
FROM `type_info` tt WHERE tt.`parent_id` = (SELECT id FROM `type_info` t WHERE t.`alias` = #{alias})
FROM `type_info` where alias in
<foreach collection="list" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...