use of com.sohu.cache.entity.InstanceAlertValueResult in project cachecloud by sohutv.
the class InstanceAlertValueServiceImpl method sendInstanceAlertEmail.
/**
* 发送邮件
* @param instanceAlertValueResultList
*/
private void sendInstanceAlertEmail(Date beginTime, Date endTime, List<InstanceAlertValueResult> instanceAlertValueResultList) {
if (CollectionUtils.isEmpty(instanceAlertValueResultList)) {
return;
}
Collections.sort(instanceAlertValueResultList, new Comparator<InstanceAlertValueResult>() {
@Override
public int compare(InstanceAlertValueResult o1, InstanceAlertValueResult o2) {
return (int) (o1.getAppId() - o2.getAppId());
}
});
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String emailTitle = String.format("Redis实例分钟报警(%s~%s)", sdf.format(beginTime), sdf.format(endTime));
String emailContent = VelocityUtils.createText(velocityEngine, null, null, null, instanceAlertValueResultList, "instanceAlert.vm", "UTF-8");
emailComponent.sendMailToAdmin(emailTitle, emailContent.toString());
}
use of com.sohu.cache.entity.InstanceAlertValueResult in project cachecloud by sohutv.
the class InstanceAlertValueServiceImpl method generateByInstanceStat.
/**
* 生成实例报警结果
*
* @param instanceAlert
* @param infoKey
* @param infoValue
* @param ip
* @param port
* @return
*/
private InstanceAlertValueResult generateByInstanceStat(InstanceAlert instanceAlert, String infoKey, Object infoValue, String ip, int port) {
//根据infoKey决定单位等
String alertValue = instanceAlert.getAlertValue();
String infoValueStr = infoValue.toString();
//网络输入输出流量、客户端最大输入buffer、aof文件当前尺寸
if ("total_net_output_bytes".equals(infoKey) || "total_net_input_bytes".equals(infoKey) || "client_biggest_input_buf".equals(infoKey) || "aof_current_size".equals(infoKey)) {
// 以MB为单位显示
alertValue = changeByteToMB(alertValue);
infoValueStr = changeByteToMB(infoValueStr);
}
InstanceAlertValueResult instanceAlertValueResult = new InstanceAlertValueResult();
instanceAlertValueResult.setAlertValue(alertValue);
instanceAlertValueResult.setCompareType(instanceAlert.getCompareType());
instanceAlertValueResult.setValueType(instanceAlert.getValueType());
instanceAlertValueResult.setConfigKey(infoKey);
instanceAlertValueResult.setCurrentValue(infoValueStr);
instanceAlertValueResult.setIp(ip);
instanceAlertValueResult.setPort(port);
InstanceInfo instanceInfo = instanceDao.getInstByIpAndPort(ip, port);
if (instanceInfo != null) {
long appId = instanceInfo.getAppId();
instanceAlertValueResult.setAppId(appId);
instanceAlertValueResult.setAppDesc(appService.getByAppId(appId));
}
return instanceAlertValueResult;
}
use of com.sohu.cache.entity.InstanceAlertValueResult 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.InstanceAlertValueResult in project cachecloud by sohutv.
the class AppEmailUtil method noticeAppResult.
/**
* 应用状态通知
* @param appDesc
* @param appAudit
*/
public void noticeAppResult(AppDesc appDesc, AppAudit appAudit) {
List<String> ccEmailList = getCCEmailList(appDesc, appAudit);
String mailContent = VelocityUtils.createText(velocityEngine, appDesc, appAudit, new AppDailyData(), new ArrayList<InstanceAlertValueResult>(), "appAudit.vm", "UTF-8");
AppUser appUser = userService.get(appDesc.getUserId());
emailComponent.sendMail("【CacheCloud】状态通知", mailContent, Arrays.asList(appUser.getEmail()), ccEmailList);
}
use of com.sohu.cache.entity.InstanceAlertValueResult in project cachecloud by sohutv.
the class InstanceAlertValueServiceImpl method checkDiffInstanceInfoAlert.
/**
* 检测每个实例统计信息
*
* @param standardStats
* @param instanceAlertList
* @return
*/
public List<InstanceAlertValueResult> checkDiffInstanceInfoAlert(StandardStats standardStats, List<InstanceAlert> instanceAlertList) {
List<InstanceAlertValueResult> resultList = new ArrayList<InstanceAlertValueResult>();
// 标准Redis info差值
String jsonInfo = standardStats.getDiffJson();
if (StringUtils.isBlank(jsonInfo)) {
logger.error("id={}'s standardStats is empty", standardStats.getId());
return null;
}
// 转换成Map
Map<String, Object> infoMap = JsonUtil.fromJson(jsonInfo, Map.class);
if (MapUtils.isEmpty(infoMap)) {
return null;
}
// 转换成Map<String, Map<String,Object>>
for (Entry<String, Object> entry : infoMap.entrySet()) {
String infoKey = entry.getKey();
Object infoValue = entry.getValue();
InstanceAlertValueResult instanceAlertValueResult = generateInstanceValueResult(instanceAlertList, infoKey, infoValue, standardStats.getIp(), standardStats.getPort());
if (instanceAlertValueResult != null) {
resultList.add(instanceAlertValueResult);
}
}
return resultList;
}
Aggregations