Authored by FengRuwei

java api 服务信息dashboard

@@ -249,7 +249,7 @@ public class TypeInfoCtrl { @@ -249,7 +249,7 @@ public class TypeInfoCtrl {
249 } 249 }
250 250
251 251
252 - @RequestMapping(value = "/queryJavaApi", method = RequestMethod.GET) 252 + @RequestMapping(value = "/queryJavaApi", method = RequestMethod.GET)
253 public BaseResponse queryJavaApi() { 253 public BaseResponse queryJavaApi() {
254 254
255 DEBUG.debug("Query all java api info..."); 255 DEBUG.debug("Query all java api info...");
@@ -62,7 +62,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { @@ -62,7 +62,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
62 if (statics.getBooleanValue("is_exception") == true) { 62 if (statics.getBooleanValue("is_exception") == true) {
63 pointBuilder.addField("exception", statics.getString("exception")); 63 pointBuilder.addField("exception", statics.getString("exception"));
64 } else { 64 } else {
65 - pointBuilder.addField("response", statics.getString("response")); 65 +// pointBuilder.addField("response", statics.getString("response"));
66 } 66 }
67 67
68 Point point = pointBuilder.build(); 68 Point point = pointBuilder.build();
@@ -38,6 +38,11 @@ @@ -38,6 +38,11 @@
38 </dependency> 38 </dependency>
39 <!--项目内部依赖--> 39 <!--项目内部依赖-->
40 40
  41 + <dependency>
  42 + <groupId>commons-collections</groupId>
  43 + <artifactId>commons-collections</artifactId>
  44 + <version>3.2.1</version>
  45 + </dependency>
41 </dependencies> 46 </dependencies>
42 47
43 48
1 package com.monitor.javaserver.client; 1 package com.monitor.javaserver.client;
2 2
  3 +import com.model.HostInfo;
3 import com.model.JavaApiInfo; 4 import com.model.JavaApiInfo;
  5 +import com.model.MObjectDetails;
4 import com.model.MObjectInfo; 6 import com.model.MObjectInfo;
  7 +import com.monitor.cmdb.service.IHostInfoService;
5 import com.monitor.cmdb.service.IJavaApiInfoService; 8 import com.monitor.cmdb.service.IJavaApiInfoService;
6 import com.monitor.cmdb.service.IMObjectInfoService; 9 import com.monitor.cmdb.service.IMObjectInfoService;
7 import com.monitor.javaserver.common.JavaApiStatics; 10 import com.monitor.javaserver.common.JavaApiStatics;
  11 +import com.monitor.javaserver.common.JavaApiStatus;
8 import com.monitor.javaserver.common.JavaApiTask; 12 import com.monitor.javaserver.common.JavaApiTask;
9 import com.monitor.javaserver.common.JavaApiThreadFactory; 13 import com.monitor.javaserver.common.JavaApiThreadFactory;
10 import com.monitor.javaserver.handle.IJavaApiHadnler; 14 import com.monitor.javaserver.handle.IJavaApiHadnler;
  15 +import com.monitor.model.request.HostInfoReq;
  16 +import com.monitor.model.response.PageResponse;
11 import org.slf4j.Logger; 17 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.BeanUtils;
13 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.beans.factory.annotation.Qualifier; 21 import org.springframework.beans.factory.annotation.Qualifier;
15 import org.springframework.stereotype.Component; 22 import org.springframework.stereotype.Component;
@@ -17,6 +24,7 @@ import org.springframework.util.LinkedMultiValueMap; @@ -17,6 +24,7 @@ import org.springframework.util.LinkedMultiValueMap;
17 import org.springframework.util.MultiValueMap; 24 import org.springframework.util.MultiValueMap;
18 import org.springframework.web.client.RestTemplate; 25 import org.springframework.web.client.RestTemplate;
19 26
  27 +import java.util.HashMap;
20 import java.util.List; 28 import java.util.List;
21 import java.util.Map; 29 import java.util.Map;
22 import java.util.concurrent.*; 30 import java.util.concurrent.*;
@@ -36,6 +44,9 @@ public class JavaApiClient { @@ -36,6 +44,9 @@ public class JavaApiClient {
36 private IMObjectInfoService mObjectInfoService; 44 private IMObjectInfoService mObjectInfoService;
37 45
38 @Autowired 46 @Autowired
  47 + private IHostInfoService hostInfoService;
  48 +
  49 + @Autowired
39 @Qualifier("javaapiRestTemplate") 50 @Qualifier("javaapiRestTemplate")
40 private RestTemplate restTemplate; 51 private RestTemplate restTemplate;
41 // 52 //
@@ -46,11 +57,14 @@ public class JavaApiClient { @@ -46,11 +57,14 @@ public class JavaApiClient {
46 @Autowired 57 @Autowired
47 private List<IJavaApiHadnler> javaApiHadnlerList; 58 private List<IJavaApiHadnler> javaApiHadnlerList;
48 59
  60 + @Autowired
  61 + JavaApiStatus javaApiStatus;
  62 +
49 63
50 //TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成 64 //TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成
51 private Map<String, JavaApiInfo> javaApimap; 65 private Map<String, JavaApiInfo> javaApimap;
52 66
53 - private MultiValueMap<Integer, MObjectInfo> mObjInfoMap; 67 + private MultiValueMap<Integer, MObjectDetails> mObjInfoMap;
54 68
55 private ExecutorService executorService; 69 private ExecutorService executorService;
56 70
@@ -64,21 +78,48 @@ public class JavaApiClient { @@ -64,21 +78,48 @@ public class JavaApiClient {
64 completionService = new ExecutorCompletionService<JavaApiStatics>(executorService); 78 completionService = new ExecutorCompletionService<JavaApiStatics>(executorService);
65 79
66 javaApimap = new ConcurrentHashMap<String, JavaApiInfo>(); 80 javaApimap = new ConcurrentHashMap<String, JavaApiInfo>();
67 - mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectInfo>(); 81 + mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectDetails>();
  82 +
  83 + //清理本次统计信息
  84 + javaApiStatus.clear();
68 } 85 }
69 86
70 public void initApiMonitor() { 87 public void initApiMonitor() {
  88 + //获取JAVA服务信息
71 List<JavaApiInfo> apiInfos = javaApiInfoService.queryJavaApiInfo(); 89 List<JavaApiInfo> apiInfos = javaApiInfoService.queryJavaApiInfo();
72 90
73 for (JavaApiInfo javaApiInfo : apiInfos) { 91 for (JavaApiInfo javaApiInfo : apiInfos) {
74 javaApimap.put(javaApiInfo.getApiName(), javaApiInfo); 92 javaApimap.put(javaApiInfo.getApiName(), javaApiInfo);
75 } 93 }
76 94
  95 + //获取云类型
  96 + HostInfoReq req = new HostInfoReq();
  97 + req.setPageSize(1000);
  98 + req.setCurrentPage(0);
  99 + PageResponse<HostInfo> hostInfos = hostInfoService.getHostInfos(req);
  100 + Map<String, Integer> ipCloudMap = new HashMap<String, Integer>();
  101 +
  102 + if (hostInfos.getTotal() > 0) {
  103 + for (HostInfo hostInfo : hostInfos.getRows()) {
  104 + ipCloudMap.put(hostInfo.getHostIp().trim(), hostInfo.getCloudType());
  105 + }
  106 + }
  107 +
  108 +
  109 + //获取部署java服务的服务对象
77 //TODO 需要删选java服务 110 //TODO 需要删选java服务
78 List<MObjectInfo> mObjectInfos = mObjectInfoService.queryMObjectsInfo(); 111 List<MObjectInfo> mObjectInfos = mObjectInfoService.queryMObjectsInfo();
79 112
80 for (MObjectInfo mObjInfo : mObjectInfos) { 113 for (MObjectInfo mObjInfo : mObjectInfos) {
81 - mObjInfoMap.add(mObjInfo.getMoTypeId(), mObjInfo); 114 + MObjectDetails mObjectDetails = new MObjectDetails();
  115 + BeanUtils.copyProperties(mObjInfo, mObjectDetails);
  116 +
  117 + if (ipCloudMap.containsKey(mObjInfo.getMoHostIp())) {
  118 + mObjectDetails.setCloudType(ipCloudMap.get(mObjInfo.getMoHostIp().trim()));
  119 + } else {
  120 + mObjectDetails.setCloudType(0);
  121 + }
  122 + mObjInfoMap.add(mObjInfo.getMoTypeId(), mObjectDetails);
82 } 123 }
83 124
84 } 125 }
@@ -89,12 +130,12 @@ public class JavaApiClient { @@ -89,12 +130,12 @@ public class JavaApiClient {
89 int tastNum = 0; 130 int tastNum = 0;
90 for (JavaApiInfo javaApiInfo : javaApimap.values()) { 131 for (JavaApiInfo javaApiInfo : javaApimap.values()) {
91 132
92 - List<MObjectInfo> mObjectInfos = mObjInfoMap.get(javaApiInfo.getServiceType()); 133 + List<MObjectDetails> mObjectInfos = mObjInfoMap.get(javaApiInfo.getServiceType());
93 if (mObjectInfos == null) { 134 if (mObjectInfos == null) {
94 log.warn("type {} has no service object", javaApiInfo.getServiceType()); 135 log.warn("type {} has no service object", javaApiInfo.getServiceType());
95 continue; 136 continue;
96 } 137 }
97 - for (MObjectInfo mObjectInfo : mObjectInfos) { 138 + for (MObjectDetails mObjectInfo : mObjectInfos) {
98 completionService.submit(new JavaApiTask(restTemplate, javaApiInfo, mObjectInfo)); 139 completionService.submit(new JavaApiTask(restTemplate, javaApiInfo, mObjectInfo));
99 tastNum++; 140 tastNum++;
100 } 141 }
@@ -135,9 +176,9 @@ public class JavaApiClient { @@ -135,9 +176,9 @@ public class JavaApiClient {
135 completionService = new ExecutorCompletionService<JavaApiStatics>(executorService); 176 completionService = new ExecutorCompletionService<JavaApiStatics>(executorService);
136 177
137 javaApimap = new ConcurrentHashMap<String, JavaApiInfo>(); 178 javaApimap = new ConcurrentHashMap<String, JavaApiInfo>();
138 - mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectInfo>(); 179 + mObjInfoMap = new LinkedMultiValueMap<Integer, MObjectDetails>();
139 180
140 - MObjectInfo mObj1 = new MObjectInfo(); 181 + MObjectDetails mObj1 = new MObjectDetails();
141 mObj1.setMoId(1); 182 mObj1.setMoId(1);
142 mObj1.setMoHostIp("192.168.102.205"); 183 mObj1.setMoHostIp("192.168.102.205");
143 mObj1.setMoTags("8080"); 184 mObj1.setMoTags("8080");
@@ -155,7 +196,7 @@ public class JavaApiClient { @@ -155,7 +196,7 @@ public class JavaApiClient {
155 // 196 //
156 // mObjInfoMap.add(1, mObj2); 197 // mObjInfoMap.add(1, mObj2);
157 198
158 - MObjectInfo mObj2 = new MObjectInfo(); 199 + MObjectDetails mObj2 = new MObjectDetails();
159 mObj2.setMoId(0); 200 mObj2.setMoId(0);
160 mObj2.setMoHostIp("localhost"); 201 mObj2.setMoHostIp("localhost");
161 mObj2.setMoTags("10080"); 202 mObj2.setMoTags("10080");
@@ -2,6 +2,7 @@ package com.monitor.javaserver.common; @@ -2,6 +2,7 @@ package com.monitor.javaserver.common;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.model.JavaApiInfo; 4 import com.model.JavaApiInfo;
  5 +import com.model.MObjectDetails;
5 import com.model.MObjectInfo; 6 import com.model.MObjectInfo;
6 import lombok.Data; 7 import lombok.Data;
7 import org.apache.commons.lang.builder.ReflectionToStringBuilder; 8 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
@@ -15,7 +16,7 @@ public class JavaApiStatics{ @@ -15,7 +16,7 @@ public class JavaApiStatics{
15 16
16 private JavaApiInfo javaApiInfo; 17 private JavaApiInfo javaApiInfo;
17 18
18 - private MObjectInfo mObjectInfo; 19 + private MObjectDetails mObjectDetails;
19 20
20 private long startTime; 21 private long startTime;
21 22
  1 +package com.monitor.javaserver.common;
  2 +
  3 +import com.monitor.model.response.JavaApiStaticsRep;
  4 +import com.monitor.model.response.JavaApiStatusRep;
  5 +import org.apache.commons.collections.map.MultiKeyMap;
  6 +import org.springframework.stereotype.Component;
  7 +
  8 +import java.util.ArrayList;
  9 +import java.util.Enumeration;
  10 +import java.util.List;
  11 +import java.util.concurrent.ConcurrentHashMap;
  12 +import java.util.concurrent.atomic.AtomicInteger;
  13 +import java.util.concurrent.atomic.AtomicLong;
  14 +
  15 +/**
  16 + * 记录当前java服务概况
  17 + * Created by fruwei on 2016/6/27.
  18 + */
  19 +@Component
  20 +public class JavaApiStatus {
  21 +
  22 + /**
  23 + * key: app_id
  24 + * val: error_num
  25 + */
  26 + private ConcurrentHashMap<String, AtomicInteger> mapStaticsErr = new ConcurrentHashMap<String, AtomicInteger>();
  27 + private ConcurrentHashMap<String, AtomicInteger> mapStaticsOk = new ConcurrentHashMap<String, AtomicInteger>();
  28 +
  29 + private ConcurrentHashMap<String, Long> mapUpdateTime = new ConcurrentHashMap<String, Long>();
  30 +
  31 + public void addError(int apiType, int cloud) {
  32 + String key = cloud + "_" + apiType;
  33 + mapStaticsErr.putIfAbsent(key, new AtomicInteger(0));
  34 + mapStaticsErr.get(key).getAndIncrement();
  35 +
  36 + }
  37 +
  38 +
  39 + public void addSuccess(int apiType, int cloud) {
  40 + String key = cloud + "_" + apiType;
  41 + mapStaticsOk.putIfAbsent(key, new AtomicInteger(0));
  42 + mapStaticsOk.get(key).getAndIncrement();
  43 + }
  44 +
  45 +
  46 + public void clear() {
  47 + mapStaticsErr.clear();
  48 + mapStaticsOk.clear();
  49 + }
  50 +
  51 +
  52 + public List<JavaApiStaticsRep> getStatusList() {
  53 +
  54 + List<JavaApiStaticsRep> rel = new ArrayList<JavaApiStaticsRep>();
  55 +
  56 + MultiKeyMap multiKeyMap = new MultiKeyMap();
  57 +
  58 +
  59 + Enumeration<String> errkeys = mapStaticsErr.keys();
  60 + while (errkeys.hasMoreElements()) {
  61 + String key = errkeys.nextElement();
  62 + JavaApiStaticsRep statics = new JavaApiStaticsRep();
  63 + String[] strKeys = key.split("_");
  64 + statics.setCloudType(Integer.parseInt(strKeys[0]));
  65 + statics.setServiceType(Integer.parseInt(strKeys[1]));
  66 +
  67 + statics.setErrNum(mapStaticsErr.getOrDefault(key, new AtomicInteger(0)).intValue());
  68 + multiKeyMap.put(statics.getServiceType(), statics.getServiceType(), statics);
  69 +
  70 + rel.add(statics);
  71 + }
  72 +
  73 +
  74 + Enumeration<String> okeys = mapStaticsOk.keys();
  75 + while (okeys.hasMoreElements()) {
  76 + String key = okeys.nextElement();
  77 + JavaApiStaticsRep statics = new JavaApiStaticsRep();
  78 + String[] strKeys = key.split("_");
  79 + statics.setCloudType(Integer.parseInt(strKeys[0]));
  80 + statics.setServiceType(Integer.parseInt(strKeys[1]));
  81 + if (multiKeyMap.containsKey(statics.getCloudType(), statics.getServiceType())) {
  82 + statics = (JavaApiStaticsRep) multiKeyMap.get(statics.getCloudType(), statics.getServiceType());
  83 + } else {
  84 + multiKeyMap.put(statics.getServiceType(), statics.getServiceType(), statics);
  85 + }
  86 + statics.setOkNum(mapStaticsOk.getOrDefault(key, new AtomicInteger(0)).intValue());
  87 + rel.add(statics);
  88 + }
  89 +
  90 + return rel;
  91 + }
  92 +
  93 +
  94 +}
@@ -3,6 +3,7 @@ package com.monitor.javaserver.common; @@ -3,6 +3,7 @@ package com.monitor.javaserver.common;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.model.JavaApiInfo; 5 import com.model.JavaApiInfo;
  6 +import com.model.MObjectDetails;
6 import com.model.MObjectInfo; 7 import com.model.MObjectInfo;
7 import org.slf4j.Logger; 8 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
@@ -18,12 +19,12 @@ public class JavaApiTask implements Callable<JavaApiStatics> { @@ -18,12 +19,12 @@ public class JavaApiTask implements Callable<JavaApiStatics> {
18 Logger log = LoggerFactory.getLogger(JavaApiTask.class); 19 Logger log = LoggerFactory.getLogger(JavaApiTask.class);
19 20
20 private JavaApiInfo javaApiInfo; 21 private JavaApiInfo javaApiInfo;
21 - private MObjectInfo mObjectInfo; 22 + private MObjectDetails mObjectInfo;
22 23
23 private RestTemplate restTemplate; 24 private RestTemplate restTemplate;
24 25
25 26
26 - public JavaApiTask(RestTemplate restTemplate, JavaApiInfo javaApiInfo, MObjectInfo mObjectInfo) { 27 + public JavaApiTask(RestTemplate restTemplate, JavaApiInfo javaApiInfo, MObjectDetails mObjectInfo) {
27 this.javaApiInfo = javaApiInfo; 28 this.javaApiInfo = javaApiInfo;
28 this.mObjectInfo = mObjectInfo; 29 this.mObjectInfo = mObjectInfo;
29 this.restTemplate = restTemplate; 30 this.restTemplate = restTemplate;
@@ -42,7 +43,7 @@ public class JavaApiTask implements Callable<JavaApiStatics> { @@ -42,7 +43,7 @@ public class JavaApiTask implements Callable<JavaApiStatics> {
42 apiStatics.setStartTime(System.currentTimeMillis()); 43 apiStatics.setStartTime(System.currentTimeMillis());
43 apiStatics.setHasException(false); 44 apiStatics.setHasException(false);
44 apiStatics.setJavaApiInfo(this.javaApiInfo); 45 apiStatics.setJavaApiInfo(this.javaApiInfo);
45 - apiStatics.setMObjectInfo(this.mObjectInfo); 46 + apiStatics.setMObjectDetails(this.mObjectInfo);
46 //TODO JSON解析异常 47 //TODO JSON解析异常
47 try { 48 try {
48 if (javaApiInfo.getApiReqMethod() == 0) { 49 if (javaApiInfo.getApiReqMethod() == 0) {
@@ -6,6 +6,7 @@ import com.monitor.model.page.PageResponse; @@ -6,6 +6,7 @@ import com.monitor.model.page.PageResponse;
6 import com.monitor.model.request.JavaApiHisReq; 6 import com.monitor.model.request.JavaApiHisReq;
7 import com.monitor.model.request.JavaApiStatusReq; 7 import com.monitor.model.request.JavaApiStatusReq;
8 import com.monitor.model.response.BaseResponse; 8 import com.monitor.model.response.BaseResponse;
  9 +import com.monitor.model.response.JavaApiStaticsRep;
9 import com.monitor.model.response.JavaApiStatusRep; 10 import com.monitor.model.response.JavaApiStatusRep;
10 import org.slf4j.Logger; 11 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
@@ -105,7 +106,7 @@ public class JavaAppInfoStaticsCtrl { @@ -105,7 +106,7 @@ public class JavaAppInfoStaticsCtrl {
105 } 106 }
106 107
107 if (req.getEndTime() == 0) 108 if (req.getEndTime() == 0)
108 - req.setEndTime( System.currentTimeMillis()); 109 + req.setEndTime(System.currentTimeMillis());
109 110
110 111
111 BaseResponse baseResponse = new BaseResponse(); 112 BaseResponse baseResponse = new BaseResponse();
@@ -130,4 +131,23 @@ public class JavaAppInfoStaticsCtrl { @@ -130,4 +131,23 @@ public class JavaAppInfoStaticsCtrl {
130 131
131 } 132 }
132 133
  134 + @RequestMapping("/queryAll")
  135 + @ResponseBody
  136 + public BaseResponse getAllJavaApiStatus() {
  137 +
  138 + BaseResponse baseResponse = new BaseResponse();
  139 + try {
  140 + List<JavaApiStaticsRep> staticsReps = javaApiStatusService.getAllJavaApiStatus();
  141 + baseResponse.setData(staticsReps);
  142 + } catch (Exception e) {
  143 + log.warn("query his failed req", e);
  144 + baseResponse.setCode(400);
  145 + baseResponse.setMessage(e.getMessage());
  146 + }
  147 +
  148 + return baseResponse;
  149 +
  150 + }
  151 +
  152 +
133 } 153 }
@@ -2,6 +2,7 @@ package com.monitor.javaserver.handle.impl; @@ -2,6 +2,7 @@ package com.monitor.javaserver.handle.impl;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.model.JavaApiInfo; 4 import com.model.JavaApiInfo;
  5 +import com.model.MObjectDetails;
5 import com.model.MObjectInfo; 6 import com.model.MObjectInfo;
6 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; 7 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
7 import com.monitor.javaserver.common.JavaApiStatics; 8 import com.monitor.javaserver.common.JavaApiStatics;
@@ -34,7 +35,7 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler { @@ -34,7 +35,7 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
34 jsonObject.put("api_type", javaApiInfo.getServiceType()); 35 jsonObject.put("api_type", javaApiInfo.getServiceType());
35 jsonObject.put("api_url", javaApiInfo.getApiUrl()); 36 jsonObject.put("api_url", javaApiInfo.getApiUrl());
36 37
37 - MObjectInfo mobjInfo = javaApiStatics.getMObjectInfo(); 38 + MObjectDetails mobjInfo = javaApiStatics.getMObjectDetails();
38 39
39 jsonObject.put("mobj_name", mobjInfo.getMoName()); 40 jsonObject.put("mobj_name", mobjInfo.getMoName());
40 jsonObject.put("mobj_ip", mobjInfo.getMoHostIp()); 41 jsonObject.put("mobj_ip", mobjInfo.getMoHostIp());
@@ -52,8 +53,8 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler { @@ -52,8 +53,8 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
52 jsonObject.put("exception", ExceptionUtils.getStackTrace(javaApiStatics.getException())); 53 jsonObject.put("exception", ExceptionUtils.getStackTrace(javaApiStatics.getException()));
53 54
54 } else { 55 } else {
55 - JSONObject rep = javaApiStatics.getResponse();  
56 - jsonObject.put("response", javaApiStatics.getResponse()); 56 +// JSONObject rep = javaApiStatics.getResponse();
  57 +// jsonObject.put("response", javaApiStatics.getResponse());
57 } 58 }
58 59
59 javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject); 60 javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject);
1 package com.monitor.javaserver.handle.impl; 1 package com.monitor.javaserver.handle.impl;
2 2
3 import com.model.JavaApiInfo; 3 import com.model.JavaApiInfo;
  4 +import com.model.MObjectDetails;
4 import com.model.MObjectInfo; 5 import com.model.MObjectInfo;
5 import com.monitor.common.config.SnsMobileConfig; 6 import com.monitor.common.config.SnsMobileConfig;
6 import com.monitor.common.service.AlarmMsgService; 7 import com.monitor.common.service.AlarmMsgService;
@@ -26,7 +27,9 @@ public class MsgJavaApiHandler implements IJavaApiHadnler { @@ -26,7 +27,9 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
26 public AlarmMsgService alarmMsgService; 27 public AlarmMsgService alarmMsgService;
27 @Autowired 28 @Autowired
28 private SnsMobileConfig snsMobileConfig; 29 private SnsMobileConfig snsMobileConfig;
29 - 30 + /**
  31 + * 应该不会出现并发情况
  32 + */
30 private ConcurrentHashMap<String, AtomicInteger> mapStatics = new ConcurrentHashMap<String, AtomicInteger>(); 33 private ConcurrentHashMap<String, AtomicInteger> mapStatics = new ConcurrentHashMap<String, AtomicInteger>();
31 34
32 35
@@ -42,13 +45,8 @@ public class MsgJavaApiHandler implements IJavaApiHadnler { @@ -42,13 +45,8 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
42 } 45 }
43 46
44 int num = 0; 47 int num = 0;
45 - if (mapStatics.containsKey(key)) {  
46 - AtomicInteger errNums = mapStatics.get(key);  
47 - num = errNums.incrementAndGet();  
48 - } else {  
49 - mapStatics.put(key, new AtomicInteger(1));  
50 - num = 1;  
51 - } 48 + mapStatics.putIfAbsent(key, new AtomicInteger(0));
  49 + num = mapStatics.get(key).incrementAndGet();
52 50
53 JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo(); 51 JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo();
54 if (javaApiInfo.getApiWarnTrigger() > 0 && 52 if (javaApiInfo.getApiWarnTrigger() > 0 &&
@@ -65,14 +63,14 @@ public class MsgJavaApiHandler implements IJavaApiHadnler { @@ -65,14 +63,14 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
65 63
66 public String buildKey(JavaApiStatics javaApiStatics) { 64 public String buildKey(JavaApiStatics javaApiStatics) {
67 String key; 65 String key;
68 - key = javaApiStatics.getJavaApiInfo().getServiceId() + "_" + javaApiStatics.getMObjectInfo().getMoId(); 66 + key = javaApiStatics.getJavaApiInfo().getServiceId() + "_" + javaApiStatics.getMObjectDetails().getMoId();
69 return key; 67 return key;
70 } 68 }
71 69
72 70
73 public String buildErrMsg(int num, JavaApiStatics javaApiStatics) { 71 public String buildErrMsg(int num, JavaApiStatics javaApiStatics) {
74 JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo(); 72 JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo();
75 - MObjectInfo mObjectInfo = javaApiStatics.getMObjectInfo(); 73 + MObjectDetails mObjectInfo = javaApiStatics.getMObjectDetails();
76 74
77 StringBuilder msgBuilder = new StringBuilder(); 75 StringBuilder msgBuilder = new StringBuilder();
78 msgBuilder.append("Java API Error ") 76 msgBuilder.append("Java API Error ")
  1 +package com.monitor.javaserver.handle.impl;
  2 +
  3 +import com.monitor.javaserver.common.JavaApiStatics;
  4 +import com.monitor.javaserver.common.JavaApiStatus;
  5 +import com.monitor.javaserver.handle.IJavaApiHadnler;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import java.util.concurrent.ConcurrentHashMap;
  10 +import java.util.concurrent.atomic.AtomicInteger;
  11 +
  12 +/**
  13 + * 统计信息处理
  14 + * Created by fruwei on 2016/6/27.
  15 + */
  16 +@Component
  17 +public class StaticsJavaApiHandler implements IJavaApiHadnler {
  18 +
  19 + @Autowired
  20 + JavaApiStatus javaApiStatus;
  21 +
  22 +
  23 + @Override
  24 + public void handler(JavaApiStatics javaApiStatics) {
  25 +
  26 + if(javaApiStatics.getJavaApiInfo().getApiToggle()==0){
  27 + return;
  28 + }
  29 + if (javaApiStatics.isHasException()) {
  30 + javaApiStatus.addError(javaApiStatics.getJavaApiInfo().getServiceType(), javaApiStatics.getMObjectDetails().getCloudType());
  31 + } else {
  32 + javaApiStatus.addSuccess(javaApiStatics.getJavaApiInfo().getServiceType(), javaApiStatics.getMObjectDetails().getCloudType());
  33 + }
  34 +
  35 + }
  36 +
  37 +
  38 +}
@@ -2,6 +2,7 @@ package com.monitor.javaserver.service; @@ -2,6 +2,7 @@ package com.monitor.javaserver.service;
2 2
3 import com.monitor.model.request.JavaApiHisReq; 3 import com.monitor.model.request.JavaApiHisReq;
4 import com.monitor.model.request.JavaApiStatusReq; 4 import com.monitor.model.request.JavaApiStatusReq;
  5 +import com.monitor.model.response.JavaApiStaticsRep;
5 import com.monitor.model.response.JavaApiStatusRep; 6 import com.monitor.model.response.JavaApiStatusRep;
6 7
7 import java.util.List; 8 import java.util.List;
@@ -22,5 +23,7 @@ public interface IJavaApiStatusService { @@ -22,5 +23,7 @@ public interface IJavaApiStatusService {
22 23
23 public int countJavaApiStatusHisByTime(JavaApiHisReq req); 24 public int countJavaApiStatusHisByTime(JavaApiHisReq req);
24 25
  26 + public List<JavaApiStaticsRep> getAllJavaApiStatus();
  27 +
25 28
26 } 29 }
@@ -3,10 +3,12 @@ package com.monitor.javaserver.service.impl; @@ -3,10 +3,12 @@ package com.monitor.javaserver.service.impl;
3 import com.monitor.common.contants.PaginationContants; 3 import com.monitor.common.contants.PaginationContants;
4 import com.monitor.common.util.DateFormatUtil; 4 import com.monitor.common.util.DateFormatUtil;
5 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; 5 import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
  6 +import com.monitor.javaserver.common.JavaApiStatus;
6 import com.monitor.javaserver.service.IJavaApiStatusService; 7 import com.monitor.javaserver.service.IJavaApiStatusService;
7 import com.monitor.model.domain.JavaApiStaticsModel; 8 import com.monitor.model.domain.JavaApiStaticsModel;
8 import com.monitor.model.request.JavaApiHisReq; 9 import com.monitor.model.request.JavaApiHisReq;
9 import com.monitor.model.request.JavaApiStatusReq; 10 import com.monitor.model.request.JavaApiStatusReq;
  11 +import com.monitor.model.response.JavaApiStaticsRep;
10 import com.monitor.model.response.JavaApiStatusRep; 12 import com.monitor.model.response.JavaApiStatusRep;
11 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Component; 14 import org.springframework.stereotype.Component;
@@ -24,6 +26,10 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { @@ -24,6 +26,10 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
24 @Autowired 26 @Autowired
25 JavaApiStaticsMapper javaApiStaticsMapper; 27 JavaApiStaticsMapper javaApiStaticsMapper;
26 28
  29 + @Autowired
  30 + JavaApiStatus javaApiStatus;
  31 +
  32 +
27 @Override 33 @Override
28 public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req) { 34 public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req) {
29 JavaApiStatusRep rep = new JavaApiStatusRep(); 35 JavaApiStatusRep rep = new JavaApiStatusRep();
@@ -82,7 +88,7 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { @@ -82,7 +88,7 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
82 long start = System.currentTimeMillis(); 88 long start = System.currentTimeMillis();
83 long end = start; 89 long end = start;
84 start = start - 1000 * 60 * 60; //一小时之内 90 start = start - 1000 * 60 * 60; //一小时之内
85 - JavaApiHisReq req=new JavaApiHisReq(); 91 + JavaApiHisReq req = new JavaApiHisReq();
86 req.setPageSize(10); 92 req.setPageSize(10);
87 req.setApiId(api_id); 93 req.setApiId(api_id);
88 req.setMobjId(mobj_id); 94 req.setMobjId(mobj_id);
@@ -131,5 +137,12 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { @@ -131,5 +137,12 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
131 return count; 137 return count;
132 } 138 }
133 139
  140 + @Override
  141 + public List<JavaApiStaticsRep> getAllJavaApiStatus() {
  142 +
  143 + return javaApiStatus.getStatusList();
  144 +
  145 + }
  146 +
134 147
135 } 148 }
  1 +package com.monitor.model.response;
  2 +
  3 +import lombok.Data;
  4 +
  5 +/**
  6 + * Created by fruwei on 2016/6/27.
  7 + */
  8 +@Data
  9 +public class JavaApiStaticsRep {
  10 +
  11 +
  12 + private int serviceType;
  13 +
  14 + private int cloudType;
  15 +
  16 + private int errNum;
  17 +
  18 + private int okNum;
  19 +
  20 + private String updateTime;
  21 +
  22 +}
  1 +package com.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.io.Serializable;
  6 +
  7 +/**
  8 + * Created by yoho on 2016/6/14.
  9 + */
  10 +@Data
  11 +public class MObjectDetails implements Serializable {
  12 + private int moId = 0;
  13 +
  14 + private String moName;
  15 +
  16 + private String moHostIp;
  17 +
  18 + private int moTypeId;
  19 +
  20 + private String moTags;
  21 +
  22 + private String moUrl;
  23 +
  24 + private int cloudType;
  25 +
  26 +}
@@ -50,5 +50,4 @@ @@ -50,5 +50,4 @@
50 ORDER BY id asc 50 ORDER BY id asc
51 </select> 51 </select>
52 52
53 -  
54 </mapper> 53 </mapper>