Authored by wangning

update

package com.monitor.influxdb.mapper;
import com.monitor.model.request.NewJavaApiInfoReq;
import com.monitor.model.response.NewJavaApiDetailInfoRep;
import com.monitor.model.response.NewJavaApiInfoRep;
import java.util.List;
... ... @@ -16,5 +17,7 @@ public interface ServiceAccessMapper {
Map<String,List> getGraphInfo(String context);
// List getDataByContextAndIP(NewJavaApiInfoReq req);
List<NewJavaApiDetailInfoRep> getDataByContextAndIP(NewJavaApiInfoReq req);
Map<String,List<String>> getTimeoutInfoByContextAndIp(NewJavaApiInfoReq req);
}
... ...
package com.monitor.influxdb.mapper;
import com.monitor.model.request.NewJavaApiInfoReq;
import java.util.List;
import java.util.Map;
... ... @@ -10,4 +12,6 @@ public interface ServiceServerExceptionMapper {
Map<String,List<String>> getErrorDataByContext(String context,String startDateStr,String endDateStr);
Map<String,List> getGraphInfo(String context);
Map<String,List<String>> getErrorDataByContextAndIp(NewJavaApiInfoReq req);
}
... ...
... ... @@ -4,8 +4,10 @@ import com.monitor.influxdb.InfluxDBQuery;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.ServiceAccessMapper;
import com.monitor.model.request.NewJavaApiInfoReq;
import com.monitor.model.response.NewJavaApiDetailInfoRep;
import com.monitor.model.response.NewJavaApiInfoRep;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.QueryResult;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
... ... @@ -23,12 +25,13 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
Logger log = LoggerFactory.getLogger(ServiceAccessMapperImpl.class);
//根据context获取总响应次数和平均耗时
@Override
public Map<String,NewJavaApiInfoRep> getBaseDataByContext(String context,String startDateStr,String endDateStr) {
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",context,startDateStr,endDateStr);
// String sql = "select count(cost),mean(cost) from service_access group by hostAddress";
map.putAll(getDataByContext(InfluxDBContants.AWS,sql));
map.putAll(getDataByContext(InfluxDBContants.Q_CLOUD,sql));
... ... @@ -60,8 +63,8 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
@Override
public Map<String,List<String>> getTimeoutInfo(String context, String startDateStr, String endDateStr) {
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'",context,startDateStr,endDateStr);
// String sql = "select ip,stack from service_access where context='gateway' and cost > 200";
map.putAll(getTimeoutInfo(InfluxDBContants.AWS,sql));
map.putAll(getTimeoutInfo(InfluxDBContants.Q_CLOUD,sql));
return map;
... ... @@ -99,8 +102,8 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
@Override
public Map<String,List> getGraphInfo(String context){
Map<String,List> map = new HashMap();
// String sql = String.format("SELECT count(ip) 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)";
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;
... ... @@ -152,36 +155,85 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
// @Override
// public List getDataByContextAndIP(NewJavaApiInfoReq req) {
//
// List list = new ArrayList<>();
// String sql = "select count(cost),mean(cost) from service_access where context = 'gateway' and hostAddress = '172.16.6.170' group by src_service";
//
// list.addAll(getDataByContextAndIP(InfluxDBContants.AWS,sql));
// list.addAll(getDataByContextAndIP(InfluxDBContants.Q_CLOUD,sql));
// return list;
// }
// private List getDataByContextAndIP(String source,String sql) {
// List list = 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)
// return list;
// for(QueryResult.Series series : listSeries){
// Map map = new HashMap();
// String srcService = series.getTags().get("src_service");
// Double count = (Double)series.getValues().get(0).get(1);
// Double mean = (Double)series.getValues().get(0).get(2);
// map.put("apiName",srcService);
// map.put("totalCount",count.intValue());
// map.put("avgCost",mean.intValue());
// list.add(map);
// }
//
// return list;
// }
@Override
public List<NewJavaApiDetailInfoRep> getDataByContextAndIP(NewJavaApiInfoReq req) {
List<NewJavaApiDetailInfoRep> list = new ArrayList<>();
String source = "";
String sql = "";
if(req.getCloudType()==2){
source = InfluxDBContants.Q_CLOUD;
}else{
source = InfluxDBContants.AWS;
}
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());
}else{
sql = String.format("select count(cost),mean(cost) from service_access where context = '%s' group by event",req.getServiceName());
}
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 list;
for(QueryResult.Series series : listSeries){
NewJavaApiDetailInfoRep rep = new NewJavaApiDetailInfoRep();
String apiName = series.getTags().get("event");
Double count = (Double)series.getValues().get(0).get(1);
Double mean = (Double)series.getValues().get(0).get(2);
rep.setApiName(apiName);
rep.setTotalCount(count.intValue());
rep.setAvgCost(mean.intValue());
list.add(rep);
}
return list;
}
@Override
public Map<String,List<String>> getTimeoutInfoByContextAndIp(NewJavaApiInfoReq req) {
String source = "";
String sql = "";
if(req.getCloudType()==2){
source = InfluxDBContants.Q_CLOUD;
}else{
source = InfluxDBContants.AWS;
}
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());
}else{
sql = String.format("select event,stack from service_access where context='%s' and cost > 200 ",req.getServiceName());
}
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 event = (String)objects.get(1);
String stack = (String)objects.get(2);
List<String> stackList = map.get(event);
if(stackList == null){
stackList = new ArrayList<>();
stackList.add(stack);
map.put(event,stackList);
}else{
stackList.add(stack);
}
}
return map;
}
}
... ...
... ... @@ -3,7 +3,9 @@ package com.monitor.influxdb.mapper.impl;
import com.monitor.influxdb.InfluxDBQuery;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.ServiceServerExceptionMapper;
import com.monitor.model.request.NewJavaApiInfoReq;
import com.monitor.model.response.NewJavaApiInfoRep;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.QueryResult;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
... ... @@ -17,11 +19,12 @@ import java.util.*;
@Component
public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements ServiceServerExceptionMapper {
//根据context获取错误信息列表
@Override
public Map<String,List<String>> getErrorDataByContext(String context,String startDateStr,String endDateStr) {
Map<String,List<String>> map = new HashMap();
// String sql = String.format("select ip,stack from service_server_exception where context='%s' and time > '%s' and time < '%s'",context,startDateStr,endDateStr);
String sql = "select ip,stack from service_server_exception";
String sql = String.format("select ip,stack from service_server_exception where context='%s' and time > '%s' and time < '%s'",context,startDateStr,endDateStr);
// String sql = "select ip,stack from service_server_exception";
map.putAll(getDataByContext(InfluxDBContants.AWS,sql));
map.putAll(getDataByContext(InfluxDBContants.Q_CLOUD,sql));
return map;
... ... @@ -64,7 +67,8 @@ public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements S
@Override
public Map<String,List> getGraphInfo(String context){
Map<String,List> map = new HashMap();
String sql = "select count(stack) from service_server_exception where time > '2016-10-20 12:04:00' and time < '2016-10-20 12:14:00' GROUP BY hostAddress,time(1m) fill(null)";
String sql = String.format("select count(stack) from service_server_exception where context = '%s' and time > now() - 10m GROUP BY hostAddress,time(1m) fill(null)",context);
// String sql = "select count(stack) from service_server_exception where time > '2016-10-20 12:04:00' and time < '2016-10-20 12:14:00' GROUP BY hostAddress,time(1m) fill(null)";
map.putAll(getGraphInfo(InfluxDBContants.AWS,sql));
map.putAll(getGraphInfo(InfluxDBContants.Q_CLOUD,sql));
return map;
... ... @@ -110,4 +114,49 @@ public class ServiceServerExceptionMapperImpl extends InfluxDBQuery implements S
return resultMap;
}
@Override
public Map<String,List<String>> getErrorDataByContextAndIp(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(StringUtils.isNotBlank(req.getIp())){
sql = String.format("select event,stack from service_server_exception where context='%s' and hostAddress = '%s'",req.getServiceName(),req.getIp());
}else{
sql = String.format("select event,stack from service_server_exception where context='%s'",req.getServiceName());
}
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;
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 event = objects.get(1).toString();
String stack = objects.get(2).toString();
List<String> stackList = map.get(event);
if(stackList == null){
stackList = new ArrayList<>();
stackList.add(stack);
map.put(event,stackList);
}else{
stackList.add(stack);
}
}
return map;
}
}
... ...
package com.monitor.javaserver.ctrl;
import com.monitor.common.util.HttpRestClient;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.javaserver.service.NewJavaApiInfoService;
import com.monitor.model.request.NewJavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.NewJavaApiDetailInfoRep;
import com.monitor.model.response.NewJavaApiInfoRep;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.influxdb.dto.Point;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
... ... @@ -19,10 +20,12 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.DecimalFormat;
import java.util.*;
/**
* Created by wangning on 2016/10/20.
* java服务接口监控
*/
@Controller
@RequestMapping("newJavaApiInfo")
... ... @@ -36,12 +39,18 @@ public class NewJavaApiInfoCtrl {
@Autowired
private InluxDBSingle inluxDBSingle;
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
@Autowired
HttpRestClient httpRestClient;
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
//根据serviceName和timeInterval查询每台ip的监控信息
@RequestMapping("/queryByServiceType")
@ResponseBody
public BaseResponse getJavaApiStatus(@RequestBody NewJavaApiInfoReq req) {
log.info("queryByServiceType accept pram : {},{},{}",req.getServiceType(),req.getServiceName(),req.getTimeInterval());
//influxdb使用的是utc时间
DateTime endDateTime = DateTime.now(DateTimeZone.UTC);
DateTime startDateTime = endDateTime.minusMinutes(req.getTimeInterval());
String startDateStr = startDateTime.toString(DATE_TIME_FORMAT);
... ... @@ -57,19 +66,22 @@ public class NewJavaApiInfoCtrl {
return rep;
}
//根据serviceName获取平均耗时和异常次数的曲线图信息
@RequestMapping("/getJavaApiGraph")
@ResponseBody
public BaseResponse getJavaApiGraph(@RequestBody NewJavaApiInfoReq req) {
log.info("getJavaApiGraph accept pram : {},{},{}",req.getServiceType(),req.getServiceName(),req.getGraphType());
Map map = newJavaApiInfoService.getJavaApiGraph(req);
BaseResponse rep = new BaseResponse();
rep.setData(map);
return rep;
}
//根据serviceType获取所有ip列表
@RequestMapping("/getIPList")
@ResponseBody
public BaseResponse getIPList(@RequestBody NewJavaApiInfoReq req) {
log.info("getIPList accept pram : {},{},{}",req.getCloudType(),req.getServiceType(),req.getServiceName());
List<String> ipList = newJavaApiInfoService.getIPList(req);
BaseResponse rep = new BaseResponse();
rep.setData(ipList);
... ... @@ -77,29 +89,82 @@ public class NewJavaApiInfoCtrl {
}
//根据context和ip查询详细接口信息
@RequestMapping("/queryByServiceTypeAndIP")
@ResponseBody
public BaseResponse queryByServiceTypeAndIP(@RequestBody NewJavaApiInfoReq req) {
log.info("getIPList accept pram : {},{},{}",req.getCloudType(),req.getServiceType(),req.getServiceName(),req.getIp(),req.getStartTime(),req.getEndTime());
List<NewJavaApiDetailInfoRep> list = newJavaApiInfoService.queryByServiceTypeAndIP(req);
BaseResponse rep = new BaseResponse();
rep.setData(list);
return rep;
}
// @RequestMapping("/queryByServiceTypeAndIP")
// @ResponseBody
// public BaseResponse queryByServiceTypeAndIP(@RequestBody NewJavaApiInfoReq req) {
// List list = newJavaApiInfoService.queryByServiceTypeAndIP(req);
// BaseResponse rep = new BaseResponse();
// rep.setData(list);
// return rep;
// }
@RequestMapping("/test")
@ResponseBody
public BaseResponse test() {
String[] strs = new String[]{"192.168.102.76","172.31.31.169","172.31.28.166","172.31.17.195","172.16.6.235","172.16.6.170","10.66.0.5","10.66.0.4","10.66.0.6","10.66.0.7","10.66.0.8","10.66.0.9","10.66.0.10","10.66.0.11","10.66.0.12","10.66.0.13","10.66.0.14"};
DecimalFormat df = new DecimalFormat("######0.00");
for(int i = 0;i<strs.length;i++){
String ip = strs[i];
Double CPU_UTIL_USER = Double.parseDouble(df.format(RandomUtils.nextDouble()));
Double MEMORY_SIZE_AVAILABLE = Double.parseDouble(df.format(RandomUtils.nextDouble() * 1000));
Double MEMORY_SIZE_TOTAL = Double.parseDouble(df.format(RandomUtils.nextDouble() * 1000));
Double NET_IF_IN = Double.parseDouble(df.format(RandomUtils.nextDouble() * 1000));
Double NET_IF_OUT = Double.parseDouble(df.format(RandomUtils.nextDouble() * 1000));
Point point = Point.measurement("vm_info")
.tag("ip",ip)
.addField("CPU_UTIL_USER",CPU_UTIL_USER).addField("MEMORY_SIZE_AVAILABLE",MEMORY_SIZE_AVAILABLE).addField("MEMORY_SIZE_TOTAL",MEMORY_SIZE_TOTAL)
.addField("NET_IF_IN",NET_IF_IN).addField("NET_IF_OUT",NET_IF_OUT)
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(InfluxDBContants.ZABBIX, "default", point);
}
return null;
}
@RequestMapping("/test2")
@ResponseBody
public BaseResponse test2() {
String[] strs = new String[]{"192.168.102.76","172.31.31.169","172.31.28.166","172.31.17.195","172.16.6.235","172.16.6.170","10.66.0.5","10.66.0.4","10.66.0.6","10.66.0.7","10.66.0.8","10.66.0.9","10.66.0.10","10.66.0.11","10.66.0.12","10.66.0.13","10.66.0.14"};
for(int i = 0;i<strs.length;i++){
String ip = strs[i];
Point point = Point.measurement("service_access")
.tag("context","gateway").tag("event","/gateway").tag("host","/gateway")
.tag("hostAddress",ip).tag("src_service","app.product.promotion").tag("status_code","200")
.addField("cost", RandomUtils.nextInt(199) + 2000).addField("ip",ip)
.addField("stack","Total Delay [15004ms] /gateway +---[15004ms] - com.yoho.core.common.monitor.ThreadProfileInterceptor.preHandle - [enter:1476930300814,exit:1476930315818] +---[15004ms] - app.product.data. - [enter:1476930300814,exit:1476930315818]")
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(InfluxDBContants.YOHO_EVENT, "default", point);
}
return null;
}
@RequestMapping("/test")
@RequestMapping("/test3")
@ResponseBody
public BaseResponse getJavaApiStatus() {
Point point = Point.measurement("service_server_exception")
.addField("ip","172.31.28.166")
.addField("stack","234523453")
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(InfluxDBContants.YOMO_MONITOR, "default", point);
public BaseResponse test3() {
String[] strs = new String[]{"192.168.102.76","172.31.31.169","172.31.28.166","172.31.17.195","172.16.6.235","172.16.6.170","10.66.0.5","10.66.0.4","10.66.0.6","10.66.0.7","10.66.0.8","10.66.0.9","10.66.0.10","10.66.0.11","10.66.0.12","10.66.0.13","10.66.0.14"};
for(int i = 0;i<strs.length;i++){
String ip = strs[i];
Point point = Point.measurement("service_server_exception")
.tag("context","gateway").tag("event","/gateway").tag("host","/brower/favorite/isFavorite")
.tag("hostAddress",ip).tag("service_name","brower/favorite/isFavorite")
.addField("ip",ip)
.addField("stack","org.apache.catalina\\n.connector.ClientAbortException: java.io.IOException: 断开的管道\\n\\tat org.apache.catalina.connector.OutputBuffer\\n.realWriteBytes(OutputBuffer.java:393)\\n\\tat org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk\\n.java:426)\\n\\tat org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:342)\\n\\tat org\\n.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:317)\\n\\tat org.apache.catalina.connector\\n.CoyoteOutputStream.flush(CoyoteOutputStream.java:110)\\n\\tat com.fasterxml.jackson.core.json.UTF8JsonGenerator\\n.flush(UTF8JsonGenerator.java:1022)\\n\\tat com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter\\n.java:891)\\n\\tat org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal\\n(AbstractJackson2HttpMessageConverter.java:264)\\n\\tat org.springframework.http.converter.AbstractGenericHttpMessageConverter\\n.write(AbstractGenericHttpMessageConverter.java:100)\\n\\tat org.springframework.web.servlet.mvc.method\\n.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor\\n.java:202)\\n\\tat org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor\\n.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:133)\\n\\tat org.springframework\\n.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor\\n.java:165)\\n\\tat org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue\\n(HandlerMethodReturnValueHandlerComposite.java:80)\\n\\tat org.springframework.web.servlet.mvc.method.annotation\\n.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126)\\n\\tat org.springframework\\n.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter\\n.java:806)\\n\\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal\\n(RequestMappingHandlerAdapter.java:729)\\n\\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter\\n.handle(AbstractHandlerMethodAdapter.java:85)\\n\\tat org.springframework.web.servlet.DispatcherServlet\\n.doDispatch(DispatcherServlet.java:959)\\n\\tat org.springframework.web.servlet.DispatcherServlet.doService\\n(DispatcherServlet.java:893)\\n\\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet\\n.java:970)\\n\\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)\\n\\n\\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:648)\\n\\tat org.springframework.web.servlet\\n.FrameworkServlet.service(FrameworkServlet.java:846)\\n\\tat javax.servlet.http.HttpServlet.service(HttpServlet\\n.java:729)\\n\\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain\\n.java:291)\\n\\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java\\n:206)\\n\\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\\n\\tat org.apache.catalina\\n.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\\n\\tat org.apache.catalina\\n.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\\n\\tat org.springframework.web\\n.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)\\n\\tat org.springframework\\n.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\\n\\tat org.apache.catalina.core\\n.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)\\n\\tat org.apache.catalina.core\\n.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)\\n\\tat org.apache.catalina.core.StandardWrapperValve\\n.invoke(StandardWrapperValve.java:217)\\n\\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve\\n.java:106)\\n\\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502\\n)\\n\\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)\\n\\tat org.apache\\n.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)\\n\\tat org.apache.catalina.core.StandardEngineValve\\n.invoke(StandardEngineValve.java:88)\\n\\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter\\n.java:518)\\n\\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java\\n:1091)\\n\\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java\\n:673)\\n\\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)\\n\\tat\\n org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)\\n\\tat java.util.concurrent\\n.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\\n\\tat java.util.concurrent.ThreadPoolExecutor$Worker\\n.run(ThreadPoolExecutor.java:617)\\n\\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run\\n(TaskThread.java:61)\\n\\tat java.lang.Thread.run(Thread.java:745)\\nCaused by: java.io.IOException: 断开\\n的管道\\n\\tat sun.nio.ch.FileDispatcherImpl.write0(Native Method)\\n\\tat sun.nio.ch.SocketDispatcher.write\\n(SocketDispatcher.java:47)\\n\\tat sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)\\n\\tat sun.nio\\n.ch.IOUtil.write(IOUtil.java:65)\\n\\tat sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471\\n)\\n\\tat org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:124)\\n\\tat org.apache.tomcat.util\\n.net.NioBlockingSelector.write(NioBlockingSelector.java:101)\\n\\tat org.apache.tomcat.util.net.NioSelectorPool\\n.write(NioSelectorPool.java:172)\\n\\tat org.apache.coyote.http11.InternalNioOutputBuffer.writeToSocket\\n(InternalNioOutputBuffer.java:139)\\n\\tat org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer\\n.java:197)\\n\\tat org.apache.coyote.http11.InternalNioOutputBuffer.access$000(InternalNioOutputBuffer\\n.java:41)\\n\\tat org.apache.coyote.http11.InternalNioOutputBuffer$SocketOutputBuffer.doWrite(InternalNioOutputBuffer\\n.java:320)\\n\\tat org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java\\n:118)\\n\\tat org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:256)\\n\\tat\\n org.apache.coyote.Response.doWrite(Response.java:501)\\n\\tat org.apache.catalina.connector.OutputBuffer\\n.realWriteBytes(OutputBuffer.java:388)\\n\\t... 47 more\\n")
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(InfluxDBContants.YOMO_MONITOR, "default", point);
}
return null;
}
}
... ...
package com.monitor.javaserver.service;
import com.monitor.model.request.NewJavaApiInfoReq;
import com.monitor.model.response.NewJavaApiDetailInfoRep;
import com.monitor.model.response.NewJavaApiInfoRep;
import java.util.List;
... ... @@ -16,5 +17,5 @@ public interface NewJavaApiInfoService {
List<String> getIPList(NewJavaApiInfoReq req);
// List queryByServiceTypeAndIP(NewJavaApiInfoReq req);
List<NewJavaApiDetailInfoRep> queryByServiceTypeAndIP(NewJavaApiInfoReq req);
}
... ...
... ... @@ -7,12 +7,14 @@ import com.monitor.influxdb.mapper.ServiceServerExceptionMapper;
import com.monitor.influxdb.mapper.VMInfoMapper;
import com.monitor.javaserver.service.NewJavaApiInfoService;
import com.monitor.model.request.NewJavaApiInfoReq;
import com.monitor.model.response.NewJavaApiDetailInfoRep;
import com.monitor.model.response.NewJavaApiInfoRep;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import com.monitor.mysql.mapper.MTypeInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
... ... @@ -41,18 +43,18 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
@Override
public List<NewJavaApiInfoRep> getJavaApiStatus(NewJavaApiInfoReq req,String startDateStr,String endDateStr) {
if(req.getServiceType() == 0){
TypeInfo typeInfo = mTypeInfoMapper.selectTypeInfoByName(req.getServiceName());
if(typeInfo == null){
return null;
}
req.setServiceType(typeInfo.getTypeId());
List<MObjectInfo> objectInfoList = getMObjectInfoList(req);
if(CollectionUtils.isEmpty(objectInfoList)){
return null;
}
List<MObjectInfo> objectInfoList = mObjectInfoMapper.getTypeMosInfo(req.getServiceType());
//获取总请求次数和平均耗时
Map<String,NewJavaApiInfoRep> infoMap = serviceAccessMapper.getBaseDataByContext(req.getServiceName(),startDateStr,endDateStr);
Map<String,List<String>> timeoutInfoList = serviceAccessMapper.getTimeoutInfo(req.getServiceName(),startDateStr,endDateStr);
Map<String,List<String>> errorInfoList = serviceServerExceptionMapper.getErrorDataByContext(req.getServiceName(),startDateStr,endDateStr);
//获取超时数据
Map<String,List<String>> timeoutInfoMap = serviceAccessMapper.getTimeoutInfo(req.getServiceName(),startDateStr,endDateStr);
//获取异常数据
Map<String,List<String>> errorInfoMap = serviceServerExceptionMapper.getErrorDataByContext(req.getServiceName(),startDateStr,endDateStr);
//获取cpu、内存、带宽使用情况
Map vmInfoMap = vmInfoMapper.getVMInfo();
List<NewJavaApiInfoRep> returnList = new ArrayList<>();
... ... @@ -68,23 +70,20 @@ 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(errorInfoList.size());
resp.setErrorInfo(errorInfoList.get(ip));
resp.setTimeoutInfo(timeoutInfoList.get(ip));
resp.setErrorCount(errorInfoMap.get(ip) == null ? 0 : errorInfoMap.get(ip).size());
resp.setErrorInfo(errorInfoMap.get(ip));
resp.setTimeoutInfo(timeoutInfoMap.get(ip));
List vmList = (List)vmInfoMap.get(ip);
if(vmList != null){
resp.setCpuRate("" + ((Double)vmList.get(1)).intValue() + "%");
resp.setMemoryRate("" + ((Double)vmList.get(2)).intValue() + "/" + ((Double)vmList.get(3)).intValue());
resp.setBandwidth("" + ((Double)vmList.get(4)).intValue() + "/" + ((Double)vmList.get(5)).intValue());
resp.setCpuRate("" + vmList.get(1) + "%");
resp.setMemoryRate("" + vmList.get(2) + "/" + vmList.get(3));
resp.setBandwidth("" + vmList.get(4) + "/" + vmList.get(5));
}
returnList.add(resp);
}
return returnList;
}
... ... @@ -92,22 +91,18 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
@Override
public Map getJavaApiGraph(NewJavaApiInfoReq req){
Map returnMap = new HashMap();
if(req.getServiceType() == 0){
TypeInfo typeInfo = mTypeInfoMapper.selectTypeInfoByName(req.getServiceName());
if(typeInfo == null){
return null;
}
req.setServiceType(typeInfo.getTypeId());
List<MObjectInfo> objectInfoList = getMObjectInfoList(req);
if(CollectionUtils.isEmpty(objectInfoList)){
return null;
}
List<MObjectInfo> objectInfoList = mObjectInfoMapper.getTypeMosInfo(req.getServiceType());
Map<String,List> map = null;
if(req.getGraphType()==1){
map = serviceAccessMapper.getGraphInfo(req.getServiceName());
}else{
if(req.getGraphType()==2){
map = serviceServerExceptionMapper.getGraphInfo(req.getServiceName());
}else{
map = serviceAccessMapper.getGraphInfo(req.getServiceName());
}
List<String> timeList = new ArrayList<String>();
List contentList = new ArrayList<>();
for(MObjectInfo mObjectInfo :objectInfoList){
... ... @@ -142,18 +137,58 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
List<String> ipList = new ArrayList<>();
for(MObjectInfo mObjectInfo : objectInfoList){
ipList.add(mObjectInfo.getMoHostIp());
if(req.getCloudType()==2){
if(mObjectInfo.getMoHostIp().startsWith("10.")){
ipList.add(mObjectInfo.getMoHostIp());
}
}else{
if(mObjectInfo.getMoHostIp().startsWith("172.")){
ipList.add(mObjectInfo.getMoHostIp());
}
}
}
return ipList;
}
// @Override
// public List queryByServiceTypeAndIP(NewJavaApiInfoReq req) {
// List list = serviceAccessMapper.getDataByContextAndIP(req);
// return list;
// }
//查询根据servicetype查询所有ip信息
private List<MObjectInfo> getMObjectInfoList(NewJavaApiInfoReq req){
if(req.getServiceType() == 0){
TypeInfo typeInfo = mTypeInfoMapper.selectTypeInfoByName(req.getServiceName());
if(typeInfo == null){
return null;
}
req.setServiceType(typeInfo.getTypeId());
}
List<MObjectInfo> objectInfoList = mObjectInfoMapper.getTypeMosInfo(req.getServiceType());
return objectInfoList;
}
@Override
public List<NewJavaApiDetailInfoRep> queryByServiceTypeAndIP(NewJavaApiInfoReq req) {
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);
for(NewJavaApiDetailInfoRep rep :dataList){
NewJavaApiDetailInfoRep returnRep = new NewJavaApiDetailInfoRep();
String apiName = rep.getApiName();
returnRep.setApiName(apiName);
returnRep.setErrorInfo(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));
returnList.add(returnRep);
}
return returnList;
}
... ...
... ... @@ -19,6 +19,8 @@ public class NewJavaApiInfoReq {
private String endTime;
//1:aws 2:qcloud
private int cloudType;
public int getServiceType() {
return serviceType;
... ... @@ -75,4 +77,12 @@ public class NewJavaApiInfoReq {
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public int getCloudType() {
return cloudType;
}
public void setCloudType(int cloudType) {
this.cloudType = cloudType;
}
}
... ...
package com.monitor.model.response;
import java.util.List;
/**
* Created by yoho on 2016/10/25.
*/
public class NewJavaApiDetailInfoRep {
private Integer totalCount = 0;
private Integer errorCount = 0;
private List<String> errorInfo;
private List<String> timeoutInfo;
private Integer avgCost = 0;
private String apiName;
public Integer getTotalCount() {
return totalCount;
}
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
public Integer getErrorCount() {
return errorCount;
}
public void setErrorCount(Integer errorCount) {
this.errorCount = errorCount;
}
public List<String> getErrorInfo() {
return errorInfo;
}
public void setErrorInfo(List<String> errorInfo) {
this.errorInfo = errorInfo;
}
public List<String> getTimeoutInfo() {
return timeoutInfo;
}
public void setTimeoutInfo(List<String> timeoutInfo) {
this.timeoutInfo = timeoutInfo;
}
public Integer getAvgCost() {
return avgCost;
}
public void setAvgCost(Integer avgCost) {
this.avgCost = avgCost;
}
public String getApiName() {
return apiName;
}
public void setApiName(String apiName) {
this.apiName = apiName;
}
}
... ...
... ... @@ -2,7 +2,7 @@
influxdb.num=4
influxdb.name=test;alarm;aws;qcloud
influxdb.ip=http://192.168.102.76:8086;http://192.168.102.76:8086;http://192.168.102.76:8086;http://192.168.102.76:8086
influxdb.ip=http://192.168.102.76:8086;http://192.168.102.76:8086;http://127.0.0.1:8086;http://127.0.0.1:8086
influxdb.user=yoho;root;root;root
influxdb.pwd=Yoho_9646;root;root;root
influxdb.connect.timeout=15;15;15;15
... ...