Showing
11 changed files
with
206 additions
and
41 deletions
@@ -6,6 +6,7 @@ import com.monitor.cmdb.service.IJavaApiInfoService; | @@ -6,6 +6,7 @@ import com.monitor.cmdb.service.IJavaApiInfoService; | ||
6 | import com.monitor.cmdb.service.impl.JavaApiInfoService; | 6 | import com.monitor.cmdb.service.impl.JavaApiInfoService; |
7 | import com.monitor.model.request.JavaApiInfoReq; | 7 | import com.monitor.model.request.JavaApiInfoReq; |
8 | import com.monitor.model.response.BaseResponse; | 8 | import com.monitor.model.response.BaseResponse; |
9 | +import com.monitor.model.response.JavaApiDetails; | ||
9 | import com.monitor.model.response.PageResponse; | 10 | import com.monitor.model.response.PageResponse; |
10 | import org.slf4j.Logger; | 11 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 12 | import org.slf4j.LoggerFactory; |
@@ -65,4 +66,22 @@ public class JavaApiInfoCtrl { | @@ -65,4 +66,22 @@ public class JavaApiInfoCtrl { | ||
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
69 | + @RequestMapping("/apiDetails") | ||
70 | + @ResponseBody | ||
71 | + public BaseResponse<JavaApiDetails> getJavaApiInfoDetails(@RequestParam(value = "id", required = true) Integer id) throws Exception { | ||
72 | + log.info("delMechineInfo with param is {}", id); | ||
73 | + | ||
74 | + BaseResponse baseResponse = new BaseResponse(); | ||
75 | + | ||
76 | + try { | ||
77 | + JavaApiDetails javaApiDetails = javaApiInfoService.getJavaApiDetails(id); | ||
78 | + baseResponse.setData(javaApiDetails); | ||
79 | + } catch (Exception e) { | ||
80 | + baseResponse.setCode(400); | ||
81 | + baseResponse.setMessage(e.getMessage()); | ||
82 | + } | ||
83 | + | ||
84 | + return baseResponse; | ||
85 | + } | ||
86 | + | ||
68 | } | 87 | } |
@@ -429,20 +429,14 @@ public class MObjectInfoCtrl { | @@ -429,20 +429,14 @@ public class MObjectInfoCtrl { | ||
429 | @RequestMapping(value = "/javaapi") | 429 | @RequestMapping(value = "/javaapi") |
430 | @ResponseBody | 430 | @ResponseBody |
431 | public BaseResponse queryJavaApiMobject() { | 431 | public BaseResponse queryJavaApiMobject() { |
432 | - | ||
433 | List<TypeInfo> allTypeInfo = null; | 432 | List<TypeInfo> allTypeInfo = null; |
434 | - | ||
435 | BaseResponse response = new BaseResponse(); | 433 | BaseResponse response = new BaseResponse(); |
436 | - | ||
437 | try { | 434 | try { |
438 | TypeInfo typeInfo = typeInfoService.queryTypeInfoByName(TypeInfoCtrl.TYPE_JAVA_APP); | 435 | TypeInfo typeInfo = typeInfoService.queryTypeInfoByName(TypeInfoCtrl.TYPE_JAVA_APP); |
439 | - | ||
440 | - | ||
441 | if (typeInfo == null) { | 436 | if (typeInfo == null) { |
442 | return response; | 437 | return response; |
443 | } | 438 | } |
444 | allTypeInfo = typeInfoService.queryChildTypesInfo(typeInfo.getTypeId()); | 439 | allTypeInfo = typeInfoService.queryChildTypesInfo(typeInfo.getTypeId()); |
445 | - | ||
446 | if (null == allTypeInfo) { | 440 | if (null == allTypeInfo) { |
447 | return response; | 441 | return response; |
448 | } | 442 | } |
@@ -450,7 +444,6 @@ public class MObjectInfoCtrl { | @@ -450,7 +444,6 @@ public class MObjectInfoCtrl { | ||
450 | for (TypeInfo type : allTypeInfo) { | 444 | for (TypeInfo type : allTypeInfo) { |
451 | ids.add(type.getTypeId()); | 445 | ids.add(type.getTypeId()); |
452 | } | 446 | } |
453 | - | ||
454 | List<MObjectInfo> javaApps = mobjectService.queryMObjectsInfoByTypes(ids); | 447 | List<MObjectInfo> javaApps = mobjectService.queryMObjectsInfoByTypes(ids); |
455 | response.setData(javaApps); | 448 | response.setData(javaApps); |
456 | 449 | ||
@@ -459,10 +452,30 @@ public class MObjectInfoCtrl { | @@ -459,10 +452,30 @@ public class MObjectInfoCtrl { | ||
459 | response.setCode(400); | 452 | response.setCode(400); |
460 | response.setMessage(e.getMessage()); | 453 | response.setMessage(e.getMessage()); |
461 | } | 454 | } |
462 | - | ||
463 | return response; | 455 | return response; |
456 | + } | ||
464 | 457 | ||
465 | 458 | ||
459 | + /** | ||
460 | + * 获取服务对象 根据类型 | ||
461 | + * | ||
462 | + * @return | ||
463 | + */ | ||
464 | + @RequestMapping(value = "/mobjById") | ||
465 | + @ResponseBody | ||
466 | + public BaseResponse queryMobjectById(@RequestParam int typeId) { | ||
467 | + List<TypeInfo> allTypeInfo = null; | ||
468 | + BaseResponse response = new BaseResponse(); | ||
469 | + try { | ||
470 | + List<MObjectInfo> javaApps = mobjectService.queryMObjectsInfoByType(typeId); | ||
471 | + response.setData(javaApps); | ||
472 | + | ||
473 | + } catch (Exception e) { | ||
474 | + DEBUG.error("Failed to query all typeInfo, error: {}", e); | ||
475 | + response.setCode(400); | ||
476 | + response.setMessage(e.getMessage()); | ||
477 | + } | ||
478 | + return response; | ||
466 | } | 479 | } |
467 | 480 | ||
468 | } | 481 | } |
@@ -3,6 +3,7 @@ package com.monitor.cmdb.service; | @@ -3,6 +3,7 @@ package com.monitor.cmdb.service; | ||
3 | import com.model.JavaApiInfo; | 3 | import com.model.JavaApiInfo; |
4 | import com.monitor.model.request.JavaApiInfoReq; | 4 | import com.monitor.model.request.JavaApiInfoReq; |
5 | import com.monitor.model.response.BaseResponse; | 5 | import com.monitor.model.response.BaseResponse; |
6 | +import com.monitor.model.response.JavaApiDetails; | ||
6 | import com.monitor.model.response.PageResponse; | 7 | import com.monitor.model.response.PageResponse; |
7 | 8 | ||
8 | import java.util.List; | 9 | import java.util.List; |
@@ -22,4 +23,7 @@ public interface IJavaApiInfoService { | @@ -22,4 +23,7 @@ public interface IJavaApiInfoService { | ||
22 | public BaseResponse<Integer> delJavaApiInfo(int id); | 23 | public BaseResponse<Integer> delJavaApiInfo(int id); |
23 | 24 | ||
24 | PageResponse<JavaApiInfo> getJavaApiInfos(JavaApiInfoReq req); | 25 | PageResponse<JavaApiInfo> getJavaApiInfos(JavaApiInfoReq req); |
26 | + | ||
27 | + JavaApiDetails getJavaApiDetails(int apiId); | ||
28 | + | ||
25 | } | 29 | } |
1 | package com.monitor.cmdb.service.impl; | 1 | package com.monitor.cmdb.service.impl; |
2 | 2 | ||
3 | import com.model.JavaApiInfo; | 3 | import com.model.JavaApiInfo; |
4 | +import com.model.MObjectInfo; | ||
4 | import com.monitor.cmdb.service.IJavaApiInfoService; | 5 | import com.monitor.cmdb.service.IJavaApiInfoService; |
6 | +import com.monitor.model.domain.MObjectModel; | ||
5 | import com.monitor.model.domain.PageBean; | 7 | import com.monitor.model.domain.PageBean; |
6 | import com.monitor.model.request.JavaApiInfoReq; | 8 | import com.monitor.model.request.JavaApiInfoReq; |
7 | import com.monitor.model.response.BaseResponse; | 9 | import com.monitor.model.response.BaseResponse; |
10 | +import com.monitor.model.response.JavaApiDetails; | ||
8 | import com.monitor.model.response.PageResponse; | 11 | import com.monitor.model.response.PageResponse; |
9 | import com.monitor.mysql.mapper.JavaApiInfoMapper; | 12 | import com.monitor.mysql.mapper.JavaApiInfoMapper; |
13 | +import com.monitor.mysql.mapper.MObjectInfoMapper; | ||
10 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
16 | +import org.springframework.beans.BeanUtils; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
13 | -import org.springframework.stereotype.Component; | ||
14 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
15 | import org.springframework.util.CollectionUtils; | 19 | import org.springframework.util.CollectionUtils; |
16 | 20 | ||
21 | +import java.util.ArrayList; | ||
17 | import java.util.List; | 22 | import java.util.List; |
18 | 23 | ||
19 | /** | 24 | /** |
@@ -21,9 +26,13 @@ import java.util.List; | @@ -21,9 +26,13 @@ import java.util.List; | ||
21 | */ | 26 | */ |
22 | @Service | 27 | @Service |
23 | public class JavaApiInfoService implements IJavaApiInfoService { | 28 | public class JavaApiInfoService implements IJavaApiInfoService { |
24 | - Logger log= LoggerFactory.getLogger(JavaApiInfoService.class); | 29 | + Logger log = LoggerFactory.getLogger(JavaApiInfoService.class); |
25 | @Autowired | 30 | @Autowired |
26 | private JavaApiInfoMapper javaApiInfoMapper; | 31 | private JavaApiInfoMapper javaApiInfoMapper; |
32 | + | ||
33 | + @Autowired | ||
34 | + private MObjectInfoMapper mObjectInfoMapper; | ||
35 | + | ||
27 | @Override | 36 | @Override |
28 | public List<JavaApiInfo> queryJavaApiInfo() { | 37 | public List<JavaApiInfo> queryJavaApiInfo() { |
29 | return javaApiInfoMapper.selectAllApi(); | 38 | return javaApiInfoMapper.selectAllApi(); |
@@ -36,18 +45,18 @@ public class JavaApiInfoService implements IJavaApiInfoService { | @@ -36,18 +45,18 @@ public class JavaApiInfoService implements IJavaApiInfoService { | ||
36 | 45 | ||
37 | @Override | 46 | @Override |
38 | public BaseResponse<Integer> saveJavaApiInfo(JavaApiInfo javaApiInfo) { | 47 | public BaseResponse<Integer> saveJavaApiInfo(JavaApiInfo javaApiInfo) { |
39 | - int result=0; | ||
40 | - if(javaApiInfo.getServiceId()!=null&&javaApiInfo.getServiceId()>0){ | ||
41 | - result=javaApiInfoMapper.updateByPrimaryKey(javaApiInfo); | ||
42 | - }else{ | ||
43 | - result=javaApiInfoMapper.insert(javaApiInfo); | 48 | + int result = 0; |
49 | + if (javaApiInfo.getServiceId() != null && javaApiInfo.getServiceId() > 0) { | ||
50 | + result = javaApiInfoMapper.updateByPrimaryKey(javaApiInfo); | ||
51 | + } else { | ||
52 | + result = javaApiInfoMapper.insert(javaApiInfo); | ||
44 | } | 53 | } |
45 | return new BaseResponse<Integer>(result); | 54 | return new BaseResponse<Integer>(result); |
46 | } | 55 | } |
47 | 56 | ||
48 | @Override | 57 | @Override |
49 | public BaseResponse<Integer> delJavaApiInfo(int id) { | 58 | public BaseResponse<Integer> delJavaApiInfo(int id) { |
50 | - int result=javaApiInfoMapper.deleteByPrimaryKey(id); | 59 | + int result = javaApiInfoMapper.deleteByPrimaryKey(id); |
51 | return new BaseResponse<Integer>(result); | 60 | return new BaseResponse<Integer>(result); |
52 | } | 61 | } |
53 | 62 | ||
@@ -80,4 +89,33 @@ public class JavaApiInfoService implements IJavaApiInfoService { | @@ -80,4 +89,33 @@ public class JavaApiInfoService implements IJavaApiInfoService { | ||
80 | return response; | 89 | return response; |
81 | } | 90 | } |
82 | 91 | ||
92 | + public JavaApiDetails getJavaApiDetails(int apiId) { | ||
93 | + if (apiId <= 0) | ||
94 | + return null; | ||
95 | + | ||
96 | + JavaApiInfo javaApiInfo = javaApiInfoMapper.selectByPrimaryKey(apiId); | ||
97 | + if (javaApiInfo == null) | ||
98 | + return null; | ||
99 | + | ||
100 | + JavaApiDetails javaApiDetails = new JavaApiDetails(); | ||
101 | + BeanUtils.copyProperties(javaApiInfo, javaApiDetails); | ||
102 | + | ||
103 | + int serviceType = javaApiDetails.getServiceType(); | ||
104 | + | ||
105 | + List<Integer> ids = new ArrayList<>(1); | ||
106 | + ids.add(serviceType); | ||
107 | + List<MObjectInfo> mObjectInfos = mObjectInfoMapper.selectMObjectsInfoByTypes(ids); | ||
108 | + List<MObjectModel> mObjectModels = new ArrayList<>(); | ||
109 | + for (MObjectInfo mObjectInfo : mObjectInfos) { | ||
110 | + MObjectModel mObjectModel = new MObjectModel(); | ||
111 | + BeanUtils.copyProperties(mObjectInfo, mObjectModel); | ||
112 | + mObjectModels.add(mObjectModel); | ||
113 | + } | ||
114 | + javaApiDetails.setMObjectModels(mObjectModels); | ||
115 | + | ||
116 | + return javaApiDetails; | ||
117 | + | ||
118 | + } | ||
119 | + | ||
120 | + | ||
83 | } | 121 | } |
@@ -19,7 +19,9 @@ public interface IJavaApiStaticsMapper { | @@ -19,7 +19,9 @@ public interface IJavaApiStaticsMapper { | ||
19 | public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> query); | 19 | public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> query); |
20 | 20 | ||
21 | 21 | ||
22 | - public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, int api_id,int mobj_id, String timeStart, String timeEnd, int limitCount, int offsetCount); | 22 | + public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd, int limitCount, int offsetCount); |
23 | + | ||
24 | + public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd); | ||
23 | 25 | ||
24 | 26 | ||
25 | } | 27 | } |
@@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper.impl; | @@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper.impl; | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.monitor.common.contants.InfluxDBContants; | 4 | import com.monitor.common.contants.InfluxDBContants; |
5 | import com.monitor.common.util.DateFormatUtil; | 5 | import com.monitor.common.util.DateFormatUtil; |
6 | +import com.monitor.common.util.QueryResultUtil; | ||
6 | import com.monitor.influxdb.InluxDBSingle; | 7 | import com.monitor.influxdb.InluxDBSingle; |
7 | import com.monitor.influxdb.mapper.IJavaApiStaticsMapper; | 8 | import com.monitor.influxdb.mapper.IJavaApiStaticsMapper; |
8 | import com.monitor.model.domain.JavaApiStaticsModel; | 9 | import com.monitor.model.domain.JavaApiStaticsModel; |
@@ -11,6 +12,8 @@ import org.influxdb.dto.BatchPoints; | @@ -11,6 +12,8 @@ import org.influxdb.dto.BatchPoints; | ||
11 | import org.influxdb.dto.Point; | 12 | import org.influxdb.dto.Point; |
12 | import org.influxdb.dto.Query; | 13 | import org.influxdb.dto.Query; |
13 | import org.influxdb.dto.QueryResult; | 14 | import org.influxdb.dto.QueryResult; |
15 | +import org.slf4j.Logger; | ||
16 | +import org.slf4j.LoggerFactory; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
15 | import org.springframework.stereotype.Component; | 18 | import org.springframework.stereotype.Component; |
16 | 19 | ||
@@ -26,6 +29,7 @@ import java.util.concurrent.TimeUnit; | @@ -26,6 +29,7 @@ import java.util.concurrent.TimeUnit; | ||
26 | @Component | 29 | @Component |
27 | public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | 30 | public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
28 | 31 | ||
32 | + Logger log = LoggerFactory.getLogger(JavaApiStaticsMapper.class); | ||
29 | @Autowired | 33 | @Autowired |
30 | private InluxDBSingle inluxDBSingle; | 34 | private InluxDBSingle inluxDBSingle; |
31 | 35 | ||
@@ -141,6 +145,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -141,6 +145,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
141 | if (mobj_id > 0) | 145 | if (mobj_id > 0) |
142 | sql += " and mobj_id= " + mobj_id; | 146 | sql += " and mobj_id= " + mobj_id; |
143 | sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount; | 147 | sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount; |
148 | + log.info("sql:{}", sql); | ||
144 | Query query = new Query(sql, InfluxDBContants.APP_ALARM); | 149 | Query query = new Query(sql, InfluxDBContants.APP_ALARM); |
145 | 150 | ||
146 | QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query); | 151 | QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query); |
@@ -150,13 +155,16 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -150,13 +155,16 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
150 | QueryResult.Result rel = result.getResults().get(0); | 155 | QueryResult.Result rel = result.getResults().get(0); |
151 | 156 | ||
152 | 157 | ||
158 | + if (rel.getSeries() == null) { | ||
159 | + return list; | ||
160 | + } | ||
153 | QueryResult.Series series = rel.getSeries().get(0); | 161 | QueryResult.Series series = rel.getSeries().get(0); |
154 | int size = series.getValues().size(); | 162 | int size = series.getValues().size(); |
155 | for (int i = 0; i < size; i++) { | 163 | for (int i = 0; i < size; i++) { |
156 | JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel(); | 164 | JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel(); |
157 | - Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception")); | ||
158 | - long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start"))); | ||
159 | - long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end"))); | 165 | + Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception")); |
166 | + long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start"))); | ||
167 | + long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end"))); | ||
160 | long costTime = (endTime - startTime); | 168 | long costTime = (endTime - startTime); |
161 | 169 | ||
162 | 170 | ||
@@ -166,31 +174,31 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -166,31 +174,31 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
166 | javaApiStaticsModel.setCostTime((int) costTime); | 174 | javaApiStaticsModel.setCostTime((int) costTime); |
167 | 175 | ||
168 | 176 | ||
169 | - int a_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue(); | ||
170 | - int m_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("mobj_id"))).intValue(); | 177 | + int a_id = ((Double) series.getValues().get(i).get(series.getColumns().indexOf("api_id"))).intValue(); |
178 | + int m_id = ((Double) series.getValues().get(i).get(series.getColumns().indexOf("mobj_id"))).intValue(); | ||
171 | 179 | ||
172 | javaApiStaticsModel.setServiceId(a_id); | 180 | javaApiStaticsModel.setServiceId(a_id); |
173 | javaApiStaticsModel.setMObjectId(m_id); | 181 | javaApiStaticsModel.setMObjectId(m_id); |
174 | 182 | ||
175 | 183 | ||
176 | - String m_ip = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_ip")); | ||
177 | - String m_port = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_port")); | ||
178 | - String m_name = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_name")); | 184 | + String m_ip = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_ip")); |
185 | + String m_port = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_port")); | ||
186 | + String m_name = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_name")); | ||
179 | javaApiStaticsModel.setMIp(m_ip); | 187 | javaApiStaticsModel.setMIp(m_ip); |
180 | javaApiStaticsModel.setMPort(m_port); | 188 | javaApiStaticsModel.setMPort(m_port); |
181 | javaApiStaticsModel.setMName(m_name); | 189 | javaApiStaticsModel.setMName(m_name); |
182 | 190 | ||
183 | - String time = (String) series.getValues().get(0).get(series.getColumns().indexOf("time")); | 191 | + String time = (String) series.getValues().get(i).get(series.getColumns().indexOf("time")); |
184 | 192 | ||
185 | javaApiStaticsModel.setTime(DateFormatUtil.displayFormat(time)); | 193 | javaApiStaticsModel.setTime(DateFormatUtil.displayFormat(time)); |
186 | 194 | ||
187 | if (is_exception == true) { | 195 | if (is_exception == true) { |
188 | javaApiStaticsModel.setStatus(0); | 196 | javaApiStaticsModel.setStatus(0); |
189 | - String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception")); | 197 | + String exception = (String) series.getValues().get(i).get(series.getColumns().indexOf("exception")); |
190 | javaApiStaticsModel.setException(exception); | 198 | javaApiStaticsModel.setException(exception); |
191 | } else { | 199 | } else { |
192 | javaApiStaticsModel.setStatus(1); | 200 | javaApiStaticsModel.setStatus(1); |
193 | - String response = (String) series.getValues().get(0).get(series.getColumns().indexOf("response")); | 201 | + String response = (String) series.getValues().get(i).get(series.getColumns().indexOf("response")); |
194 | javaApiStaticsModel.setResponse(response); | 202 | javaApiStaticsModel.setResponse(response); |
195 | } | 203 | } |
196 | list.add(javaApiStaticsModel); | 204 | list.add(javaApiStaticsModel); |
@@ -198,5 +206,21 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | @@ -198,5 +206,21 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
198 | return list; | 206 | return list; |
199 | } | 207 | } |
200 | 208 | ||
209 | + public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd) { | ||
210 | + String sql = "select count(api_id) from " + InfluxDBContants.YOMO_TB_JAVAAPI; | ||
211 | + sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' "; | ||
212 | + if (api_id > 0) | ||
213 | + sql += " and api_id= " + api_id; | ||
214 | + if (mobj_id > 0) | ||
215 | + sql += " and mobj_id= " + mobj_id; | ||
216 | + | ||
217 | + | ||
218 | + Query query = new Query(sql, InfluxDBContants.APP_ALARM); | ||
219 | + | ||
220 | + QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query); | ||
221 | + | ||
222 | + return QueryResultUtil.getCount(result); | ||
223 | + } | ||
224 | + | ||
201 | 225 | ||
202 | } | 226 | } |
@@ -2,6 +2,7 @@ package com.monitor.javaserver.ctrl; | @@ -2,6 +2,7 @@ package com.monitor.javaserver.ctrl; | ||
2 | 2 | ||
3 | import com.monitor.javaserver.client.JavaApiClient; | 3 | import com.monitor.javaserver.client.JavaApiClient; |
4 | import com.monitor.javaserver.service.IJavaApiStatusService; | 4 | import com.monitor.javaserver.service.IJavaApiStatusService; |
5 | +import com.monitor.model.page.PageResponse; | ||
5 | import com.monitor.model.request.JavaApiStatusReq; | 6 | import com.monitor.model.request.JavaApiStatusReq; |
6 | import com.monitor.model.response.BaseResponse; | 7 | import com.monitor.model.response.BaseResponse; |
7 | import com.monitor.model.response.JavaApiStatusRep; | 8 | import com.monitor.model.response.JavaApiStatusRep; |
@@ -91,6 +92,8 @@ public class JavaAppInfoCtrl { | @@ -91,6 +92,8 @@ public class JavaAppInfoCtrl { | ||
91 | rep.setMessage(e.getMessage()); | 92 | rep.setMessage(e.getMessage()); |
92 | } | 93 | } |
93 | return rep; | 94 | return rep; |
95 | + | ||
96 | + | ||
94 | } | 97 | } |
95 | 98 | ||
96 | @RequestMapping("/queryhis") | 99 | @RequestMapping("/queryhis") |
@@ -99,8 +102,8 @@ public class JavaAppInfoCtrl { | @@ -99,8 +102,8 @@ public class JavaAppInfoCtrl { | ||
99 | @RequestParam(required = false, defaultValue = "0") int mobj_id, | 102 | @RequestParam(required = false, defaultValue = "0") int mobj_id, |
100 | @RequestParam(required = false, defaultValue = "0") long start_time, | 103 | @RequestParam(required = false, defaultValue = "0") long start_time, |
101 | @RequestParam(required = false, defaultValue = "0") long end_time, | 104 | @RequestParam(required = false, defaultValue = "0") long end_time, |
102 | - @RequestParam(required = false, defaultValue = "0") int page) { | ||
103 | - BaseResponse rep = new BaseResponse(); | 105 | + @RequestParam(required = false, defaultValue = "0") int page, |
106 | + @RequestParam(required = false, defaultValue = "10") int pageSize) { | ||
104 | if (start_time == 0) { | 107 | if (start_time == 0) { |
105 | return getJavaApiStatusHisLatest(api_id, mobj_id); | 108 | return getJavaApiStatusHisLatest(api_id, mobj_id); |
106 | } | 109 | } |
@@ -108,16 +111,27 @@ public class JavaAppInfoCtrl { | @@ -108,16 +111,27 @@ public class JavaAppInfoCtrl { | ||
108 | if (end_time == 0) | 111 | if (end_time == 0) |
109 | end_time = System.currentTimeMillis(); | 112 | end_time = System.currentTimeMillis(); |
110 | 113 | ||
114 | + | ||
115 | + BaseResponse baseResponse = new BaseResponse(); | ||
116 | + PageResponse<JavaApiStatusRep> pageResponse = new PageResponse<JavaApiStatusRep>(); | ||
111 | try { | 117 | try { |
112 | - List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page); | ||
113 | - rep.setData(javaApiStatusRepList); | 118 | + |
119 | + int count = javaApiStatusService.countJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time); | ||
120 | + | ||
121 | + List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page, pageSize); | ||
122 | + pageResponse.setRows(javaApiStatusRepList); | ||
123 | + pageResponse.setCurrentPage(page); | ||
124 | + pageResponse.setPageSize(pageSize); | ||
125 | + pageResponse.setTotal(count); | ||
126 | + baseResponse.setData(pageResponse); | ||
114 | } catch (Exception e) { | 127 | } catch (Exception e) { |
115 | log.warn("queryhis failed apiId :{} mobjId:{} start_time:{} endTime:{} ,page:{} ", api_id, mobj_id, start_time, end_time, page, e); | 128 | log.warn("queryhis failed apiId :{} mobjId:{} start_time:{} endTime:{} ,page:{} ", api_id, mobj_id, start_time, end_time, page, e); |
116 | - rep.setCode(400); | ||
117 | - rep.setMessage(e.getMessage()); | 129 | + baseResponse.setCode(400); |
130 | + baseResponse.setMessage(e.getMessage()); | ||
118 | } | 131 | } |
119 | 132 | ||
120 | - return rep; | 133 | + return baseResponse; |
134 | + | ||
121 | } | 135 | } |
122 | 136 | ||
123 | } | 137 | } |
@@ -17,6 +17,9 @@ public interface IJavaApiStatusService { | @@ -17,6 +17,9 @@ public interface IJavaApiStatusService { | ||
17 | 17 | ||
18 | public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id); | 18 | public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id); |
19 | 19 | ||
20 | - public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page); | 20 | + public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page,int pageSize); |
21 | + | ||
22 | + public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end); | ||
23 | + | ||
21 | 24 | ||
22 | } | 25 | } |
@@ -81,18 +81,18 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { | @@ -81,18 +81,18 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { | ||
81 | long start = System.currentTimeMillis(); | 81 | long start = System.currentTimeMillis(); |
82 | long end = start; | 82 | long end = start; |
83 | start = start - 1000 * 60 * 60; //一小时之内 | 83 | start = start - 1000 * 60 * 60; //一小时之内 |
84 | - return this.getJavaApiStatusHisByTime(api_id, mobj_id, start, end, 0); | 84 | + return this.getJavaApiStatusHisByTime(api_id, mobj_id, start, end, 0, 10); |
85 | } | 85 | } |
86 | 86 | ||
87 | @Override | 87 | @Override |
88 | - public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page) { | 88 | + public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page, int pageSize) { |
89 | String startTime = DateFormatUtil.influxDBTimeFormat(start); | 89 | String startTime = DateFormatUtil.influxDBTimeFormat(start); |
90 | String endTime = DateFormatUtil.influxDBTimeFormat(end); | 90 | String endTime = DateFormatUtil.influxDBTimeFormat(end); |
91 | 91 | ||
92 | 92 | ||
93 | List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, api_id, mobj_id, | 93 | List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, api_id, mobj_id, |
94 | - startTime, endTime, PaginationContants.PAGE_COMMON_OFFSET_PERIOD, | ||
95 | - page * PaginationContants.PAGE_COMMON_OFFSET_PERIOD); | 94 | + startTime, endTime, pageSize, |
95 | + page * pageSize); | ||
96 | List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>(); | 96 | List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>(); |
97 | 97 | ||
98 | for (JavaApiStaticsModel model : modelList) { | 98 | for (JavaApiStaticsModel model : modelList) { |
@@ -120,5 +120,15 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { | @@ -120,5 +120,15 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService { | ||
120 | 120 | ||
121 | } | 121 | } |
122 | 122 | ||
123 | + @Override | ||
124 | + public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end) { | ||
125 | + String startTime = DateFormatUtil.influxDBTimeFormat(start); | ||
126 | + String endTime = DateFormatUtil.influxDBTimeFormat(end); | ||
127 | + | ||
128 | + | ||
129 | + int count = javaApiStaticsMapper.countJavaApiStaticHis(null, api_id, mobj_id, startTime, endTime); | ||
130 | + return count; | ||
131 | + } | ||
132 | + | ||
123 | 133 | ||
124 | } | 134 | } |
1 | +package com.monitor.model.response; | ||
2 | + | ||
3 | + | ||
4 | +import com.monitor.model.domain.MObjectModel; | ||
5 | +import lombok.Data; | ||
6 | +import org.apache.commons.lang.builder.ReflectionToStringBuilder; | ||
7 | + | ||
8 | +import java.util.List; | ||
9 | + | ||
10 | +/** | ||
11 | + * Created by fruwei on 2016/6/23. | ||
12 | + */ | ||
13 | +@Data | ||
14 | +public class JavaApiDetails { | ||
15 | + private Integer serviceId; | ||
16 | + | ||
17 | + private Integer serviceType; | ||
18 | + | ||
19 | + private String apiName; | ||
20 | + | ||
21 | + private String apiUrl; | ||
22 | + | ||
23 | + private String apiData; | ||
24 | + | ||
25 | + private Integer apiToggle; | ||
26 | + | ||
27 | + private Integer apiReqMethod; | ||
28 | + | ||
29 | + private Integer apiWarnTrigger; | ||
30 | + | ||
31 | + private List<MObjectModel> mObjectModels; | ||
32 | + | ||
33 | + | ||
34 | + @Override | ||
35 | + public String toString() { | ||
36 | + return ReflectionToStringBuilder.toString(this); | ||
37 | + } | ||
38 | +} |
1 | # ******************** influxdb common configs ******************** | 1 | # ******************** influxdb common configs ******************** |
2 | influxdb.num=2 | 2 | influxdb.num=2 |
3 | influxdb.name=aws;qcloud | 3 | influxdb.name=aws;qcloud |
4 | -influxdb.ip=http://123.206.79.151:8086;http://10.66.4.25:8086 | 4 | +influxdb.ip=http://192.168.102.162:8086;http://10.66.4.25:8086 |
5 | influxdb.user=root;root | 5 | influxdb.user=root;root |
6 | influxdb.pwd=root;root | 6 | influxdb.pwd=root;root |
7 | influxdb.connect.timeout=15;15 | 7 | influxdb.connect.timeout=15;15 |
-
Please register or login to post a comment