Showing
6 changed files
with
112 additions
and
9 deletions
@@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper; | @@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper; | ||
3 | import com.monitor.influxdb.model.ZkInfo; | 3 | import com.monitor.influxdb.model.ZkInfo; |
4 | import com.monitor.model.domain.JavaProjectStatus; | 4 | import com.monitor.model.domain.JavaProjectStatus; |
5 | import com.monitor.model.domain.PageBean; | 5 | import com.monitor.model.domain.PageBean; |
6 | +import org.influxdb.dto.QueryResult; | ||
6 | 7 | ||
7 | import java.util.List; | 8 | import java.util.List; |
8 | 9 | ||
@@ -13,4 +14,6 @@ public interface JavaProjectMapper { | @@ -13,4 +14,6 @@ public interface JavaProjectMapper { | ||
13 | 14 | ||
14 | void insert(JavaProjectStatus javaProjectStatus); | 15 | void insert(JavaProjectStatus javaProjectStatus); |
15 | 16 | ||
17 | + List<JavaProjectStatus> getByProject(String project); | ||
18 | + | ||
16 | } | 19 | } |
@@ -4,14 +4,16 @@ import com.monitor.influxdb.InfluxDBQuery; | @@ -4,14 +4,16 @@ import com.monitor.influxdb.InfluxDBQuery; | ||
4 | import com.monitor.influxdb.InluxDBSingle; | 4 | import com.monitor.influxdb.InluxDBSingle; |
5 | import com.monitor.influxdb.contants.InfluxDBContants; | 5 | import com.monitor.influxdb.contants.InfluxDBContants; |
6 | import com.monitor.influxdb.mapper.JavaProjectMapper; | 6 | import com.monitor.influxdb.mapper.JavaProjectMapper; |
7 | +import com.monitor.influxdb.util.QueryResultUtil; | ||
7 | import com.monitor.model.domain.JavaProjectStatus; | 8 | import com.monitor.model.domain.JavaProjectStatus; |
8 | import org.influxdb.dto.Point; | 9 | import org.influxdb.dto.Point; |
10 | +import org.influxdb.dto.QueryResult; | ||
9 | import org.slf4j.Logger; | 11 | import org.slf4j.Logger; |
10 | import org.slf4j.LoggerFactory; | 12 | import org.slf4j.LoggerFactory; |
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; |
13 | 15 | ||
14 | -import java.util.Random; | 16 | +import java.util.*; |
15 | import java.util.concurrent.TimeUnit; | 17 | import java.util.concurrent.TimeUnit; |
16 | 18 | ||
17 | /** | 19 | /** |
@@ -34,10 +36,36 @@ public class JavaProjectMapperImpl extends InfluxDBQuery implements JavaProjectM | @@ -34,10 +36,36 @@ public class JavaProjectMapperImpl extends InfluxDBQuery implements JavaProjectM | ||
34 | .tag("ip", javaProjectStatus.getIp()) | 36 | .tag("ip", javaProjectStatus.getIp()) |
35 | .tag("cloud", javaProjectStatus.getCloud()) | 37 | .tag("cloud", javaProjectStatus.getCloud()) |
36 | .tag("status", javaProjectStatus.getStatus()) | 38 | .tag("status", javaProjectStatus.getStatus()) |
37 | - .addField("lastStart",javaProjectStatus.getLastStart() == null? "1":javaProjectStatus.getLastStart()) | 39 | + .addField("lastStart", javaProjectStatus.getLastStart() == null ? "1" : javaProjectStatus.getLastStart()) |
38 | .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS) | 40 | .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS) |
39 | .build(); | 41 | .build(); |
40 | inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB() | 42 | inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB() |
41 | .write(InfluxDBContants.MONITOR_SYSTEM, "default", point); | 43 | .write(InfluxDBContants.MONITOR_SYSTEM, "default", point); |
42 | } | 44 | } |
45 | + | ||
46 | + @Override | ||
47 | + public List<JavaProjectStatus> getByProject(String project) { | ||
48 | + String cpmmond = "select cloud,ip,lastStart,status from java_project_status where time > now() - 4m and \"name\" = '" + project + "' order by time desc"; | ||
49 | + QueryResult result = query(InfluxDBContants.AWS, cpmmond, InfluxDBContants.MONITOR_SYSTEM); | ||
50 | + List<List<Object>> lists = QueryResultUtil.getValues(result); | ||
51 | + List<JavaProjectStatus> javaProjectStatusList = new ArrayList<>(); | ||
52 | + Set<String> stringSet = new HashSet<>(); | ||
53 | + if (lists != null){ | ||
54 | + JavaProjectStatus javaProjectStatus; | ||
55 | + for (List<Object> objects : lists){ | ||
56 | + String ip = objects.get(2).toString(); | ||
57 | + if (stringSet.contains(ip)){ | ||
58 | + continue; | ||
59 | + } | ||
60 | + stringSet.add(ip); | ||
61 | + javaProjectStatus = new JavaProjectStatus(); | ||
62 | + javaProjectStatus.setCloud(objects.get(1).toString()); | ||
63 | + javaProjectStatus.setIp(objects.get(2).toString().split("@")[1]); | ||
64 | + javaProjectStatus.setLastStart(objects.get(3).toString()); | ||
65 | + javaProjectStatus.setStatus(objects.get(4).toString()); | ||
66 | + javaProjectStatusList.add(javaProjectStatus); | ||
67 | + } | ||
68 | + } | ||
69 | + return javaProjectStatusList; | ||
70 | + } | ||
43 | } | 71 | } |
@@ -9,6 +9,7 @@ public class ProjectOnline { | @@ -9,6 +9,7 @@ public class ProjectOnline { | ||
9 | 9 | ||
10 | 10 | ||
11 | static{ | 11 | static{ |
12 | + JAVA_LIST.add(new Project("1","yoho-gateway","126","yoho30")); | ||
12 | JAVA_LIST.add(new Project("1","yoho-sns","125","yoho30")); | 13 | JAVA_LIST.add(new Project("1","yoho-sns","125","yoho30")); |
13 | JAVA_LIST.add(new Project("1","yoho-message","123","yoho30")); | 14 | JAVA_LIST.add(new Project("1","yoho-message","123","yoho30")); |
14 | JAVA_LIST.add(new Project("1","uic","439","yoho30")); | 15 | JAVA_LIST.add(new Project("1","uic","439","yoho30")); |
@@ -18,8 +19,6 @@ public class ProjectOnline { | @@ -18,8 +19,6 @@ public class ProjectOnline { | ||
18 | JAVA_LIST.add(new Project("1","yohobuy-product","143","yoho30")); | 19 | JAVA_LIST.add(new Project("1","yohobuy-product","143","yoho30")); |
19 | JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30")); | 20 | JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30")); |
20 | JAVA_LIST.add(new Project("1","yoho-push","137","yoho30")); | 21 | JAVA_LIST.add(new Project("1","yoho-push","137","yoho30")); |
21 | - JAVA_LIST.add(new Project("1","cms_push","514","yoho30")); | ||
22 | - JAVA_LIST.add(new Project("1","mars_push","494","yoho30")); | ||
23 | JAVA_LIST.add(new Project("1","yoho-social","353","yoho30")); | 22 | JAVA_LIST.add(new Project("1","yoho-social","353","yoho30")); |
24 | JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30")); | 23 | JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30")); |
25 | JAVA_LIST.add(new Project("1","yohobuy-activity","129","yoho30")); | 24 | JAVA_LIST.add(new Project("1","yohobuy-activity","129","yoho30")); |
@@ -28,15 +27,14 @@ public class ProjectOnline { | @@ -28,15 +27,14 @@ public class ProjectOnline { | ||
28 | JAVA_LIST.add(new Project("1","yohobuy-wechat","248","yoho30")); | 27 | JAVA_LIST.add(new Project("1","yohobuy-wechat","248","yoho30")); |
29 | JAVA_LIST.add(new Project("1","yohobuy-brower","131","yoho30")); | 28 | JAVA_LIST.add(new Project("1","yohobuy-brower","131","yoho30")); |
30 | JAVA_LIST.add(new Project("1","yohobuy-bigdata","144","yoho30")); | 29 | JAVA_LIST.add(new Project("1","yohobuy-bigdata","144","yoho30")); |
31 | - JAVA_LIST.add(new Project("1","yoho-gateway","126","yoho30")); | ||
32 | - | ||
33 | JAVA_LIST.add(new Project("2","yoho-search-service","12","yoho-search")); | 30 | JAVA_LIST.add(new Project("2","yoho-search-service","12","yoho-search")); |
34 | JAVA_LIST.add(new Project("2","yoho-search-consumer","8","yoho-search")); | 31 | JAVA_LIST.add(new Project("2","yoho-search-consumer","8","yoho-search")); |
35 | JAVA_LIST.add(new Project("2","yoho-search-producer","7","yoho-search")); | 32 | JAVA_LIST.add(new Project("2","yoho-search-producer","7","yoho-search")); |
36 | JAVA_LIST.add(new Project("2","yohomars-search-service","554","yoho-search")); | 33 | JAVA_LIST.add(new Project("2","yohomars-search-service","554","yoho-search")); |
37 | JAVA_LIST.add(new Project("2","yoho-search-adaptor","13","yoho-search")); | 34 | JAVA_LIST.add(new Project("2","yoho-search-adaptor","13","yoho-search")); |
38 | - | ||
39 | JAVA_LIST.add(new Project("3","yohobuy-platform","110","platform")); | 35 | JAVA_LIST.add(new Project("3","yohobuy-platform","110","platform")); |
36 | + JAVA_LIST.add(new Project("1","cms_push","514","yoho30")); | ||
37 | + JAVA_LIST.add(new Project("1","mars_push","494","yoho30")); | ||
40 | 38 | ||
41 | } | 39 | } |
42 | 40 |
monitor-service-other/src/main/java/com/monitor/other/projectRestart/ctrl/JavaRestartCtrl.java
0 → 100644
1 | +package com.monitor.other.projectRestart.ctrl; | ||
2 | + | ||
3 | +import com.model.JavaApiInfo; | ||
4 | +import com.monitor.influxdb.mapper.JavaProjectMapper; | ||
5 | +import com.monitor.model.domain.JavaProjectStatus; | ||
6 | +import com.monitor.model.domain.PageBean; | ||
7 | +import com.monitor.model.page.PageRequest; | ||
8 | +import com.monitor.model.request.JavaApiInfoReq; | ||
9 | +import com.monitor.model.response.BaseResponse; | ||
10 | +import com.monitor.model.response.PageResponse; | ||
11 | +import com.monitor.other.projectRestart.common.Project; | ||
12 | +import com.monitor.other.projectRestart.common.ProjectOnline; | ||
13 | +import org.slf4j.Logger; | ||
14 | +import org.slf4j.LoggerFactory; | ||
15 | +import org.springframework.beans.factory.annotation.Autowired; | ||
16 | +import org.springframework.util.CollectionUtils; | ||
17 | +import org.springframework.web.bind.annotation.RequestBody; | ||
18 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
19 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
20 | +import org.springframework.web.bind.annotation.RestController; | ||
21 | + | ||
22 | +import java.util.List; | ||
23 | + | ||
24 | +/** | ||
25 | + * Created by zhengyouwei on 2016/10/18. | ||
26 | + */ | ||
27 | +@RestController | ||
28 | +@RequestMapping(value = "/javaRestart") | ||
29 | +public class JavaRestartCtrl { | ||
30 | + Logger log = LoggerFactory.getLogger(JavaRestartCtrl.class); | ||
31 | + | ||
32 | + @Autowired | ||
33 | + private JavaProjectMapper javaProjectMapper; | ||
34 | + | ||
35 | + @RequestMapping("/query") | ||
36 | + @ResponseBody | ||
37 | + public BaseResponse<PageResponse<Project>> getProjectInfos(@RequestBody PageRequest req) throws Exception { | ||
38 | + PageResponse<Project> response = new PageResponse<Project>(); | ||
39 | + try { | ||
40 | + // 组装分页对象 | ||
41 | + PageBean page = PageBean.initPageInfo(req.getCurrentPage(), | ||
42 | + req.getPageSize(), req); | ||
43 | + // 先查询符合条件的总数量 | ||
44 | + int total = ProjectOnline.getJavaList().size(); | ||
45 | + response.setCurrentPage(req.getCurrentPage()); | ||
46 | + int end = page.getStartIndex() + page.getPageSize(); | ||
47 | + if (end >= total) { | ||
48 | + end = total; | ||
49 | + } | ||
50 | + response.setRows(ProjectOnline.getJavaList().subList(page.getStartIndex(), end)); | ||
51 | + response.setPageSize(req.getPageSize()); | ||
52 | + response.setTotal(total); | ||
53 | + } catch (Exception e) { | ||
54 | + log.error("getProjectInfos~", e); | ||
55 | + } | ||
56 | + | ||
57 | + return new BaseResponse<>(response); | ||
58 | + } | ||
59 | + | ||
60 | + @RequestMapping("/getProjectStatus") | ||
61 | + @ResponseBody | ||
62 | + public BaseResponse<List<JavaProjectStatus>> getStatusInfos(String project) { | ||
63 | + try { | ||
64 | + List<JavaProjectStatus> list = javaProjectMapper.getByProject(project); | ||
65 | + return new BaseResponse<>(list); | ||
66 | + } catch (Exception e) { | ||
67 | + log.error("getStatusInfos ~", e); | ||
68 | + return null; | ||
69 | + } | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | +} |
@@ -32,7 +32,7 @@ public class ProjectStatusTask { | @@ -32,7 +32,7 @@ public class ProjectStatusTask { | ||
32 | for (Project project :ProjectOnline.getJavaList()){ | 32 | for (Project project :ProjectOnline.getJavaList()){ |
33 | try { | 33 | try { |
34 | String name = project.getName(); | 34 | String name = project.getName(); |
35 | - String commond = "ssh master@10.66.4.25 /home/master/.java_pm/java_restart.sh checkstatus mix " + name; | 35 | + String commond = "ssh master@10.66.4.25 sh /home/master/.java_pm/java_restart.sh checkstatus mix " + name; |
36 | List<String> list = exe(commond); | 36 | List<String> list = exe(commond); |
37 | for (String string : list){ | 37 | for (String string : list){ |
38 | String[] array = string.split("@@"); | 38 | String[] array = string.split("@@"); |
@@ -44,6 +44,7 @@ public class ProjectStatusTask { | @@ -44,6 +44,7 @@ public class ProjectStatusTask { | ||
44 | javaProjectStatus.setCloud(array[0]); | 44 | javaProjectStatus.setCloud(array[0]); |
45 | javaProjectStatus.setIp(array[1]); | 45 | javaProjectStatus.setIp(array[1]); |
46 | javaProjectStatus.setStatus(array[2]); | 46 | javaProjectStatus.setStatus(array[2]); |
47 | + javaProjectStatus.setLastStart(array[3]); | ||
47 | javaProjectMapper.insert(javaProjectStatus); | 48 | javaProjectMapper.insert(javaProjectStatus); |
48 | } | 49 | } |
49 | }catch (Exception e){ | 50 | }catch (Exception e){ |
-
Please register or login to post a comment