Showing
5 changed files
with
272 additions
and
15 deletions
@@ -9,19 +9,19 @@ public class RedisInfo { | @@ -9,19 +9,19 @@ public class RedisInfo { | ||
9 | 9 | ||
10 | private String connected_clients;//连接客户端数量 | 10 | private String connected_clients;//连接客户端数量 |
11 | 11 | ||
12 | - private String is_slave;//分配的内存总量 | 12 | + private int is_slave; |
13 | 13 | ||
14 | - private String used_memory_peak_human;//内存高峰值 | 14 | + private int is_run; |
15 | 15 | ||
16 | private String role;//实例角色 | 16 | private String role;//实例角色 |
17 | 17 | ||
18 | public RedisInfo(String hostIp, String connected_clients, | 18 | public RedisInfo(String hostIp, String connected_clients, |
19 | - String is_slave, String used_memory_peak_human, String role) { | 19 | + int is_slave, int is_run, String role) { |
20 | super(); | 20 | super(); |
21 | this.hostIp = hostIp; | 21 | this.hostIp = hostIp; |
22 | this.connected_clients = connected_clients; | 22 | this.connected_clients = connected_clients; |
23 | this.is_slave = is_slave; | 23 | this.is_slave = is_slave; |
24 | - this.used_memory_peak_human = used_memory_peak_human; | 24 | + this.is_run = is_run; |
25 | this.role = role; | 25 | this.role = role; |
26 | } | 26 | } |
27 | 27 |
@@ -21,26 +21,33 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { | @@ -21,26 +21,33 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { | ||
21 | 21 | ||
22 | @Override | 22 | @Override |
23 | public void redisMonitor() { | 23 | public void redisMonitor() { |
24 | - | ||
25 | - String isSlave=""; | 24 | + |
25 | + int isSlave=0; | ||
26 | + int isRun=0; | ||
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 | 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 | //检验主从同步 | 28 | //检验主从同步 |
28 | 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';"); |
29 | 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;"); |
30 | - String[] arry = redisInfo2.split("<br>"); | ||
31 | - String val = arry[0].replace("\r\n", "").trim(); | ||
32 | - if("test".equals(val)){ | ||
33 | - isSlave="同步"; | ||
34 | - }else { | ||
35 | - isSlave="不同步"; | 31 | + if(StringUtils.isNotEmpty(redisInfo2)){ |
32 | + String[] arry = redisInfo2.split("<br>"); | ||
33 | + String val = arry[0].replace("\r\n", "").trim(); | ||
34 | + if("test".equals(val)){ | ||
35 | + isSlave=1; | ||
36 | + }else { | ||
37 | + isSlave=0; | ||
38 | + } | ||
36 | } | 39 | } |
40 | + | ||
37 | if (StringUtils.isNotEmpty(redisInfo)) { | 41 | if (StringUtils.isNotEmpty(redisInfo)) { |
42 | + isRun=1; | ||
38 | RedisInfo redis = new RedisInfo("192.168.102.162", getRedisInfo( | 43 | RedisInfo redis = new RedisInfo("192.168.102.162", getRedisInfo( |
39 | - redisInfo, "connected_clients"), isSlave, getRedisInfo(redisInfo, | ||
40 | - "used_memory_peak_human"), getRedisInfo(redisInfo,"role")); | 44 | + redisInfo, "connected_clients"), isSlave, isRun, getRedisInfo(redisInfo,"role")); |
45 | + redisMapper.insert(redis); | ||
46 | + }else{ | ||
47 | + isRun=0; | ||
48 | + RedisInfo redis = new RedisInfo("192.168.102.162", "", isSlave, isRun, ""); | ||
41 | redisMapper.insert(redis); | 49 | redisMapper.insert(redis); |
42 | } | 50 | } |
43 | - | ||
44 | } | 51 | } |
45 | 52 | ||
46 | public String getRedisInfo(String redisInfo, String info) { | 53 | public String getRedisInfo(String redisInfo, String info) { |
monitor-service-middleware/src/main/java/com/monitor/middleware/redis/service/impl/Test.java
0 → 100644
1 | +package com.monitor.middleware.redis.service.impl; | ||
2 | + | ||
3 | +import java.util.ArrayList; | ||
4 | +import java.util.List; | ||
5 | + | ||
6 | +import com.model.RedisInfo; | ||
7 | + | ||
8 | +public class Test { | ||
9 | + public static void main(String[] args) { | ||
10 | + StringBuffer buff = new StringBuffer(); | ||
11 | + List<RedisInfo> list = new ArrayList<RedisInfo>(); | ||
12 | + | ||
13 | + int width1=12; | ||
14 | + int width2=8; | ||
15 | + int width21=30; | ||
16 | + int width3=4; | ||
17 | + | ||
18 | + RedisInfo redis1 = new RedisInfo(); | ||
19 | + redis1.setNodeFrom("AWS"); | ||
20 | + redis1.setNodeTo("172.31.19.49:6379"); | ||
21 | + redis1.setLevel(1); | ||
22 | + list.add(redis1); | ||
23 | + RedisInfo redis2 = new RedisInfo(); | ||
24 | + redis2.setNodeFrom("AWS"); | ||
25 | + redis2.setNodeTo("172.31.24.61:6379"); | ||
26 | + redis2.setLevel(1); | ||
27 | + list.add(redis2); | ||
28 | + RedisInfo redis3 = new RedisInfo(); | ||
29 | + redis3.setNodeFrom("172.31.19.49:6379"); | ||
30 | + redis3.setNodeTo("172.31.19.49:16379"); | ||
31 | + redis3.setLevel(2); | ||
32 | + list.add(redis3); | ||
33 | + RedisInfo redis4 = new RedisInfo(); | ||
34 | + redis4.setNodeFrom("172.31.19.49:6379"); | ||
35 | + redis4.setNodeTo("172.31.19.49:26379"); | ||
36 | + redis4.setLevel(2); | ||
37 | + list.add(redis4); | ||
38 | + RedisInfo redis5 = new RedisInfo(); | ||
39 | + redis5.setNodeFrom("172.31.24.61:6379"); | ||
40 | + redis5.setNodeTo("172.31.24.61:16379"); | ||
41 | + redis5.setLevel(2); | ||
42 | + list.add(redis5); | ||
43 | + RedisInfo redis6 = new RedisInfo(); | ||
44 | + redis6.setNodeFrom("172.31.24.61:6379"); | ||
45 | + redis6.setNodeTo("172.31.24.61:26379"); | ||
46 | + redis6.setLevel(2); | ||
47 | + list.add(redis6); | ||
48 | + RedisInfo redis7 = new RedisInfo(); | ||
49 | + redis7.setNodeFrom("AWS"); | ||
50 | + redis7.setNodeTo("AWS"); | ||
51 | + redis7.setLevel(0); | ||
52 | + redis7.setParamMonitor("AWS"); | ||
53 | + list.add(redis7); | ||
54 | + | ||
55 | + RedisInfo redis10 = new RedisInfo(); | ||
56 | + redis10.setNodeFrom("Qcloud"); | ||
57 | + redis10.setNodeTo("10.66.4.2:6379"); | ||
58 | + redis10.setLevel(1); | ||
59 | + list.add(redis10); | ||
60 | + RedisInfo redis20 = new RedisInfo(); | ||
61 | + redis20.setNodeFrom("10.66.4.2:6379"); | ||
62 | + redis20.setNodeTo("10.66.4.2:16379"); | ||
63 | + redis20.setLevel(2); | ||
64 | + list.add(redis20); | ||
65 | + RedisInfo redis30 = new RedisInfo(); | ||
66 | + redis30.setNodeFrom("10.66.4.2:6379"); | ||
67 | + redis30.setNodeTo("10.66.4.2:26379"); | ||
68 | + redis30.setLevel(2); | ||
69 | + list.add(redis30); | ||
70 | + RedisInfo redis40 = new RedisInfo(); | ||
71 | + redis40.setNodeFrom("10.66.4.2:6379"); | ||
72 | + redis40.setNodeTo("10.66.4.10:16379"); | ||
73 | + redis40.setLevel(2); | ||
74 | + list.add(redis40); | ||
75 | + RedisInfo redis50 = new RedisInfo(); | ||
76 | + redis50.setNodeFrom("10.66.4.2:6379"); | ||
77 | + redis50.setNodeTo("10.66.4.10:26379"); | ||
78 | + redis50.setLevel(2); | ||
79 | + list.add(redis50); | ||
80 | + RedisInfo redis60 = new RedisInfo(); | ||
81 | + redis60.setNodeFrom("10.66.4.2:6379"); | ||
82 | + redis60.setNodeTo("10.66.4.11:16379"); | ||
83 | + redis60.setLevel(2); | ||
84 | + list.add(redis60); | ||
85 | + RedisInfo redis70 = new RedisInfo(); | ||
86 | + redis70.setNodeFrom("Qcloud"); | ||
87 | + redis70.setNodeTo("Qcloud"); | ||
88 | + redis70.setLevel(0); | ||
89 | + list.add(redis70); | ||
90 | + | ||
91 | + buff.append("'<chart charttopmargin=\"0\" chartBottomMargin=\"0\" chartleftmargin=\"0\" chartrightmargin=\"0\" bordercolor=\"#FFFFFF\" border=\"0\" borderAlpha=\"0\" borderThickness=\"0\" canvasBorderThickness=\"0\" canvasBorderColor=\"#FFFFFF\" showFormBtn=\"0\">\\n\\\n"); | ||
92 | + buff.append("<dataset plotborderAlpha=\"0\" >\\n\\\n"); | ||
93 | + for(RedisInfo info : list){ | ||
94 | + if(info.getLevel()==0){ | ||
95 | + buff.append("<set x=\""+width1+"\" y=\"80\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" tooltext= \""+info.getParamMonitor()+"\" />\\n\\\n"); | ||
96 | + width1+=18; | ||
97 | + }else if(info.getLevel()==1){ | ||
98 | + if(info.getId().equals("Qcloud")){ | ||
99 | + buff.append("<set x=\""+width21+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n"); | ||
100 | + width21+=8; | ||
101 | + }else{ | ||
102 | + buff.append("<set x=\""+width2+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n"); | ||
103 | + width2+=8; | ||
104 | + } | ||
105 | + }else if(info.getLevel()==2){ | ||
106 | + buff.append("<set x=\""+width3+"\" y=\"55\" width=\"55\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n"); | ||
107 | + width3+=4; | ||
108 | + } | ||
109 | + } | ||
110 | + buff.append("</dataset>\\n\\\n"); | ||
111 | + buff.append("<connectors color=\"83C6E1\" stdThickness=\"8\">\\n\\\n"); | ||
112 | + for(RedisInfo info : list){ | ||
113 | + buff.append("<connector strength=\"0.45\" from=\""+info.getNodeFrom()+"\" to=\""+info.getNodeTo()+"\" arrowAtStart=\"0\" arrowAtEnd=\"0\"/>\\n\\\n"); | ||
114 | + } | ||
115 | + buff.append("</connectors>\\n\\\n</chart>'"); | ||
116 | + buff.toString(); | ||
117 | + System.out.println(buff.toString()); | ||
118 | + } | ||
119 | + | ||
120 | + | ||
121 | +} |
1 | +package com.model; | ||
2 | + | ||
3 | +public class RedisInfo { | ||
4 | + | ||
5 | + private String id; | ||
6 | + private String alias; | ||
7 | + private String hostIp; | ||
8 | + private String port; | ||
9 | + private int level; | ||
10 | + private String nodeFrom; | ||
11 | + private String nodeTo; | ||
12 | + private String paramMonitor; | ||
13 | + private int state; | ||
14 | + private int cloudType; | ||
15 | + private String createTime; | ||
16 | + private String updateTime; | ||
17 | + | ||
18 | + public String getId() { | ||
19 | + return id; | ||
20 | + } | ||
21 | + | ||
22 | + public void setId(String id) { | ||
23 | + this.id = id; | ||
24 | + } | ||
25 | + | ||
26 | + public String getAlias() { | ||
27 | + return alias; | ||
28 | + } | ||
29 | + | ||
30 | + public void setAlias(String alias) { | ||
31 | + this.alias = alias; | ||
32 | + } | ||
33 | + | ||
34 | + public String getHostIp() { | ||
35 | + return hostIp; | ||
36 | + } | ||
37 | + | ||
38 | + public void setHostIp(String hostIp) { | ||
39 | + this.hostIp = hostIp; | ||
40 | + } | ||
41 | + | ||
42 | + public String getPort() { | ||
43 | + return port; | ||
44 | + } | ||
45 | + | ||
46 | + public void setPort(String port) { | ||
47 | + this.port = port; | ||
48 | + } | ||
49 | + | ||
50 | + public int getLevel() { | ||
51 | + return level; | ||
52 | + } | ||
53 | + | ||
54 | + public void setLevel(int level) { | ||
55 | + this.level = level; | ||
56 | + } | ||
57 | + | ||
58 | + public String getNodeFrom() { | ||
59 | + return nodeFrom; | ||
60 | + } | ||
61 | + | ||
62 | + public void setNodeFrom(String nodeFrom) { | ||
63 | + this.nodeFrom = nodeFrom; | ||
64 | + } | ||
65 | + | ||
66 | + public String getNodeTo() { | ||
67 | + return nodeTo; | ||
68 | + } | ||
69 | + | ||
70 | + public void setNodeTo(String nodeTo) { | ||
71 | + this.nodeTo = nodeTo; | ||
72 | + } | ||
73 | + | ||
74 | + public String getParamMonitor() { | ||
75 | + return paramMonitor; | ||
76 | + } | ||
77 | + | ||
78 | + public void setParamMonitor(String paramMonitor) { | ||
79 | + this.paramMonitor = paramMonitor; | ||
80 | + } | ||
81 | + | ||
82 | + public int getState() { | ||
83 | + return state; | ||
84 | + } | ||
85 | + | ||
86 | + public void setState(int state) { | ||
87 | + this.state = state; | ||
88 | + } | ||
89 | + | ||
90 | + public int getCloudType() { | ||
91 | + return cloudType; | ||
92 | + } | ||
93 | + | ||
94 | + public void setCloudType(int cloudType) { | ||
95 | + this.cloudType = cloudType; | ||
96 | + } | ||
97 | + | ||
98 | + public String getCreateTime() { | ||
99 | + return createTime; | ||
100 | + } | ||
101 | + | ||
102 | + public void setCreateTime(String createTime) { | ||
103 | + this.createTime = createTime; | ||
104 | + } | ||
105 | + | ||
106 | + public String getUpdateTime() { | ||
107 | + return updateTime; | ||
108 | + } | ||
109 | + | ||
110 | + public void setUpdateTime(String updateTime) { | ||
111 | + this.updateTime = updateTime; | ||
112 | + } | ||
113 | + | ||
114 | +} |
1 | +package com.monitor.mysql.mapper; | ||
2 | + | ||
3 | +import java.util.List; | ||
4 | + | ||
5 | +import com.model.RedisInfo; | ||
6 | + | ||
7 | +public interface RedisMonitorMapper { | ||
8 | + | ||
9 | + List<RedisInfo> selectRedisMonitor(); | ||
10 | + | ||
11 | + List<RedisInfo> selectRedisMonitorByLevel(int level); | ||
12 | + | ||
13 | + int updateByPrimaryKey(RedisInfo redis); | ||
14 | + | ||
15 | +} |
-
Please register or login to post a comment