Authored by jack.xue

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

@@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.Scheduled; @@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.Scheduled;
8 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
9 9
10 /** 10 /**
  11 + * javaApi 定时任务
11 * Created by fruwei on 2016/6/19. 12 * Created by fruwei on 2016/6/19.
12 */ 13 */
13 @Component 14 @Component
@@ -70,7 +70,7 @@ public class JavaApiClient { @@ -70,7 +70,7 @@ public class JavaApiClient {
70 private int JavaApiExecutorPoolMaxSize; 70 private int JavaApiExecutorPoolMaxSize;
71 71
72 72
73 - //TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成 73 + //TODO 需不需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成
74 private Map<String, JavaApiInfo> javaApimap; 74 private Map<String, JavaApiInfo> javaApimap;
75 75
76 private MultiValueMap<Integer, MObjectDetails> mObjInfoMap; 76 private MultiValueMap<Integer, MObjectDetails> mObjInfoMap;
@@ -80,6 +80,9 @@ public class JavaApiClient { @@ -80,6 +80,9 @@ public class JavaApiClient {
80 private CompletionService<JavaApiStatics> completionService; 80 private CompletionService<JavaApiStatics> completionService;
81 81
82 82
  83 + /**
  84 + * 初始化任务执行客户端
  85 + */
83 public void initClient() { 86 public void initClient() {
84 executorService = new ThreadPoolExecutor(JavaApiExecutorPoolCoreSize, JavaApiExecutorPoolMaxSize, 87 executorService = new ThreadPoolExecutor(JavaApiExecutorPoolCoreSize, JavaApiExecutorPoolMaxSize,
85 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), 88 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
@@ -94,6 +97,9 @@ public class JavaApiClient { @@ -94,6 +97,9 @@ public class JavaApiClient {
94 javaApiStatus.clear(); 97 javaApiStatus.clear();
95 } 98 }
96 99
  100 + /**
  101 + * 初始化监控的任务列表
  102 + */
97 public void initApiMonitor() { 103 public void initApiMonitor() {
98 //获取JAVA服务信息 104 //获取JAVA服务信息
99 List<JavaApiInfo> apiInfos = javaApiInfoService.queryJavaApiInfo(); 105 List<JavaApiInfo> apiInfos = javaApiInfoService.queryJavaApiInfo();
@@ -135,6 +141,9 @@ public class JavaApiClient { @@ -135,6 +141,9 @@ public class JavaApiClient {
135 } 141 }
136 142
137 143
  144 + /**
  145 + * 任务执行函数
  146 + */
138 public void run() { 147 public void run() {
139 long startTime = System.currentTimeMillis(); 148 long startTime = System.currentTimeMillis();
140 int tastNum = 0; 149 int tastNum = 0;
@@ -169,6 +178,11 @@ public class JavaApiClient { @@ -169,6 +178,11 @@ public class JavaApiClient {
169 } 178 }
170 179
171 180
  181 + /**
  182 + * 结果处理函数
  183 + *
  184 + * @param rep
  185 + */
172 public void handleResult(JavaApiStatics rep) { 186 public void handleResult(JavaApiStatics rep) {
173 187
174 188
@@ -59,6 +59,11 @@ public class JavaApiStatus { @@ -59,6 +59,11 @@ public class JavaApiStatus {
59 } 59 }
60 60
61 61
  62 + /**
  63 + * 获取各个模块的状态
  64 + *
  65 + * @return
  66 + */
62 public List<JavaApiStaticsRep> getStatusList() { 67 public List<JavaApiStaticsRep> getStatusList() {
63 68
64 List<JavaApiStaticsRep> rel = new ArrayList<JavaApiStaticsRep>(); 69 List<JavaApiStaticsRep> rel = new ArrayList<JavaApiStaticsRep>();
@@ -12,6 +12,7 @@ import org.springframework.web.client.RestTemplate; @@ -12,6 +12,7 @@ import org.springframework.web.client.RestTemplate;
12 import java.util.concurrent.Callable; 12 import java.util.concurrent.Callable;
13 13
14 /** 14 /**
  15 + * java api 任务单元
15 * Created by fruwei on 2016/6/19. 16 * Created by fruwei on 2016/6/19.
16 */ 17 */
17 public class JavaApiTask implements Callable<JavaApiStatics> { 18 public class JavaApiTask implements Callable<JavaApiStatics> {
@@ -4,6 +4,8 @@ import java.util.concurrent.ThreadFactory; @@ -4,6 +4,8 @@ import java.util.concurrent.ThreadFactory;
4 import java.util.concurrent.atomic.AtomicInteger; 4 import java.util.concurrent.atomic.AtomicInteger;
5 5
6 /** 6 /**
  7 + * 自定义java api线程池内工作线程工厂
  8 + * 指定生成线程名称:pool-javaApi-thread-[num]
7 * Created by fruwei on 2016/6/20. 9 * Created by fruwei on 2016/6/20.
8 */ 10 */
9 public class JavaApiThreadFactory implements ThreadFactory { 11 public class JavaApiThreadFactory implements ThreadFactory {
@@ -31,6 +31,15 @@ public class JavaAppInfoStaticsCtrl { @@ -31,6 +31,15 @@ public class JavaAppInfoStaticsCtrl {
31 @Autowired 31 @Autowired
32 IJavaApiStatusService javaApiStatusService; 32 IJavaApiStatusService javaApiStatusService;
33 33
  34 + @Autowired
  35 + JavaApiClient client; //留给测试函数使用
  36 +
  37 + /**
  38 + * 查询单个api的状态
  39 + *
  40 + * @param req
  41 + * @return
  42 + */
34 @RequestMapping("/queryOne") 43 @RequestMapping("/queryOne")
35 @ResponseBody 44 @ResponseBody
36 public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq req) { 45 public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq req) {
@@ -49,6 +58,12 @@ public class JavaAppInfoStaticsCtrl { @@ -49,6 +58,12 @@ public class JavaAppInfoStaticsCtrl {
49 return rep; 58 return rep;
50 } 59 }
51 60
  61 + /**
  62 + * 批量查询api的状态
  63 + *
  64 + * @param req
  65 + * @return
  66 + */
52 @RequestMapping("/query") 67 @RequestMapping("/query")
53 @ResponseBody 68 @ResponseBody
54 public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq[] req) { 69 public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq[] req) {
@@ -67,9 +82,11 @@ public class JavaAppInfoStaticsCtrl { @@ -67,9 +82,11 @@ public class JavaAppInfoStaticsCtrl {
67 } 82 }
68 83
69 84
70 - @Autowired  
71 - JavaApiClient client;  
72 - 85 + /**
  86 + * 手动任务执行入口
  87 + *
  88 + * @return
  89 + */
73 @RequestMapping("/tasktest") 90 @RequestMapping("/tasktest")
74 @ResponseBody 91 @ResponseBody
75 public String getJavaApiStatus() { 92 public String getJavaApiStatus() {
@@ -81,6 +98,11 @@ public class JavaAppInfoStaticsCtrl { @@ -81,6 +98,11 @@ public class JavaAppInfoStaticsCtrl {
81 return "cost : " + (end - start) / 1000 + "s"; 98 return "cost : " + (end - start) / 1000 + "s";
82 } 99 }
83 100
  101 + /**
  102 + * 最近的api日志
  103 + *
  104 + * @return
  105 + */
84 @RequestMapping("/querylatesthis") 106 @RequestMapping("/querylatesthis")
85 @ResponseBody 107 @ResponseBody
86 public BaseResponse getJavaApiStatusHisLatest(@RequestParam(required = false, defaultValue = "0") int api_id, 108 public BaseResponse getJavaApiStatusHisLatest(@RequestParam(required = false, defaultValue = "0") int api_id,
@@ -99,6 +121,11 @@ public class JavaAppInfoStaticsCtrl { @@ -99,6 +121,11 @@ public class JavaAppInfoStaticsCtrl {
99 121
100 } 122 }
101 123
  124 + /**
  125 + * 条件查询api日志
  126 + *
  127 + * @return
  128 + */
102 @RequestMapping("/queryhis") 129 @RequestMapping("/queryhis")
103 @ResponseBody 130 @ResponseBody
104 public BaseResponse getJavaApiStatusHis(@RequestBody JavaApiHisReq req) { 131 public BaseResponse getJavaApiStatusHis(@RequestBody JavaApiHisReq req) {
@@ -132,6 +159,11 @@ public class JavaAppInfoStaticsCtrl { @@ -132,6 +159,11 @@ public class JavaAppInfoStaticsCtrl {
132 159
133 } 160 }
134 161
  162 + /**
  163 + * 查询api各个模块的统计信息
  164 + *
  165 + * @return
  166 + */
135 @RequestMapping("/queryAll") 167 @RequestMapping("/queryAll")
136 @ResponseBody 168 @ResponseBody
137 public BaseResponse getAllJavaApiStatus() { 169 public BaseResponse getAllJavaApiStatus() {
@@ -8,6 +8,11 @@ import com.monitor.javaserver.common.JavaApiStatics; @@ -8,6 +8,11 @@ import com.monitor.javaserver.common.JavaApiStatics;
8 */ 8 */
9 public interface IJavaApiHadnler { 9 public interface IJavaApiHadnler {
10 10
11 - public void handler(JavaApiStatics javaApiStatics) ; 11 + /**
  12 + * 请求处理函数
  13 + *
  14 + * @param javaApiStatics
  15 + */
  16 + public void handler(JavaApiStatics javaApiStatics);
12 17
13 } 18 }
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Component; 14 import org.springframework.stereotype.Component;
15 15
16 /** 16 /**
  17 + * influxdb api访问日志记录
17 * Created by fruwei on 2016/6/20. 18 * Created by fruwei on 2016/6/20.
18 */ 19 */
19 @Component("influxDBJavaApiHandler") 20 @Component("influxDBJavaApiHandler")
@@ -27,7 +28,6 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler { @@ -27,7 +28,6 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
27 public void handler(JavaApiStatics javaApiStatics) { 28 public void handler(JavaApiStatics javaApiStatics) {
28 // log.info("handle result: {}", javaApiStatics); 29 // log.info("handle result: {}", javaApiStatics);
29 30
30 -  
31 JSONObject jsonObject = new JSONObject(); 31 JSONObject jsonObject = new JSONObject();
32 JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo(); 32 JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo();
33 jsonObject.put("api_id", javaApiInfo.getServiceId()); 33 jsonObject.put("api_id", javaApiInfo.getServiceId());
@@ -51,14 +51,11 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler { @@ -51,14 +51,11 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
51 jsonObject.put("is_exception", javaApiStatics.isHasException()); 51 jsonObject.put("is_exception", javaApiStatics.isHasException());
52 if (javaApiStatics.isHasException()) { 52 if (javaApiStatics.isHasException()) {
53 jsonObject.put("exception", ExceptionUtils.getStackTrace(javaApiStatics.getException())); 53 jsonObject.put("exception", ExceptionUtils.getStackTrace(javaApiStatics.getException()));
54 -  
55 } else { 54 } else {
56 // JSONObject rep = javaApiStatics.getResponse(); 55 // JSONObject rep = javaApiStatics.getResponse();
57 // jsonObject.put("response", javaApiStatics.getResponse()); 56 // jsonObject.put("response", javaApiStatics.getResponse());
58 } 57 }
59 58
60 javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject); 59 javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject);
61 -  
62 -  
63 } 60 }
64 } 61 }
@@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentHashMap; @@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentHashMap;
16 import java.util.concurrent.atomic.AtomicInteger; 16 import java.util.concurrent.atomic.AtomicInteger;
17 17
18 /** 18 /**
  19 + * 短信告警处理
19 * Created by fruwei on 2016/6/22. 20 * Created by fruwei on 2016/6/22.
20 */ 21 */
21 @Component("msgJavaApiHandler") 22 @Component("msgJavaApiHandler")
@@ -36,8 +37,10 @@ public class MsgJavaApiHandler implements IJavaApiHadnler { @@ -36,8 +37,10 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
36 @Override 37 @Override
37 public void handler(JavaApiStatics javaApiStatics) { 38 public void handler(JavaApiStatics javaApiStatics) {
38 String key = buildKey(javaApiStatics); 39 String key = buildKey(javaApiStatics);
39 - //无错  
40 - if (javaApiStatics.isHasException() == false) { 40 + //开关关闭、告警次数未设置、无错
  41 + if (javaApiStatics.getJavaApiInfo().getApiToggle() == 0 ||
  42 + javaApiStatics.getJavaApiInfo().getApiWarnTrigger() <= 0 ||
  43 + javaApiStatics.isHasException() == false) {
41 if (mapStatics.containsKey(key)) { 44 if (mapStatics.containsKey(key)) {
42 mapStatics.remove(key); 45 mapStatics.remove(key);
43 } 46 }
@@ -76,10 +79,9 @@ public class MsgJavaApiHandler implements IJavaApiHadnler { @@ -76,10 +79,9 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
76 msgBuilder.append("Java API Error ") 79 msgBuilder.append("Java API Error ")
77 .append("最近出错次数:" + num).append(" , ") 80 .append("最近出错次数:" + num).append(" , ")
78 .append("NAME:" + javaApiInfo.getApiName()).append(" , ") 81 .append("NAME:" + javaApiInfo.getApiName()).append(" , ")
79 - .append("URL:" + javaApiInfo.getApiUrl()).append(" , ") 82 +// .append("URL:" + javaApiInfo.getApiUrl()).append(" , ")
80 .append("IP:" + mObjectInfo.getMoHostIp()).append(" , ") 83 .append("IP:" + mObjectInfo.getMoHostIp()).append(" , ")
81 - .append("TYPE:" + javaApiInfo.getServiceType()).append(" , ")  
82 - .append("."); 84 + .append("TYPE:" + javaApiInfo.getServiceType()).append(" , ");
83 85
84 return msgBuilder.toString(); 86 return msgBuilder.toString();
85 } 87 }
@@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger; @@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
11 11
12 /** 12 /**
13 * 统计信息处理 13 * 统计信息处理
  14 + * 统计每个模块的(gateway,order...)的整体状态(出错、成功数量)
14 * Created by fruwei on 2016/6/27. 15 * Created by fruwei on 2016/6/27.
15 */ 16 */
16 @Component 17 @Component
@@ -23,7 +24,7 @@ public class StaticsJavaApiHandler implements IJavaApiHadnler { @@ -23,7 +24,7 @@ public class StaticsJavaApiHandler implements IJavaApiHadnler {
23 @Override 24 @Override
24 public void handler(JavaApiStatics javaApiStatics) { 25 public void handler(JavaApiStatics javaApiStatics) {
25 26
26 - if(javaApiStatics.getJavaApiInfo().getApiToggle()==0){ 27 + if (javaApiStatics.getJavaApiInfo().getApiToggle() == 0) {
27 return; 28 return;
28 } 29 }
29 if (javaApiStatics.isHasException()) { 30 if (javaApiStatics.isHasException()) {
@@ -31,8 +32,5 @@ public class StaticsJavaApiHandler implements IJavaApiHadnler { @@ -31,8 +32,5 @@ public class StaticsJavaApiHandler implements IJavaApiHadnler {
31 } else { 32 } else {
32 javaApiStatus.addSuccess(javaApiStatics); 33 javaApiStatus.addSuccess(javaApiStatics);
33 } 34 }
34 -  
35 } 35 }
36 -  
37 -  
38 } 36 }
@@ -13,16 +13,52 @@ import java.util.List; @@ -13,16 +13,52 @@ import java.util.List;
13 public interface IJavaApiStatusService { 13 public interface IJavaApiStatusService {
14 14
15 15
  16 + /**
  17 + * 查询api的状态
  18 + *
  19 + * @param req
  20 + * @return
  21 + */
16 public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req); 22 public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req);
17 23
  24 + /**
  25 + * 批量查询api的状态
  26 + *
  27 + * @param reqList
  28 + * @return
  29 + */
18 public List<JavaApiStatusRep> getJavaApiStatusList(List<JavaApiStatusReq> reqList); 30 public List<JavaApiStatusRep> getJavaApiStatusList(List<JavaApiStatusReq> reqList);
19 31
  32 + /**
  33 + * 查询最近的java api的历史信息
  34 + *
  35 + * @param api_id
  36 + * @param mobj_id
  37 + * @return
  38 + */
20 public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id); 39 public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id);
21 40
  41 + /**
  42 + * 根据时间段、查询条件查询java api的历史信息
  43 + *
  44 + * @param req
  45 + * @return
  46 + */
22 public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req); 47 public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req);
23 48
  49 + /**
  50 + * 根据时间段、查询条件统计数量
  51 + *
  52 + * @param req
  53 + * @return
  54 + */
24 public int countJavaApiStatusHisByTime(JavaApiHisReq req); 55 public int countJavaApiStatusHisByTime(JavaApiHisReq req);
25 56
  57 + /**
  58 + * 获取各个模块的状态信息
  59 + *
  60 + * @return
  61 + */
26 public List<JavaApiStaticsRep> getAllJavaApiStatus(); 62 public List<JavaApiStaticsRep> getAllJavaApiStatus();
27 63
28 64
@@ -18,7 +18,7 @@ public class ZookeeperMonitorTask { @@ -18,7 +18,7 @@ public class ZookeeperMonitorTask {
18 IZkMonitorService zkMonitorService; 18 IZkMonitorService zkMonitorService;
19 19
20 //@Scheduled(fixedRate=20000) 20 //@Scheduled(fixedRate=20000)
21 - //@Scheduled(cron="0 */5 * * * ?") 21 + //@Scheduled(cron="0 */15 * * * ?")
22 public void zookeeperMonitor() { 22 public void zookeeperMonitor() {
23 zkMonitorService.zookeeperMonitor(); 23 zkMonitorService.zookeeperMonitor();
24 } 24 }
@@ -46,7 +46,7 @@ sendsms.alarm.mobile.logs.sns_send_failed=15905144483,18751986615,18652008443,18 @@ -46,7 +46,7 @@ sendsms.alarm.mobile.logs.sns_send_failed=15905144483,18751986615,18652008443,18
46 #-----------------------------Logs告警模块-------------------------- 46 #-----------------------------Logs告警模块--------------------------
47 47
48 #-----------------------------监控系统开发人员-------------------------- 48 #-----------------------------监控系统开发人员--------------------------
49 -sendsms.alarm.mobile.ops_manager.developer=13914772123,15150551036 49 +sendsms.alarm.mobile.ops_manager.developer=13914772123
50 #-----------------------------监控系统开发人员-------------------------- 50 #-----------------------------监控系统开发人员--------------------------
51 51
52 dnspod.mobile=15905144483,18652008443,18751986615 52 dnspod.mobile=15905144483,18652008443,18751986615
@@ -46,7 +46,7 @@ sendsms.alarm.mobile.logs.sns_send_failed=15905144483,18751986615,18652008443,18 @@ -46,7 +46,7 @@ sendsms.alarm.mobile.logs.sns_send_failed=15905144483,18751986615,18652008443,18
46 #-----------------------------Logs告警模块-------------------------- 46 #-----------------------------Logs告警模块--------------------------
47 47
48 #-----------------------------监控系统开发人员-------------------------- 48 #-----------------------------监控系统开发人员--------------------------
49 -sendsms.alarm.mobile.ops_manager.developer=13914772123,15150551036 49 +sendsms.alarm.mobile.ops_manager.developer=13914772123
50 #-----------------------------监控系统开发人员-------------------------- 50 #-----------------------------监控系统开发人员--------------------------
51 51
52 dnspod.mobile=15905144483,18652008443,18751986615 52 dnspod.mobile=15905144483,18652008443,18751986615