Authored by jack

Merge branch 'dev_memcache'

... ... @@ -15,4 +15,6 @@ public interface MemConstants {
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<>();
}
... ...
... ... @@ -159,4 +159,8 @@ public class MemcachedCtrl {
}
}
@RequestMapping(value = "/updateTime")
public String queryUpdateTime() {
return MemConstants.MEMCACHED_UPDATE_TIME.get("memcachedUpdateTime");
}
}
\ No newline at end of file
... ...
... ... @@ -6,9 +6,9 @@ import com.monitor.cmdb.service.IMObjectInfoService;
import com.monitor.cmdb.service.ITypeInfoService;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.AlarmMsgService;
import com.monitor.common.util.DateTimeUtil;
import com.monitor.middleware.memcached.constant.MemConstants;
import com.monitor.middleware.memcached.model.MemcachedInfo;
import lombok.Getter;
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.XMemcachedClient;
import net.rubyeye.xmemcached.exception.MemcachedException;
... ... @@ -29,6 +29,8 @@ import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.TimeoutException;
import static com.monitor.middleware.memcached.constant.MemConstants.MEMCACHED_UPDATE_TIME;
/**
* Created by yoho on 2016/10/11.
*/
... ... @@ -88,6 +90,11 @@ public class MemcachedMonitorImpl {
result = client.getStats();
LOGGER.debug("MemcachedMonitorImpl.doMonitor:get memcached status is {}", result);
client.shutdown();
//校验是否所有memcached都返回状态,对未返回状态的memcached短信告警
checkAllStatus(monitorUrl.toString().trim(), result);
processAllStatus(result);
} catch (IOException e) {
LOGGER.error("MemcachedMonitorImpl.doMonitor:creatr/shutdown memcached client occurs Exception: ", e.getMessage());
alarmMsgService.sendSms("Memcached", "Can not connect to Memcached " + monitorUrl.toString() + " .", snsMobileConfig.getBaseMobile());
... ... @@ -100,11 +107,10 @@ public class MemcachedMonitorImpl {
} catch (TimeoutException e) {
LOGGER.error("MemcachedMonitorImpl.doMonitor:get memcached status occurs Exception: ", e.getMessage());
alarmMsgService.sendSms("Memcached", "Can not get Memcached status" + monitorUrl.toString() + " .", snsMobileConfig.getBaseMobile());
}catch(Exception e){
LOGGER.error("MemcachedMonitorImpl.doMonitor:occurs Exception: ", e.getMessage());
}
//校验是否所有memcached都返回状态,对未返回状态的memcached短信告警
checkAllStatus(monitorUrl.toString().trim(), result);
processAllStatus(result);
}
/**
... ... @@ -149,6 +155,7 @@ public class MemcachedMonitorImpl {
info.setUpTime(uptime / (60 * 60 * 24) + " Days");
info.setUseMemory(new DecimalFormat("0.00").format(bytes * 1.0 / 1024 / 1024 / 1024) + " G");
MemConstants.MEMCACHED_INFO_MAP.put(url, info);
MemConstants.MEMCACHED_UPDATE_TIME.put("memcachedUpdateTime",DateTimeUtil.unix2time(System.currentTimeMillis()));
LOGGER.info("MemConstants.MEMCACHED_INFO_MAP all key is {}",MemConstants.MEMCACHED_INFO_MAP.keySet());
}
}
... ...