Search in sources :

Example 1 with InstanceCommandStats

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

the class InstanceStatsCenterImpl method parseCommand.

private InstanceCommandStats parseCommand(long instanceId, String command, Map<String, Object> commandMap, boolean isCommand, int type) {
    Long collectTime = MapUtils.getLong(commandMap, ConstUtils.COLLECT_TIME, null);
    if (collectTime == null) {
        return null;
    }
    Long count;
    if (isCommand) {
        count = MapUtils.getLong(commandMap, "cmdstat_" + command.toLowerCase(), null);
    } else {
        count = MapUtils.getLong(commandMap, command.toLowerCase(), null);
    }
    if (count == null) {
        return null;
    }
    InstanceCommandStats stats = new InstanceCommandStats();
    stats.setCommandCount(count);
    stats.setCommandName(command);
    stats.setCollectTime(collectTime);
    stats.setCreateTime(DateUtil.getDateByFormat(String.valueOf(collectTime), "yyyyMMddHHmm"));
    stats.setModifyTime(DateUtil.getDateByFormat(String.valueOf(collectTime), "yyyyMMddHHmm"));
    stats.setInstanceId(instanceId);
    return stats;
}
Also used : InstanceCommandStats(com.sohu.cache.entity.InstanceCommandStats)

Example 2 with InstanceCommandStats

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

the class InstanceStatsCenterImpl method getStandardStatsList.

@Override
public Map<Integer, Map<String, List<InstanceCommandStats>>> getStandardStatsList(Long appId, long beginTime, long endTime, List<String> commands) {
    if (appId == null) {
        return Collections.emptyMap();
    }
    List<InstanceInfo> list = instanceDao.getInstListByAppId(appId);
    if (list == null || list.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<Integer, Map<String, List<InstanceCommandStats>>> resultMap = new LinkedHashMap<Integer, Map<String, List<InstanceCommandStats>>>();
    for (InstanceInfo instance : list) {
        if (instance.isOffline()) {
            continue;
        }
        int instanceId = instance.getId();
        String ip = instance.getIp();
        int port = instance.getPort();
        int type = instance.getType();
        Boolean isMaster = redisCenter.isMaster(ip, port);
        if (BooleanUtils.isNotTrue(isMaster)) {
            continue;
        }
        List<Map<String, Object>> objectList = this.queryDiffMapList(beginTime, endTime, ip, port, ConstUtils.REDIS);
        ;
        if (objectList != null) {
            Map<String, List<InstanceCommandStats>> commandMap = new LinkedHashMap<String, List<InstanceCommandStats>>();
            for (String commandName : commands) {
                List<InstanceCommandStats> resultList = new ArrayList<InstanceCommandStats>(objectList.size());
                for (Map<String, Object> map : objectList) {
                    InstanceCommandStats stats = parseCommand(instanceId, commandName, map, false, type);
                    if (stats != null) {
                        resultList.add(stats);
                    }
                }
                commandMap.put(commandName, resultList);
            }
            resultMap.put(instanceId, commandMap);
        }
    }
    return resultMap;
}
Also used : InstanceInfo(com.sohu.cache.entity.InstanceInfo) InstanceCommandStats(com.sohu.cache.entity.InstanceCommandStats)

Example 3 with InstanceCommandStats

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

the class InstanceStatsCenterImpl method getCommandStatsList.

@Override
public List<InstanceCommandStats> getCommandStatsList(Long instanceId, long beginTime, long endTime, String commandName) {
    if (instanceId == null) {
        return Collections.emptyList();
    }
    InstanceInfo instanceInfo = instanceDao.getInstanceInfoById(instanceId);
    List<InstanceCommandStats> resultList = new ArrayList<InstanceCommandStats>();
    String ip = instanceInfo.getIp();
    int port = instanceInfo.getPort();
    int type = instanceInfo.getType();
    List<Map<String, Object>> objectList = this.queryDiffMapList(beginTime, endTime, ip, port, ConstUtils.REDIS);
    ;
    if (objectList != null) {
        for (Map<String, Object> map : objectList) {
            InstanceCommandStats stats = parseCommand(instanceId, commandName, map, true, type);
            if (stats != null) {
                resultList.add(stats);
            }
        }
    }
    return resultList;
}
Also used : InstanceCommandStats(com.sohu.cache.entity.InstanceCommandStats) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Aggregations

InstanceCommandStats (com.sohu.cache.entity.InstanceCommandStats)3 InstanceInfo (com.sohu.cache.entity.InstanceInfo)2