...
|
...
|
@@ -3,29 +3,28 @@ package com.monitor.middleware.redis.service.impl; |
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.monitor.common.util.SSHRedis;
|
|
|
import com.monitor.influxdb.mapper.IRedisMapper;
|
|
|
import com.monitor.influxdb.model.RedisInfo;
|
|
|
import com.monitor.middleware.redis.service.IRedisMonitorService;
|
|
|
|
|
|
@Service
|
|
|
public class RedisMonitorServiceImpl implements IRedisMonitorService {
|
|
|
|
|
|
Logger log = LoggerFactory.getLogger(RedisMonitorServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
IRedisMapper redisMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void redisMonitor() {
|
|
|
|
|
|
//TODO
|
|
|
//1、getallredis 分配给redis的总内存通过”config get maxmemory“取出然后算出占用百分比,需要用进度条展示(领导要求)
|
|
|
//2、level=2 twemproxy取这个值,update更新需要取的值: "curr_connections":2,"client_eof":1959, "requests":2423810, "request_bytes":487387692, "responses":2423810, "response_bytes":20334901
|
|
|
//3、遍历level=3
|
|
|
|
|
|
|
|
|
StringBuffer buff = new StringBuffer();
|
|
|
String isSlave="";
|
|
|
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;");
|
...
|
...
|
@@ -38,19 +37,16 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { |
|
|
isSlave="不同步";
|
|
|
}
|
|
|
}
|
|
|
buff.append("角色:"+getRedisInfo(redisInfo,"role")+";");
|
|
|
buff.append("用量:"+getRedisInfo(redisInfo,"role")+";");
|
|
|
|
|
|
if (StringUtils.isNotEmpty(redisInfo)) {
|
|
|
isRun=1;
|
|
|
RedisInfo redis = new RedisInfo("192.168.102.162", getRedisInfo(
|
|
|
redisInfo, "connected_clients"), isSlave, isRun, getRedisInfo(redisInfo,"role"));
|
|
|
redisMapper.insert(redis);
|
|
|
if(StringUtils.isEmpty(redisInfo)){
|
|
|
buff.append("状态:宕机;");
|
|
|
}else{
|
|
|
isRun=0;
|
|
|
RedisInfo redis = new RedisInfo("192.168.102.162", "", isSlave, isRun, "");
|
|
|
redisMapper.insert(redis);
|
|
|
buff.append("角色:"+getRedisInfo(redisInfo,"role")+";");
|
|
|
buff.append("用量:"+getRedisInfo(redisInfo,"used_memory_rss")+";");
|
|
|
buff.append("内存碎片比率:"+getRedisInfo(redisInfo,"mem_fragmentation_ratio")+";");
|
|
|
buff.append("主从同步:"+isSlave+";");
|
|
|
}
|
|
|
buff.toString();
|
|
|
System.out.println(buff.toString());
|
|
|
}
|
|
|
|
|
|
public String getRedisInfo(String redisInfo, String info) {
|
...
|
...
|
|