Authored by fanzelei

redis

... ... @@ -9,19 +9,19 @@ public class RedisInfo {
private String connected_clients;//连接客户端数量
private String is_slave;//分配的内存总量
private int is_slave;
private String used_memory_peak_human;//内存高峰值
private int is_run;
private String role;//实例角色
public RedisInfo(String hostIp, String connected_clients,
String is_slave, String used_memory_peak_human, String role) {
int is_slave, int is_run, String role) {
super();
this.hostIp = hostIp;
this.connected_clients = connected_clients;
this.is_slave = is_slave;
this.used_memory_peak_human = used_memory_peak_human;
this.is_run = is_run;
this.role = role;
}
... ...
... ... @@ -21,26 +21,33 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService {
@Override
public void redisMonitor() {
String isSlave="";
int isSlave=0;
int isRun=0;
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;");
//检验主从同步
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';");
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;");
String[] arry = redisInfo2.split("<br>");
String val = arry[0].replace("\r\n", "").trim();
if("test".equals(val)){
isSlave="同步";
}else {
isSlave="不同步";
if(StringUtils.isNotEmpty(redisInfo2)){
String[] arry = redisInfo2.split("<br>");
String val = arry[0].replace("\r\n", "").trim();
if("test".equals(val)){
isSlave=1;
}else {
isSlave=0;
}
}
if (StringUtils.isNotEmpty(redisInfo)) {
isRun=1;
RedisInfo redis = new RedisInfo("192.168.102.162", getRedisInfo(
redisInfo, "connected_clients"), isSlave, getRedisInfo(redisInfo,
"used_memory_peak_human"), getRedisInfo(redisInfo,"role"));
redisInfo, "connected_clients"), isSlave, isRun, getRedisInfo(redisInfo,"role"));
redisMapper.insert(redis);
}else{
isRun=0;
RedisInfo redis = new RedisInfo("192.168.102.162", "", isSlave, isRun, "");
redisMapper.insert(redis);
}
}
public String getRedisInfo(String redisInfo, String info) {
... ...
package com.monitor.middleware.redis.service.impl;
import java.util.ArrayList;
import java.util.List;
import com.model.RedisInfo;
public class Test {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer();
List<RedisInfo> list = new ArrayList<RedisInfo>();
int width1=12;
int width2=8;
int width21=30;
int width3=4;
RedisInfo redis1 = new RedisInfo();
redis1.setNodeFrom("AWS");
redis1.setNodeTo("172.31.19.49:6379");
redis1.setLevel(1);
list.add(redis1);
RedisInfo redis2 = new RedisInfo();
redis2.setNodeFrom("AWS");
redis2.setNodeTo("172.31.24.61:6379");
redis2.setLevel(1);
list.add(redis2);
RedisInfo redis3 = new RedisInfo();
redis3.setNodeFrom("172.31.19.49:6379");
redis3.setNodeTo("172.31.19.49:16379");
redis3.setLevel(2);
list.add(redis3);
RedisInfo redis4 = new RedisInfo();
redis4.setNodeFrom("172.31.19.49:6379");
redis4.setNodeTo("172.31.19.49:26379");
redis4.setLevel(2);
list.add(redis4);
RedisInfo redis5 = new RedisInfo();
redis5.setNodeFrom("172.31.24.61:6379");
redis5.setNodeTo("172.31.24.61:16379");
redis5.setLevel(2);
list.add(redis5);
RedisInfo redis6 = new RedisInfo();
redis6.setNodeFrom("172.31.24.61:6379");
redis6.setNodeTo("172.31.24.61:26379");
redis6.setLevel(2);
list.add(redis6);
RedisInfo redis7 = new RedisInfo();
redis7.setNodeFrom("AWS");
redis7.setNodeTo("AWS");
redis7.setLevel(0);
redis7.setParamMonitor("AWS");
list.add(redis7);
RedisInfo redis10 = new RedisInfo();
redis10.setNodeFrom("Qcloud");
redis10.setNodeTo("10.66.4.2:6379");
redis10.setLevel(1);
list.add(redis10);
RedisInfo redis20 = new RedisInfo();
redis20.setNodeFrom("10.66.4.2:6379");
redis20.setNodeTo("10.66.4.2:16379");
redis20.setLevel(2);
list.add(redis20);
RedisInfo redis30 = new RedisInfo();
redis30.setNodeFrom("10.66.4.2:6379");
redis30.setNodeTo("10.66.4.2:26379");
redis30.setLevel(2);
list.add(redis30);
RedisInfo redis40 = new RedisInfo();
redis40.setNodeFrom("10.66.4.2:6379");
redis40.setNodeTo("10.66.4.10:16379");
redis40.setLevel(2);
list.add(redis40);
RedisInfo redis50 = new RedisInfo();
redis50.setNodeFrom("10.66.4.2:6379");
redis50.setNodeTo("10.66.4.10:26379");
redis50.setLevel(2);
list.add(redis50);
RedisInfo redis60 = new RedisInfo();
redis60.setNodeFrom("10.66.4.2:6379");
redis60.setNodeTo("10.66.4.11:16379");
redis60.setLevel(2);
list.add(redis60);
RedisInfo redis70 = new RedisInfo();
redis70.setNodeFrom("Qcloud");
redis70.setNodeTo("Qcloud");
redis70.setLevel(0);
list.add(redis70);
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");
buff.append("<dataset plotborderAlpha=\"0\" >\\n\\\n");
for(RedisInfo info : list){
if(info.getLevel()==0){
buff.append("<set x=\""+width1+"\" y=\"80\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" tooltext= \""+info.getParamMonitor()+"\" />\\n\\\n");
width1+=18;
}else if(info.getLevel()==1){
if(info.getId().equals("Qcloud")){
buff.append("<set x=\""+width21+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width21+=8;
}else{
buff.append("<set x=\""+width2+"\" y=\"70\" width=\"120\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width2+=8;
}
}else if(info.getLevel()==2){
buff.append("<set x=\""+width3+"\" y=\"55\" width=\"55\" height=\"40\" name=\""+info.getNodeFrom()+"\" color=\"62D0FE\" id=\""+info.getNodeTo()+"\" />\\n\\\n");
width3+=4;
}
}
buff.append("</dataset>\\n\\\n");
buff.append("<connectors color=\"83C6E1\" stdThickness=\"8\">\\n\\\n");
for(RedisInfo info : list){
buff.append("<connector strength=\"0.45\" from=\""+info.getNodeFrom()+"\" to=\""+info.getNodeTo()+"\" arrowAtStart=\"0\" arrowAtEnd=\"0\"/>\\n\\\n");
}
buff.append("</connectors>\\n\\\n</chart>'");
buff.toString();
System.out.println(buff.toString());
}
}
... ...
package com.model;
public class RedisInfo {
private String id;
private String alias;
private String hostIp;
private String port;
private int level;
private String nodeFrom;
private String nodeTo;
private String paramMonitor;
private int state;
private int cloudType;
private String createTime;
private String updateTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getHostIp() {
return hostIp;
}
public void setHostIp(String hostIp) {
this.hostIp = hostIp;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public String getNodeFrom() {
return nodeFrom;
}
public void setNodeFrom(String nodeFrom) {
this.nodeFrom = nodeFrom;
}
public String getNodeTo() {
return nodeTo;
}
public void setNodeTo(String nodeTo) {
this.nodeTo = nodeTo;
}
public String getParamMonitor() {
return paramMonitor;
}
public void setParamMonitor(String paramMonitor) {
this.paramMonitor = paramMonitor;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public int getCloudType() {
return cloudType;
}
public void setCloudType(int cloudType) {
this.cloudType = cloudType;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}
... ...
package com.monitor.mysql.mapper;
import java.util.List;
import com.model.RedisInfo;
public interface RedisMonitorMapper {
List<RedisInfo> selectRedisMonitor();
List<RedisInfo> selectRedisMonitorByLevel(int level);
int updateByPrimaryKey(RedisInfo redis);
}
\ No newline at end of file
... ...