Merge branch 'master' of http://git.yoho.cn/ops/monitor-service
# Conflicts: # monitor-service-influxdb/src/main/java/com/monitor/influxdb/mapper/impl/RedisMapper.java # monitor-service-middleware/src/main/java/com/monitor/middleware/redis/service/impl/RedisMonitorServiceImpl.java
Showing
18 changed files
with
136 additions
and
257 deletions
1 | -package com.monitor.cmdb.ctrl; | ||
2 | - | ||
3 | -import org.slf4j.Logger; | ||
4 | -import org.slf4j.LoggerFactory; | ||
5 | -import org.springframework.beans.factory.annotation.Autowired; | ||
6 | -import org.springframework.stereotype.Controller; | ||
7 | -import org.springframework.util.CollectionUtils; | ||
8 | -import org.springframework.web.bind.annotation.RequestBody; | ||
9 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
10 | -import org.springframework.web.bind.annotation.ResponseBody; | ||
11 | - | ||
12 | -import com.monitor.cmdb.service.IRedisInfoService; | ||
13 | -import com.monitor.model.request.RedisInfoReq; | ||
14 | -import com.monitor.model.response.BaseResponse; | ||
15 | -import com.monitor.model.response.PageResponse; | ||
16 | - | ||
17 | -@Controller | ||
18 | -@RequestMapping("redisMonitor") | ||
19 | -public class RedisInfoCtrl { | ||
20 | - | ||
21 | - Logger log = LoggerFactory.getLogger(RedisInfoCtrl.class); | ||
22 | - | ||
23 | - @Autowired | ||
24 | - private IRedisInfoService redisInfoService; | ||
25 | - | ||
26 | - @RequestMapping("/getRedisInfo") | ||
27 | - @ResponseBody | ||
28 | - public BaseResponse<PageResponse<Object>> getRedisInfo(@RequestBody RedisInfoReq req){ | ||
29 | - log.info("getRedisInfo with param is {}",req); | ||
30 | - | ||
31 | - // 查询列表 | ||
32 | - PageResponse<Object> responseBO = redisInfoService.getRedisInfo(req); | ||
33 | - if (responseBO == null || CollectionUtils.isEmpty(responseBO.getRows())) { | ||
34 | - return null; | ||
35 | - } | ||
36 | - PageResponse<Object> response = new PageResponse<Object>(); | ||
37 | - response.setCurrentPage(responseBO.getCurrentPage()); | ||
38 | - response.setRows(responseBO.getRows()); | ||
39 | - response.setPageSize(responseBO.getPageSize()); | ||
40 | - response.setTotal(responseBO.getTotal()); | ||
41 | - log.info("getRedisInfo success and total={}", response.getTotal()); | ||
42 | - return new BaseResponse<PageResponse<Object>>(response); | ||
43 | - | ||
44 | - } | ||
45 | -} |
monitor-service-cmdb/src/main/java/com/monitor/cmdb/service/impl/RedisServiceImpl.java
deleted
100644 → 0
1 | -package com.monitor.cmdb.service.impl; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | - | ||
5 | -import org.slf4j.Logger; | ||
6 | -import org.slf4j.LoggerFactory; | ||
7 | -import org.springframework.beans.factory.annotation.Autowired; | ||
8 | -import org.springframework.stereotype.Service; | ||
9 | - | ||
10 | -import com.monitor.cmdb.service.IRedisInfoService; | ||
11 | -import com.monitor.influxdb.mapper.IRedisMapper; | ||
12 | -import com.monitor.model.domain.PageBean; | ||
13 | -import com.monitor.model.request.RedisInfoReq; | ||
14 | -import com.monitor.model.response.PageResponse; | ||
15 | - | ||
16 | -@Service | ||
17 | -public class RedisServiceImpl implements IRedisInfoService { | ||
18 | - | ||
19 | - Logger log = LoggerFactory.getLogger(RedisServiceImpl.class); | ||
20 | - | ||
21 | - @Autowired | ||
22 | - IRedisMapper redisMapper; | ||
23 | - | ||
24 | - @Override | ||
25 | - public PageResponse<Object> getRedisInfo(RedisInfoReq req) { | ||
26 | - | ||
27 | - log.debug("getRedisInfo with param is {}",req); | ||
28 | - | ||
29 | - PageBean page = PageBean.initPageInfo(req.getCurrentPage(),req.getPageSize(), req); | ||
30 | - // 先查询符合条件的总数量 | ||
31 | - int total = redisMapper.selectCountByCodition(page); | ||
32 | - log.info("selectUserTotal num is {}, with param is {}", total, | ||
33 | - req); | ||
34 | - // 数量为0 直接返回 | ||
35 | - if (total == 0) { | ||
36 | - // 返回初始page对象 | ||
37 | - return null; | ||
38 | - } | ||
39 | - // 获取列表 | ||
40 | - List<?> redis = redisMapper.selectRedisInfosByCodition(page); | ||
41 | - if (redis==null) { | ||
42 | - log.debug("selectRedisInfosByCodition is null with param is {}", page); | ||
43 | - return null; | ||
44 | - } | ||
45 | - PageResponse<Object> response = new PageResponse<Object>(); | ||
46 | - response.setCurrentPage(req.getCurrentPage()); | ||
47 | - response.setPageSize(req.getPageSize()); | ||
48 | - response.setTotal(total); | ||
49 | - response.setRows((List<Object>) redis); | ||
50 | - return response; | ||
51 | - } | ||
52 | - | ||
53 | -} |
monitor-service-influxdb/src/main/java/com/monitor/influxdb/mapper/IRedisMapper.java
deleted
100644 → 0
1 | -package com.monitor.influxdb.mapper; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | - | ||
5 | -import com.monitor.influxdb.model.RedisInfo; | ||
6 | -import com.monitor.model.domain.PageBean; | ||
7 | - | ||
8 | -public interface IRedisMapper { | ||
9 | - | ||
10 | - void insert(RedisInfo redis); | ||
11 | - | ||
12 | - int selectCountByCodition(PageBean page); | ||
13 | - | ||
14 | - List<?> selectRedisInfosByCodition(PageBean page); | ||
15 | - | ||
16 | -} |
@@ -58,8 +58,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -58,8 +58,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
58 | .addField("mobj_ip", statics.getString("mobj_ip")) | 58 | .addField("mobj_ip", statics.getString("mobj_ip")) |
59 | .addField("mobj_id", statics.getIntValue("mobj_id")) | 59 | .addField("mobj_id", statics.getIntValue("mobj_id")) |
60 | .addField("mobj_port", statics.getString("mobj_port")) | 60 | .addField("mobj_port", statics.getString("mobj_port")) |
61 | - .addField("start", statics.getLongValue("start")) | ||
62 | - .addField("end", statics.getLongValue("end")) | 61 | + .addField("start_time", statics.getLongValue("start")) |
62 | + .addField("end_time", statics.getLongValue("end")) | ||
63 | .addField("is_exception", statics.getBooleanValue("is_exception")) | 63 | .addField("is_exception", statics.getBooleanValue("is_exception")) |
64 | .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS); | 64 | .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS); |
65 | 65 | ||
@@ -101,8 +101,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -101,8 +101,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
101 | QueryResult.Series series = rel.getSeries().get(0); | 101 | QueryResult.Series series = rel.getSeries().get(0); |
102 | 102 | ||
103 | Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception")); | 103 | Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception")); |
104 | - long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start"))); | ||
105 | - long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end"))); | 104 | + long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start_time"))); |
105 | + long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end_time"))); | ||
106 | long costTime = (endTime - startTime); | 106 | long costTime = (endTime - startTime); |
107 | 107 | ||
108 | String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception")); | 108 | String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception")); |
@@ -119,24 +119,75 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -119,24 +119,75 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
119 | javaApiStaticsModel.setStatus(1); | 119 | javaApiStaticsModel.setStatus(1); |
120 | 120 | ||
121 | } catch (Exception e) { | 121 | } catch (Exception e) { |
122 | - e.printStackTrace(); | 122 | + log.warn("select latest java api info failed ", e); |
123 | } | 123 | } |
124 | return javaApiStaticsModel; | 124 | return javaApiStaticsModel; |
125 | 125 | ||
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | + /** | ||
130 | + * 批量查询 | ||
131 | + * | ||
132 | + * @param influxDBName | ||
133 | + * @param paramList | ||
134 | + * @return | ||
135 | + */ | ||
129 | @Override | 136 | @Override |
130 | public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) { | 137 | public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) { |
131 | 138 | ||
132 | - //TODO 后期改批量查询 | 139 | + List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>(); |
140 | + StringBuilder sb = new StringBuilder(); | ||
141 | + for (JavaApiStatusReq param : paramList) { | ||
142 | + int api_id = param.getServiceId(); | ||
143 | + int mobj_id = param.getMObjectId(); | ||
144 | + sb.append("select api_id,mobj_id,start_time,end_time,is_exception,exception from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 1h "); | ||
145 | + sb.append(" and api_id=" + api_id); | ||
146 | + sb.append(" and mobj_id=" + mobj_id); | ||
147 | + sb.append(" order by time desc limit 1;"); | ||
148 | + } | ||
149 | + Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM); | ||
133 | 150 | ||
134 | - List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<>(); | 151 | + QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query); |
135 | 152 | ||
136 | - for (JavaApiStatusReq param : paramList) { | ||
137 | - JavaApiStaticsModel model = selectlatestJavaApiStatics(influxDBName, param); | ||
138 | - javaApiStaticsModels.add(model); | 153 | + for (QueryResult.Result queryResult : result.getResults()) { |
154 | + if (queryResult.getSeries() == null) | ||
155 | + continue; | ||
156 | + try { | ||
157 | + QueryResult.Series series = queryResult.getSeries().get(0); | ||
158 | + | ||
159 | + Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception")); | ||
160 | + long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start_time"))); | ||
161 | + long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end_time"))); | ||
162 | + long costTime = (endTime - startTime); | ||
163 | + | ||
164 | + int api_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue(); | ||
165 | + int mobj_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("mobj_id"))).intValue(); | ||
166 | + | ||
167 | + String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception")); | ||
168 | + | ||
169 | + JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel(); | ||
170 | + javaApiStaticsModel.setServiceId(api_id); | ||
171 | + javaApiStaticsModel.setMObjectId(mobj_id); | ||
172 | + javaApiStaticsModel.setStatus(0); | ||
173 | + | ||
174 | + javaApiStaticsModel.setStartTime(DateFormatUtil.parseLongToTimeStr(startTime)); | ||
175 | + javaApiStaticsModel.setEndTime(DateFormatUtil.parseLongToTimeStr(endTime)); | ||
176 | + | ||
177 | + javaApiStaticsModel.setCostTime((int) costTime); | ||
178 | + | ||
179 | + if (is_exception == true) { | ||
180 | + javaApiStaticsModel.setStatus(0); | ||
181 | + javaApiStaticsModel.setException(exception); | ||
182 | + } else | ||
183 | + javaApiStaticsModel.setStatus(1); | ||
184 | + | ||
185 | + javaApiStaticsModels.add(javaApiStaticsModel); | ||
186 | + } catch (Exception e) { | ||
187 | + log.warn("batch select latest java api info failed ", e); | ||
139 | } | 188 | } |
189 | + } | ||
190 | + | ||
140 | 191 | ||
141 | return javaApiStaticsModels; | 192 | return javaApiStaticsModels; |
142 | } | 193 | } |
@@ -189,8 +240,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -189,8 +240,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
189 | for (int i = 0; i < size; i++) { | 240 | for (int i = 0; i < size; i++) { |
190 | JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel(); | 241 | JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel(); |
191 | Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception")); | 242 | Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception")); |
192 | - long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start"))); | ||
193 | - long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end"))); | 243 | + long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start_time"))); |
244 | + long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end_time"))); | ||
194 | long costTime = (endTime - startTime); | 245 | long costTime = (endTime - startTime); |
195 | 246 | ||
196 | 247 |
1 | package com.monitor.influxdb.mapper.impl; | 1 | package com.monitor.influxdb.mapper.impl; |
2 | 2 | ||
3 | +import java.util.List; | ||
4 | +import java.util.Random; | ||
5 | +import java.util.concurrent.TimeUnit; | ||
6 | + | ||
7 | +import org.apache.commons.lang.StringUtils; | ||
8 | +import org.influxdb.dto.Point; | ||
9 | +import org.influxdb.dto.QueryResult; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import org.springframework.stereotype.Component; | ||
12 | + | ||
3 | import com.monitor.common.contants.InfluxDBContants; | 13 | import com.monitor.common.contants.InfluxDBContants; |
4 | import com.monitor.common.util.QueryResultUtil; | 14 | import com.monitor.common.util.QueryResultUtil; |
5 | import com.monitor.influxdb.InfluxDBModel; | 15 | import com.monitor.influxdb.InfluxDBModel; |
@@ -8,15 +18,6 @@ import com.monitor.influxdb.InluxDBSingle; | @@ -8,15 +18,6 @@ import com.monitor.influxdb.InluxDBSingle; | ||
8 | import com.monitor.influxdb.mapper.IRedisMapper; | 18 | import com.monitor.influxdb.mapper.IRedisMapper; |
9 | import com.monitor.influxdb.model.RedisInfo; | 19 | import com.monitor.influxdb.model.RedisInfo; |
10 | import com.monitor.model.domain.PageBean; | 20 | import com.monitor.model.domain.PageBean; |
11 | -import org.apache.commons.lang.StringUtils; | ||
12 | -import org.influxdb.dto.Point; | ||
13 | -import org.influxdb.dto.QueryResult; | ||
14 | -import org.springframework.beans.factory.annotation.Autowired; | ||
15 | -import org.springframework.stereotype.Component; | ||
16 | - | ||
17 | -import java.util.List; | ||
18 | -import java.util.Random; | ||
19 | -import java.util.concurrent.TimeUnit; | ||
20 | 21 | ||
21 | @Component | 22 | @Component |
22 | public class RedisMapper extends InfluxDBQuery implements IRedisMapper { | 23 | public class RedisMapper extends InfluxDBQuery implements IRedisMapper { |
@@ -35,7 +36,7 @@ public class RedisMapper extends InfluxDBQuery implements IRedisMapper { | @@ -35,7 +36,7 @@ public class RedisMapper extends InfluxDBQuery implements IRedisMapper { | ||
35 | .addField("role", redis.getRole()) | 36 | .addField("role", redis.getRole()) |
36 | .addField("connected_clients", redis.getConnected_clients()) | 37 | .addField("connected_clients", redis.getConnected_clients()) |
37 | .addField("is_slave", redis.getIs_slave()) | 38 | .addField("is_slave", redis.getIs_slave()) |
38 | - // .addField("used_memory_peak_human", redis.getUsed_memory_peak_human()) | 39 | +// .addField("used_memory_peak_human", redis.getUsed_memory_peak_human()) |
39 | .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS) | 40 | .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS) |
40 | .build(); | 41 | .build(); |
41 | inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB() | 42 | inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB() |
1 | -package com.monitor.influxdb.model; | ||
2 | - | ||
3 | -import lombok.Data; | ||
4 | - | ||
5 | -@Data | ||
6 | -public class RedisInfo { | ||
7 | - | ||
8 | - private String hostIp; | ||
9 | - | ||
10 | - private String connected_clients;//连接客户端数量 | ||
11 | - | ||
12 | - private int is_slave; | ||
13 | - | ||
14 | - private int is_run; | ||
15 | - | ||
16 | - private String role;//实例角色 | ||
17 | - | ||
18 | - public RedisInfo(String hostIp, String connected_clients, | ||
19 | - int is_slave, int is_run, String role) { | ||
20 | - super(); | ||
21 | - this.hostIp = hostIp; | ||
22 | - this.connected_clients = connected_clients; | ||
23 | - this.is_slave = is_slave; | ||
24 | - this.is_run = is_run; | ||
25 | - this.role = role; | ||
26 | - } | ||
27 | - | ||
28 | -} |
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory; | @@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory; | ||
20 | import org.springframework.beans.BeanUtils; | 20 | import org.springframework.beans.BeanUtils; |
21 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
22 | import org.springframework.beans.factory.annotation.Qualifier; | 22 | import org.springframework.beans.factory.annotation.Qualifier; |
23 | +import org.springframework.beans.factory.annotation.Value; | ||
23 | import org.springframework.stereotype.Component; | 24 | import org.springframework.stereotype.Component; |
24 | import org.springframework.util.LinkedMultiValueMap; | 25 | import org.springframework.util.LinkedMultiValueMap; |
25 | import org.springframework.util.MultiValueMap; | 26 | import org.springframework.util.MultiValueMap; |
@@ -62,6 +63,13 @@ public class JavaApiClient { | @@ -62,6 +63,13 @@ public class JavaApiClient { | ||
62 | JavaApiStatus javaApiStatus; | 63 | JavaApiStatus javaApiStatus; |
63 | 64 | ||
64 | 65 | ||
66 | + @Value("${JavaApiExecutorPoolCoreSize:20}") | ||
67 | + private int JavaApiExecutorPoolCoreSize; | ||
68 | + | ||
69 | + @Value("${JavaApiExecutorPoolMaxSize:50}") | ||
70 | + private int JavaApiExecutorPoolMaxSize; | ||
71 | + | ||
72 | + | ||
65 | //TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成 | 73 | //TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成 |
66 | private Map<String, JavaApiInfo> javaApimap; | 74 | private Map<String, JavaApiInfo> javaApimap; |
67 | 75 | ||
@@ -73,7 +81,8 @@ public class JavaApiClient { | @@ -73,7 +81,8 @@ public class JavaApiClient { | ||
73 | 81 | ||
74 | 82 | ||
75 | public void initClient() { | 83 | public void initClient() { |
76 | - executorService = new ThreadPoolExecutor(10, 30, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), | 84 | + executorService = new ThreadPoolExecutor(JavaApiExecutorPoolCoreSize, JavaApiExecutorPoolMaxSize, |
85 | + 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), | ||
77 | new JavaApiThreadFactory()); | 86 | new JavaApiThreadFactory()); |
78 | 87 | ||
79 | completionService = new ExecutorCompletionService<JavaApiStatics>(executorService); | 88 | completionService = new ExecutorCompletionService<JavaApiStatics>(executorService); |
@@ -163,7 +172,7 @@ public class JavaApiClient { | @@ -163,7 +172,7 @@ public class JavaApiClient { | ||
163 | public void handleResult(JavaApiStatics rep) { | 172 | public void handleResult(JavaApiStatics rep) { |
164 | 173 | ||
165 | 174 | ||
166 | - //TODO 加开关 控制gateway的检测条件 | 175 | + //TODO 后期可以加开关 控制gateway的检测条件 |
167 | //先做预处理,主要对返回结果格式为{code:200,message:".."}的响应做处理,对code非200的设置异常标志 | 176 | //先做预处理,主要对返回结果格式为{code:200,message:".."}的响应做处理,对code非200的设置异常标志 |
168 | for (IJavaApiHadnler javaApiHadnler : javaApiHadnlerList) { | 177 | for (IJavaApiHadnler javaApiHadnler : javaApiHadnlerList) { |
169 | if (javaApiHadnler instanceof PreProcessJavaApiHandler) { | 178 | if (javaApiHadnler instanceof PreProcessJavaApiHandler) { |
@@ -75,7 +75,7 @@ public class JavaApiStatus { | @@ -75,7 +75,7 @@ public class JavaApiStatus { | ||
75 | statics.setServiceType(Integer.parseInt(strKeys[1])); | 75 | statics.setServiceType(Integer.parseInt(strKeys[1])); |
76 | 76 | ||
77 | statics.setErrNum(mapStaticsErr.getOrDefault(key, new AtomicInteger(0)).intValue()); | 77 | statics.setErrNum(mapStaticsErr.getOrDefault(key, new AtomicInteger(0)).intValue()); |
78 | - multiKeyMap.put(statics.getServiceType(), statics.getServiceType(), statics); | 78 | + multiKeyMap.put(statics.getCloudType(), statics.getServiceType(), statics); |
79 | 79 | ||
80 | rel.add(statics); | 80 | rel.add(statics); |
81 | } | 81 | } |
@@ -44,13 +44,15 @@ public class JavaApiTask implements Callable<JavaApiStatics> { | @@ -44,13 +44,15 @@ public class JavaApiTask implements Callable<JavaApiStatics> { | ||
44 | apiStatics.setHasException(false); | 44 | apiStatics.setHasException(false); |
45 | apiStatics.setJavaApiInfo(this.javaApiInfo); | 45 | apiStatics.setJavaApiInfo(this.javaApiInfo); |
46 | apiStatics.setMObjectDetails(this.mObjectInfo); | 46 | apiStatics.setMObjectDetails(this.mObjectInfo); |
47 | + | ||
47 | //TODO JSON解析异常 | 48 | //TODO JSON解析异常 |
48 | try { | 49 | try { |
50 | + JSONObject req = null; | ||
51 | + if (javaApiInfo.getApiData() != null && !(javaApiInfo.getApiData().equals(""))) | ||
52 | + req = JSON.parseObject(javaApiInfo.getApiData()); | ||
49 | if (javaApiInfo.getApiReqMethod() == 0) { | 53 | if (javaApiInfo.getApiReqMethod() == 0) { |
50 | - JSONObject req = JSON.parseObject(javaApiInfo.getApiData()); | ||
51 | jsonRep = restTemplate.getForObject(url, JSONObject.class); | 54 | jsonRep = restTemplate.getForObject(url, JSONObject.class); |
52 | } else { | 55 | } else { |
53 | - JSONObject req = JSON.parseObject(javaApiInfo.getApiData()); | ||
54 | jsonRep = restTemplate.postForObject(url, req, JSONObject.class); | 56 | jsonRep = restTemplate.postForObject(url, req, JSONObject.class); |
55 | 57 | ||
56 | } | 58 | } |
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | 6 | ||
7 | <bean id="javaapi_ConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager"> | 7 | <bean id="javaapi_ConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager"> |
8 | <property name="maxTotal" value="40" /> | 8 | <property name="maxTotal" value="40" /> |
9 | - <property name="defaultMaxPerRoute" value="5" /> | 9 | + <property name="defaultMaxPerRoute" value="10" /> |
10 | </bean> | 10 | </bean> |
11 | 11 | ||
12 | <bean id="javaapi_httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder" | 12 | <bean id="javaapi_httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder" |
@@ -21,8 +21,8 @@ | @@ -21,8 +21,8 @@ | ||
21 | <bean id="javaapi_clientHttpRequestFactory" | 21 | <bean id="javaapi_clientHttpRequestFactory" |
22 | class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"> | 22 | class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"> |
23 | <constructor-arg ref="javaapi_httpClient" /> | 23 | <constructor-arg ref="javaapi_httpClient" /> |
24 | - <property name="connectTimeout" value="2000" /> | ||
25 | - <property name="readTimeout" value="2000" /> | 24 | + <property name="connectTimeout" value="800" /> |
25 | + <property name="readTimeout" value="1200" /> | ||
26 | </bean> | 26 | </bean> |
27 | 27 | ||
28 | <bean id="javaapiRestTemplate" class="org.springframework.web.client.RestTemplate"> | 28 | <bean id="javaapiRestTemplate" class="org.springframework.web.client.RestTemplate"> |
1 | package com.monitor.middleware.redis.service.impl; | 1 | package com.monitor.middleware.redis.service.impl; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.JSONObject; | ||
4 | -import com.monitor.common.util.HttpRestClient; | ||
5 | -import com.monitor.common.util.SSHRedis; | ||
6 | -import com.monitor.influxdb.mapper.IRedisMapper; | ||
7 | -import com.monitor.influxdb.model.RedisInfo; | ||
8 | -import com.monitor.middleware.redis.service.IRedisMonitorService; | ||
9 | -import com.monitor.mysql.mapper.RedisMonitorMapper; | ||
10 | import org.apache.commons.lang.StringUtils; | 3 | import org.apache.commons.lang.StringUtils; |
11 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
12 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
13 | -import org.springframework.beans.factory.annotation.Autowired; | ||
14 | import org.springframework.stereotype.Service; | 6 | import org.springframework.stereotype.Service; |
15 | -import org.springframework.util.CollectionUtils; | ||
16 | - | ||
17 | -import java.util.List; | 7 | +import com.monitor.common.util.SSHRedis; |
8 | +import com.monitor.middleware.redis.service.IRedisMonitorService; | ||
18 | 9 | ||
19 | @Service | 10 | @Service |
20 | public class RedisMonitorServiceImpl implements IRedisMonitorService { | 11 | public class RedisMonitorServiceImpl implements IRedisMonitorService { |
21 | 12 | ||
22 | Logger log = LoggerFactory.getLogger(RedisMonitorServiceImpl.class); | 13 | Logger log = LoggerFactory.getLogger(RedisMonitorServiceImpl.class); |
23 | 14 | ||
24 | - @Autowired | ||
25 | - IRedisMapper redisMapper; | ||
26 | - | ||
27 | - @Autowired | ||
28 | - RedisMonitorMapper redisMonitorMapper; | ||
29 | - | ||
30 | - @Autowired | ||
31 | - HttpRestClient httpRestClient; | ||
32 | - | ||
33 | @Override | 15 | @Override |
34 | public void redisMonitor() { | 16 | public void redisMonitor() { |
35 | 17 | ||
36 | - /********************************************************************** | ||
37 | - *1、处理twemproxy | ||
38 | - ***********************************************************************/ | ||
39 | - List<com.model.RedisInfo> proxyList=redisMonitorMapper.selectRedisMonitorByLevel(1); | ||
40 | - if(CollectionUtils.isEmpty(proxyList)){ | ||
41 | - return; | ||
42 | - } | ||
43 | - StringBuffer paramMonitor=null; | ||
44 | - for(com.model.RedisInfo obj:proxyList){ | ||
45 | - paramMonitor=new StringBuffer(); | ||
46 | - //JSONObject response=httpRestClient.defaultPost(obj.getHostIp()+obj.getParamMonitor(), null, JSONObject.class); | ||
47 | - JSONObject response=httpRestClient.defaultPost("http://192.168.102.222:22222", null, JSONObject.class); | ||
48 | - if(null != response){ | ||
49 | - int total_connections=(Integer)response.get("total_connections"); | ||
50 | - int curr_connections=(Integer)response.get("curr_connections"); | ||
51 | - if(total_connections>0){ | ||
52 | - paramMonitor.append("总连接数:"+total_connections); | ||
53 | - } | ||
54 | - if (total_connections > 0) { | ||
55 | - paramMonitor.append("当前接数:"+curr_connections); | ||
56 | - } | ||
57 | - } | ||
58 | - obj.setParamMonitor(paramMonitor.toString()); | ||
59 | - redisMonitorMapper.updateByPrimaryKey(obj); | ||
60 | - } | 18 | + //TODO |
19 | + //1、getallredis 分配给redis的总内存通过”config get maxmemory“取出然后算出占用百分比,需要用进度条展示(领导要求) | ||
20 | + //2、level=2 twemproxy取这个值,update更新需要取的值: "curr_connections":2,"client_eof":1959, "requests":2423810, "request_bytes":487387692, "responses":2423810, "response_bytes":20334901 | ||
21 | + //3、遍历level=3 | ||
61 | 22 | ||
62 | - /********************************************************************** | ||
63 | - *2、处理Redis | ||
64 | - ***********************************************************************/ | ||
65 | - List<com.model.RedisInfo> redisList=redisMonitorMapper.selectRedisMonitorByLevel(2); | ||
66 | 23 | ||
67 | - | ||
68 | - | ||
69 | - int isSlave=0; | ||
70 | - int isRun=0; | 24 | + StringBuffer buff = new StringBuffer(); |
25 | + String isSlave=""; | ||
71 | String redisInfo = SSHRedis.exec("192.168.102.162", "root", "123456", 22,"sleep 20;cd /usr/bin;redis-cli -h 192.168.102.222 -p 6379 info;"); | 26 | String redisInfo = SSHRedis.exec("192.168.102.162", "root", "123456", 22,"sleep 20;cd /usr/bin;redis-cli -h 192.168.102.222 -p 6379 info;"); |
27 | + | ||
72 | //检验主从同步 | 28 | //检验主从同步 |
73 | SSHRedis.exec("192.168.102.162", "root", "123456", 22,"sleep 20;cd /usr/bin;redis-cli -h 192.168.102.222 -p 6379 set test_key 'test';"); | 29 | SSHRedis.exec("192.168.102.162", "root", "123456", 22,"sleep 20;cd /usr/bin;redis-cli -h 192.168.102.222 -p 6379 set test_key 'test';"); |
74 | String redisInfo2 = SSHRedis.exec("192.168.102.162", "root", "123456", 22,"sleep 20;cd /usr/bin;redis-cli -h 192.168.102.222 -p 6379 get test_key;"); | 30 | String redisInfo2 = SSHRedis.exec("192.168.102.162", "root", "123456", 22,"sleep 20;cd /usr/bin;redis-cli -h 192.168.102.222 -p 6379 get test_key;"); |
@@ -76,22 +32,21 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { | @@ -76,22 +32,21 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { | ||
76 | String[] arry = redisInfo2.split("<br>"); | 32 | String[] arry = redisInfo2.split("<br>"); |
77 | String val = arry[0].replace("\r\n", "").trim(); | 33 | String val = arry[0].replace("\r\n", "").trim(); |
78 | if("test".equals(val)){ | 34 | if("test".equals(val)){ |
79 | - isSlave=1; | 35 | + isSlave="同步"; |
80 | }else { | 36 | }else { |
81 | - isSlave=0; | 37 | + isSlave="不同步"; |
82 | } | 38 | } |
83 | } | 39 | } |
84 | - | ||
85 | - if (StringUtils.isNotEmpty(redisInfo)) { | ||
86 | - isRun=1; | ||
87 | - RedisInfo redis = new RedisInfo("192.168.102.162", getRedisInfo( | ||
88 | - redisInfo, "connected_clients"), isSlave, isRun, getRedisInfo(redisInfo,"role")); | ||
89 | - redisMapper.insert(redis); | 40 | + if(StringUtils.isEmpty(redisInfo)){ |
41 | + buff.append("状态:宕机;"); | ||
90 | }else{ | 42 | }else{ |
91 | - isRun=0; | ||
92 | - RedisInfo redis = new RedisInfo("192.168.102.162", "", isSlave, isRun, ""); | ||
93 | - redisMapper.insert(redis); | 43 | + buff.append("角色:"+getRedisInfo(redisInfo,"role")+";"); |
44 | + buff.append("用量:"+getRedisInfo(redisInfo,"used_memory_rss")+";"); | ||
45 | + buff.append("内存碎片比率:"+getRedisInfo(redisInfo,"mem_fragmentation_ratio")+";"); | ||
46 | + buff.append("主从同步:"+isSlave+";"); | ||
94 | } | 47 | } |
48 | + buff.toString(); | ||
49 | + System.out.println(buff.toString()); | ||
95 | } | 50 | } |
96 | 51 | ||
97 | public String getRedisInfo(String redisInfo, String info) { | 52 | public String getRedisInfo(String redisInfo, String info) { |
@@ -13,8 +13,8 @@ public class RedisMonitorTask { | @@ -13,8 +13,8 @@ public class RedisMonitorTask { | ||
13 | @Autowired | 13 | @Autowired |
14 | private IRedisMonitorService redisMonitorService; | 14 | private IRedisMonitorService redisMonitorService; |
15 | 15 | ||
16 | - //@Scheduled(fixedRate=20000) | ||
17 | - @Scheduled(cron="0 */5 * * * ?") | 16 | + @Scheduled(fixedRate=20000) |
17 | +// @Scheduled(cron="0 */5 * * * ?") | ||
18 | public void redisMonitor(){ | 18 | public void redisMonitor(){ |
19 | redisMonitorService.redisMonitor(); | 19 | redisMonitorService.redisMonitor(); |
20 | } | 20 | } |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | influxdb.num=2 | 3 | influxdb.num=2 |
4 | influxdb.name=test;alarm | 4 | influxdb.name=test;alarm |
5 | -influxdb.ip=http://192.168.102.162:8086;http://123.206.79.151:18086 | 5 | +influxdb.ip=http://192.168.102.162:8086;http://192.168.102.162:8086 |
6 | influxdb.user=yoho;root | 6 | influxdb.user=yoho;root |
7 | influxdb.pwd=Yoho_9646;root | 7 | influxdb.pwd=Yoho_9646;root |
8 | influxdb.connect.timeout=15;15 | 8 | influxdb.connect.timeout=15;15 |
1 | package com.monitor; | 1 | package com.monitor; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.JSON; | ||
3 | import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; | 4 | import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; |
4 | import com.monitor.javaserver.common.JavaApiStatics; | 5 | import com.monitor.javaserver.common.JavaApiStatics; |
5 | import com.monitor.model.domain.JavaApiStaticsModel; | 6 | import com.monitor.model.domain.JavaApiStaticsModel; |
@@ -51,19 +52,20 @@ public class JavaApiInfluxDBTest { | @@ -51,19 +52,20 @@ public class JavaApiInfluxDBTest { | ||
51 | public void testBatchQuery() { | 52 | public void testBatchQuery() { |
52 | 53 | ||
53 | List<JavaApiStatusReq> listParam = new ArrayList<>(); | 54 | List<JavaApiStatusReq> listParam = new ArrayList<>(); |
55 | + for (int i = 0; i < 30; i++) { | ||
54 | JavaApiStatusReq param1 = new JavaApiStatusReq(); | 56 | JavaApiStatusReq param1 = new JavaApiStatusReq(); |
55 | - param1.setServiceId(21); | ||
56 | - param1.setServiceId(43); | 57 | + param1.setServiceId(19); |
58 | + param1.setMObjectId(24); | ||
57 | listParam.add(param1); | 59 | listParam.add(param1); |
58 | - JavaApiStatusReq param2 = new JavaApiStatusReq(); | ||
59 | - param2.setServiceId(19); | ||
60 | - param2.setServiceId(134); | ||
61 | - | 60 | + } |
62 | 61 | ||
63 | - listParam.add(param2); | ||
64 | 62 | ||
63 | + long start = System.currentTimeMillis(); | ||
64 | + logger.info("############################################start..."); | ||
65 | List<JavaApiStaticsModel> rel = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, listParam); | 65 | List<JavaApiStaticsModel> rel = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, listParam); |
66 | - | 66 | + long end = System.currentTimeMillis(); |
67 | + logger.info("###########################################end... cost : {}", (end - start)); | ||
68 | + logger.info("############################################rel: {}", JSON.toJSON(rel)); | ||
67 | logger.info(rel.toString()); | 69 | logger.info(rel.toString()); |
68 | 70 | ||
69 | } | 71 | } |
-
Please register or login to post a comment