Search in sources :

Example 1 with StandardStats

use of com.sohu.cache.entity.StandardStats 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 2 with StandardStats

use of com.sohu.cache.entity.StandardStats in project cachecloud by sohutv.

the class InstanceStatsCenterImpl method queryDiffMapList.

@Override
public List<Map<String, Object>> queryDiffMapList(long beginTime, long endTime, String ip, int port, String dbType) {
    Assert.isTrue(StringUtils.isNotBlank(ip));
    Assert.isTrue(port > 0);
    Assert.isTrue(beginTime > 0);
    Assert.isTrue(endTime > 0);
    List<StandardStats> list = instanceStatsDao.getDiffJsonList(beginTime, endTime, ip, port, dbType);
    if (list == null || list.isEmpty()) {
        return new ArrayList<Map<String, Object>>(0);
    }
    List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(list.size());
    for (StandardStats ss : list) {
        Map<String, Object> diffMap = ss.getDiffMap();
        diffMap.put(ConstUtils.COLLECT_TIME, ss.getCollectTime());
        resultList.add(diffMap);
    }
    return resultList;
}
Also used : StandardStats(com.sohu.cache.entity.StandardStats)

Example 3 with StandardStats

use of com.sohu.cache.entity.StandardStats in project cachecloud by sohutv.

the class InstanceStatsCenterImpl method saveStandardStats.

@Override
public boolean saveStandardStats(Map<String, Object> infoMap, String ip, int port, String dbType) {
    Assert.isTrue(infoMap != null && infoMap.size() > 0);
    Assert.isTrue(StringUtils.isNotBlank(ip));
    Assert.isTrue(port > 0);
    Assert.isTrue(infoMap.containsKey(ConstUtils.COLLECT_TIME), ConstUtils.COLLECT_TIME + " not in infoMap");
    long collectTime = MapUtils.getLong(infoMap, ConstUtils.COLLECT_TIME);
    StandardStats ss = new StandardStats();
    ss.setCollectTime(collectTime);
    ss.setIp(ip);
    ss.setPort(port);
    ss.setDbType(dbType);
    if (infoMap.containsKey(RedisConstant.DIFF.getValue())) {
        Map<String, Object> diffMap = (Map<String, Object>) infoMap.get(RedisConstant.DIFF.getValue());
        ss.setDiffMap(diffMap);
        infoMap.remove(RedisConstant.DIFF.getValue());
    } else {
        ss.setDiffMap(new HashMap<String, Object>(0));
    }
    ss.setInfoMap(infoMap);
    int mergeCount = instanceStatsDao.mergeStandardStats(ss);
    return mergeCount > 0;
}
Also used : StandardStats(com.sohu.cache.entity.StandardStats)

Example 4 with StandardStats

use of com.sohu.cache.entity.StandardStats in project cachecloud by sohutv.

the class InstanceStatsCenterImpl method queryStandardInfoMap.

@Override
public Map<String, Object> queryStandardInfoMap(long collectTime, String ip, int port, String dbType) {
    Assert.isTrue(StringUtils.isNotBlank(ip));
    Assert.isTrue(port > 0);
    Assert.isTrue(collectTime > 0);
    StandardStats ss = instanceStatsDao.getStandardStats(collectTime, ip, port, dbType);
    if (ss != null) {
        Map<String, Object> infoMap = ss.getInfoMap();
        Map<String, Object> diffMap = ss.getDiffMap();
        infoMap.put(RedisConstant.DIFF.getValue(), diffMap);
        return infoMap;
    } else {
        return Collections.emptyMap();
    }
}
Also used : StandardStats(com.sohu.cache.entity.StandardStats)

Aggregations

StandardStats (com.sohu.cache.entity.StandardStats)4 InstanceAlert (com.sohu.cache.entity.InstanceAlert)1 InstanceAlertValueResult (com.sohu.cache.entity.InstanceAlertValueResult)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1