Authored by qinchao

redis监控

... ... @@ -12,13 +12,6 @@ import java.util.concurrent.ConcurrentHashMap;
* Created by yoho on 2016/10/11.
*/
public interface MemConstants {
/* //key: "ip:port"
Map<String, MemcachedInfo> MEMCACHED_INFO_MAP = new ConcurrentHashMap<>();
Map<String, String> MEMCACHED_NAME_MAP = new ConcurrentHashMap<>(); //用于缓存memcached的l1、l2*/
Map<String, String> MEMCACHED_UPDATE_TIME = new ConcurrentHashMap<>();
Map<String, XMemcachedClient> MEMCACHED_CLIENT_MAP = new ConcurrentHashMap<>();
Map<String, List<String>> MEMCACHED_RELATE_MAP = new ConcurrentHashMap<>();
... ...
... ... @@ -39,7 +39,8 @@ public class MemcachedMonitService {
updateTime=System.currentTimeMillis();
//查询逻辑分组 memcached
Map<String, List<MObjectInfo>> memcachedMap = queryAllMoListByLogic("memcached");
TypeInfo parentTypeInfo = typeInfoService.getTypeByMobjectPathArray("YOHO,middleware,memcached".split(","));
Map<String, List<MObjectInfo>> memcachedMap = queryAllMoListByLogic(parentTypeInfo);
if (memcachedMap.isEmpty()) {
//要监控内容为空,则清空map
... ... @@ -47,6 +48,16 @@ public class MemcachedMonitService {
return;
}
if(MemConstants.MEMCACHED_RELATE_MAP.size()>0){
for(String key:MemConstants.MEMCACHED_RELATE_MAP.keySet()){
//把被移除的对象从缓存中清除 ,map里面的内容会重新的put ,所有不用关心
if(!memcachedMap.keySet().contains(key)){
MemConstants.MEMCACHED_RELATE_MAP.remove(key);
}
}
}
ExecutorService executorService = Executors.newFixedThreadPool(memcachedMap.size());
for (Map.Entry<String, List<MObjectInfo>> entry : memcachedMap.entrySet()) {
... ... @@ -55,12 +66,7 @@ public class MemcachedMonitService {
}
for(String key:MemConstants.MEMCACHED_RELATE_MAP.keySet()){
//把被移除的对象从缓存中清除
if(!memcachedMap.keySet().contains(key)){
MemConstants.MEMCACHED_RELATE_MAP.remove(key);
}
}
executorService.shutdown();
}
... ... @@ -71,25 +77,20 @@ public class MemcachedMonitService {
*
* @return not null
*/
public Map<String, List<MObjectInfo>> queryAllMoListByLogic(String parentName) {
public Map<String, List<MObjectInfo>> queryAllMoListByLogic(TypeInfo parentTypeInfo) {
Map<String, List<MObjectInfo>> serversMap = new HashMap<>();
RedisMonitService redisMonitService = SpringContextUtils.getBeanByClass(RedisMonitService.class);
TypeInfo parentTypeInfo = redisMonitService.queryParentType(parentName);
//未找到 父类型 memcached
if (null == parentTypeInfo) {
DEBUG.warn("Not found parent type in memcached...");
return serversMap;
}
RedisMonitService redisMonitService = SpringContextUtils.getBeanByClass(RedisMonitService.class);
//查询 memcached下的子类型(逻辑分组)
List<TypeInfo> childTypeList = redisMonitService.queryChildType(parentTypeInfo);
Set<String> currentKeys=new HashSet<>();
//Set<String> currentKeys=new HashSet<>();
for (TypeInfo typeInfo : childTypeList) {
List<MObjectInfo> memcacheList = redisMonitService.queryMoByType(typeInfo);
... ... @@ -98,35 +99,18 @@ public class MemcachedMonitService {
if(!memcacheList.isEmpty())
{
String logicName = typeInfo.getTypeName();
currentKeys.add(logicName);
//currentKeys.add(logicName);
serversMap.put(logicName, memcacheList);
/*List<MObjectInfo> sMemcacheList = serversMap.get(logicName);
//该类型下没有查询过,则新插入
if (null == sMemcacheList) {
serversMap.put(logicName, memcacheList);
}
//否则,更新已有的列表
else {
sMemcacheList.addAll(memcacheList);
}*/
}
}
//把已经被去掉的不再监控对象的,从缓存中移除
/*//把已经被去掉的不再监控对象的,从缓存中移除
for(String key:serversMap.keySet()){
if(!currentKeys.contains(key)){
serversMap.remove(key);
}
}
*/
return serversMap;
}
... ...
... ... @@ -43,11 +43,10 @@ public class RedisMonitService {
updateTime = System.currentTimeMillis();
Map<String, List<MObjectInfo>> redisMap = new HashMap<>();
redisMap = queryAllMoListByLogic("redis");
TypeInfo typeInfo=typeInfoService.getTypeByMobjectPathArray("YOHO,middleware,redis".split(","));
Map<String, List<MObjectInfo>> redisMap = queryAllMoListByLogic(typeInfo);
if (redisMap.isEmpty()) {
Constants.TWEMPROXY_INFO_MAP.clear();//清空
return;
}
... ... @@ -102,8 +101,7 @@ public class RedisMonitService {
*
* @return not null
*/
public Map<String, List<MObjectInfo>> queryAllMoListByLogic(String parentName) {
TypeInfo parentTypeInfo = queryParentType(parentName);
public Map<String, List<MObjectInfo>> queryAllMoListByLogic(TypeInfo parentTypeInfo) {
Map<String, List<MObjectInfo>> serversMap = new HashMap<>();
//未找到 父类型 redis
... ... @@ -154,36 +152,6 @@ public class RedisMonitService {
}
public TypeInfo queryParentType(String parentName) {
List<TypeInfo> typeList = new ArrayList<>();
TypeInfo parentTypeInfo = null;
try {
typeList = typeInfoService.queryAllTypesInfo();
} catch (Exception e) {
DEBUG.error("Failed to query parent redis type...", e);
return parentTypeInfo;
}
for (TypeInfo typeInfo : typeList) {
//查找redis监控对象 父节点
if (StringUtils.equals(parentName, typeInfo.getTypeName()) && 0 == typeInfo.getTypeIsLeaf()) {
parentTypeInfo = typeInfo;
break;
}
}
return parentTypeInfo;
}
/**
* 查询所有子类型
*
... ...
... ... @@ -52,7 +52,7 @@ public class OneTask implements Callable {
}
}
/*for (MObjectInfo mo : moList) {
for (MObjectInfo mo : moList) {
if (mo.getMoName().startsWith("cluster")) {
... ... @@ -62,7 +62,7 @@ public class OneTask implements Callable {
relastionRedis.add(clusterJob.getJedisUrl());
}
}*/
}
for (MObjectInfo mo : moList) {
... ...
... ... @@ -43,7 +43,7 @@ public class OneClusterJob extends OneJob {
private void handleConnected(Jedis jedis) {
Map<String, String> redisInfoMap = buildInfoMap(jedis);
RedisInfo redisInfo = buildRedisInfo(redisInfoMap);
testRedis(jedis, redisInfo);
//testRedis(jedis, redisInfo);
try {
queryRedisVmInfo(redisInfo);
} catch (Exception e) {
... ...