use of com.sohu.cache.entity.InstanceAlert in project cachecloud by sohutv.
the class InstanceAlertValueServiceImpl method generateInstanceValueResult.
/**
* 比较info的没有一个属性
*
* @param instanceAlertList
* @param infoKey
* @param infoValue
* @return
*/
private InstanceAlertValueResult generateInstanceValueResult(List<InstanceAlert> instanceAlertList, String infoKey, Object infoValue, String ip, int port) {
for (InstanceAlert instanceAlert : instanceAlertList) {
String alertConfigKey = instanceAlert.getConfigKey();
if (StringUtils.isBlank(infoKey) || StringUtils.isBlank(alertConfigKey) || !infoKey.equals(alertConfigKey)) {
continue;
}
String alertInfoValue = instanceAlert.getAlertValue();
// 比较类型 1和-1是大于和小于
int compareType = instanceAlert.getCompareType();
if (compareType == CompareTypeEnum.SMALLER.getValue() || compareType == CompareTypeEnum.BIGGER.getValue()) {
double infoValueDouble = NumberUtils.toDouble(infoValue.toString());
double alertInfoValueDouble = NumberUtils.toDouble(alertInfoValue);
if ((compareType == -1 && infoValueDouble < alertInfoValueDouble) || (compareType == 1 && infoValueDouble > alertInfoValueDouble)) {
return generateByInstanceStat(instanceAlert, infoKey, infoValue, ip, port);
}
} else // 比较类型为0,表示等于
if (compareType == CompareTypeEnum.EQUAL.getValue() && infoValue.toString().equals(alertInfoValue)) {
return generateByInstanceStat(instanceAlert, infoKey, infoValue, ip, port);
} else // 比较类型为2,表示不等于
if (compareType == CompareTypeEnum.NOT_EQUAL.getValue() && !infoValue.toString().equals(alertInfoValue)) {
return generateByInstanceStat(instanceAlert, infoKey, infoValue, ip, port);
}
}
return null;
}
use of com.sohu.cache.entity.InstanceAlert in project cachecloud by sohutv.
the class InstanceAlertValueServiceImpl method monitorLastMinuteAllInstanceInfo.
@Override
public int monitorLastMinuteAllInstanceInfo() {
List<InstanceAlertValueResult> resultList = new ArrayList<InstanceAlertValueResult>();
// 固定值
List<InstanceAlert> staticInstanceAlertList = instanceAlertValueDao.getByValueType(ValueTypeEnum.STATIC.getValue(), StatusEnum.YES.getValue());
// 差值
List<InstanceAlert> diffInstanceAlertList = instanceAlertValueDao.getByValueType(ValueTypeEnum.DIFF.getValue(), StatusEnum.YES.getValue());
// 取上1分钟Redis实例统计信息
Date date = new Date();
Date beginTime = DateUtils.addMinutes(date, -2);
Date endTime = DateUtils.addMinutes(date, -1);
// 上一分钟Redis实例信息统计
long start = System.currentTimeMillis();
List<StandardStats> standardStatsList = instanceStatsDao.getStandardStatsByCreateTime(beginTime, endTime, "redis");
long cost = System.currentTimeMillis() - start;
if (cost > 2000) {
logger.warn("getStandardStatsByCreateTime {} to {} costtime is {} ms", beginTime, endTime, cost);
}
// 遍历所有Redis实例统计信息,和预设阀值对比报警
for (StandardStats standardStats : standardStatsList) {
try {
if (standardStats == null) {
continue;
}
// 固定值
if (CollectionUtils.isNotEmpty(staticInstanceAlertList)) {
List<InstanceAlertValueResult> staticInstanceAlertResultList = checkStaticInstanceInfoAlert(standardStats, staticInstanceAlertList);
resultList.addAll(staticInstanceAlertResultList);
}
// 差值
if (CollectionUtils.isNotEmpty(diffInstanceAlertList)) {
List<InstanceAlertValueResult> diffInstanceAlertResultList = checkDiffInstanceInfoAlert(standardStats, diffInstanceAlertList);
if (CollectionUtils.isNotEmpty(diffInstanceAlertResultList)) {
resultList.addAll(diffInstanceAlertResultList);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
// 最终报警
sendInstanceAlertEmail(beginTime, endTime, resultList);
return standardStatsList.size();
}
use of com.sohu.cache.entity.InstanceAlert in project cachecloud by sohutv.
the class InstanceAlertValueController method update.
/**
* 修改配置
*/
@RequestMapping(value = "/update")
public ModelAndView update(HttpServletRequest request, HttpServletResponse response, Model model) {
AppUser appUser = getUserInfo(request);
String configKey = request.getParameter("configKey");
String alertValue = request.getParameter("alertValue");
int compareType = NumberUtils.toInt(request.getParameter("compareType"));
int valueType = NumberUtils.toInt(request.getParameter("valueType"));
String info = request.getParameter("info");
int status = NumberUtils.toInt(request.getParameter("status"), -1);
if (StringUtils.isBlank(configKey) || status > 1 || status < 0) {
model.addAttribute("status", SuccessEnum.FAIL.value());
model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + ",configKey=" + configKey + ",alertValue=" + alertValue + ",status=" + status);
return new ModelAndView("");
}
//开始修改
logger.warn("user {} want to change instance alert configKey={}, alertValue={}, info={}, status={}", appUser.getName(), configKey, alertValue, info, status);
SuccessEnum successEnum;
InstanceAlert instanceAlert = instanceAlertValueService.getByConfigKey(configKey);
try {
instanceAlert.setAlertValue(alertValue);
instanceAlert.setValueType(valueType);
instanceAlert.setInfo(info);
instanceAlert.setStatus(status);
instanceAlert.setCompareType(compareType);
instanceAlertValueService.saveOrUpdate(instanceAlert);
successEnum = SuccessEnum.SUCCESS;
} catch (Exception e) {
successEnum = SuccessEnum.FAIL;
model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
logger.error(e.getMessage(), e);
}
logger.warn("user {} want to change instance alert configKey={}, alertValue={}, info={}, status={}, result is {}", appUser.getName(), configKey, alertValue, info, status, successEnum.value());
model.addAttribute("status", successEnum.value());
return new ModelAndView("");
}
use of com.sohu.cache.entity.InstanceAlert in project cachecloud by sohutv.
the class InstanceAlertValueController method add.
/**
* 添加配置
*/
@RequestMapping(value = "/add")
public ModelAndView add(HttpServletRequest request, HttpServletResponse response, Model model) {
AppUser appUser = getUserInfo(request);
InstanceAlert instanceAlert = getInstanceAlert(request);
if (StringUtils.isBlank(instanceAlert.getConfigKey())) {
model.addAttribute("status", SuccessEnum.FAIL.value());
model.addAttribute("message", ErrorMessageEnum.PARAM_ERROR_MSG.getMessage() + "configKey=" + instanceAlert.getConfigKey());
return new ModelAndView("");
}
logger.warn("user {} want to add instance alert, configKey is {}, alertValue is {}, info is {}, orderId is {}", appUser.getName(), instanceAlert.getConfigKey(), instanceAlert.getAlertValue(), instanceAlert.getInfo(), instanceAlert.getOrderId());
SuccessEnum successEnum;
try {
instanceAlertValueService.saveOrUpdate(instanceAlert);
successEnum = SuccessEnum.SUCCESS;
} catch (Exception e) {
successEnum = SuccessEnum.FAIL;
model.addAttribute("message", ErrorMessageEnum.INNER_ERROR_MSG.getMessage());
logger.error(e.getMessage(), e);
}
logger.warn("user {} want to add instance alert, configKey is {}, alertValue is {}, info is {}, orderId is {}, result is {}", appUser.getName(), instanceAlert.getConfigKey(), instanceAlert.getAlertValue(), instanceAlert.getInfo(), instanceAlert.getOrderId(), successEnum.info());
model.addAttribute("status", successEnum.value());
return new ModelAndView("");
}
use of com.sohu.cache.entity.InstanceAlert in project cachecloud by sohutv.
the class InstanceAlertValueController method getInstanceAlert.
/**
* 使用最简单的request生成InstanceAlert对象
*
* @return
*/
private InstanceAlert getInstanceAlert(HttpServletRequest request) {
String configKey = request.getParameter("configKey");
String alertValue = request.getParameter("alertValue");
String info = request.getParameter("info");
int compareType = NumberUtils.toInt(request.getParameter("compareType"));
int valueType = NumberUtils.toInt(request.getParameter("valueType"));
int orderId = NumberUtils.toInt(request.getParameter("orderId"));
InstanceAlert instanceAlert = new InstanceAlert();
instanceAlert.setConfigKey(configKey);
instanceAlert.setAlertValue(alertValue);
instanceAlert.setValueType(valueType);
instanceAlert.setCompareType(compareType);
instanceAlert.setInfo(info);
instanceAlert.setOrderId(orderId);
instanceAlert.setStatus(1);
return instanceAlert;
}
Aggregations