Search in sources :

Example 1 with InstanceAlertValueResult

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());
}
Also used : InstanceAlertValueResult(com.sohu.cache.entity.InstanceAlertValueResult) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with InstanceAlertValueResult

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;
}
Also used : InstanceAlertValueResult(com.sohu.cache.entity.InstanceAlertValueResult) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 3 with 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();
}
Also used : InstanceAlertValueResult(com.sohu.cache.entity.InstanceAlertValueResult) StandardStats(com.sohu.cache.entity.StandardStats) ArrayList(java.util.ArrayList) InstanceAlert(com.sohu.cache.entity.InstanceAlert) Date(java.util.Date)

Example 4 with InstanceAlertValueResult

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);
}
Also used : InstanceAlertValueResult(com.sohu.cache.entity.InstanceAlertValueResult) AppUser(com.sohu.cache.entity.AppUser) AppDailyData(com.sohu.cache.entity.AppDailyData)

Example 5 with InstanceAlertValueResult

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;
}
Also used : InstanceAlertValueResult(com.sohu.cache.entity.InstanceAlertValueResult) ArrayList(java.util.ArrayList)

Aggregations

InstanceAlertValueResult (com.sohu.cache.entity.InstanceAlertValueResult)6 ArrayList (java.util.ArrayList)3 AppDailyData (com.sohu.cache.entity.AppDailyData)1 AppUser (com.sohu.cache.entity.AppUser)1 InstanceAlert (com.sohu.cache.entity.InstanceAlert)1 InstanceInfo (com.sohu.cache.entity.InstanceInfo)1 StandardStats (com.sohu.cache.entity.StandardStats)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1