Search in sources :

Example 11 with InstanceInfo

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

the class BaseController method fillAppInstanceStats.

/**
     * 实例统计信息
     * 
     * @param appId
     * @param model
     */
protected void fillAppInstanceStats(Long appId, Model model) {
    List<InstanceInfo> instanceList = appService.getAppInstanceInfo(appId);
    List<InstanceStats> appInstanceStats = appService.getAppInstanceStats(appId);
    Map<String, InstanceStats> instanceStatsMap = new HashMap<String, InstanceStats>();
    for (InstanceStats instanceStats : appInstanceStats) {
        instanceStatsMap.put(instanceStats.getIp() + ":" + instanceStats.getPort(), instanceStats);
    }
    model.addAttribute("instanceList", instanceList);
    model.addAttribute("instanceStatsMap", instanceStatsMap);
    //slot分布
    Map<String, InstanceSlotModel> clusterSlotsMap = redisCenter.getClusterSlotsMap(appId);
    model.addAttribute("clusterSlotsMap", clusterSlotsMap);
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) HashMap(java.util.HashMap) InstanceInfo(com.sohu.cache.entity.InstanceInfo) InstanceSlotModel(com.sohu.cache.entity.InstanceSlotModel)

Example 12 with InstanceInfo

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

the class MachineManageController method fillInstanceModel.

/**
     * 实例统计信息
     * @param appAudit
     * @param model
     */
protected void fillInstanceModel(List<InstanceInfo> instanceList, List<InstanceStats> appInstanceStats, Model model) {
    Map<String, MachineStats> machineStatsMap = new HashMap<String, MachineStats>();
    Map<String, Long> machineCanUseMem = new HashMap<String, Long>();
    Map<String, InstanceStats> instanceStatsMap = new HashMap<String, InstanceStats>();
    Map<Long, AppDesc> appInfoMap = new HashMap<Long, AppDesc>();
    for (InstanceStats instanceStats : appInstanceStats) {
        instanceStatsMap.put(instanceStats.getIp() + ":" + instanceStats.getPort(), instanceStats);
        appInfoMap.put(instanceStats.getAppId(), appService.getByAppId(instanceStats.getAppId()));
    }
    for (InstanceInfo instanceInfo : instanceList) {
        if (TypeUtil.isRedisSentinel(instanceInfo.getType())) {
            continue;
        }
        String ip = instanceInfo.getIp();
        if (machineStatsMap.containsKey(ip)) {
            continue;
        }
        List<MachineStats> machineStatsList = machineCenter.getMachineStats(ip);
        MachineStats machineStats = null;
        for (MachineStats stats : machineStatsList) {
            if (stats.getIp().equals(ip)) {
                machineStats = stats;
                machineStatsMap.put(ip, machineStats);
                break;
            }
        }
        MachineStats ms = machineCenter.getMachineMemoryDetail(ip);
        machineCanUseMem.put(ip, ms.getMachineMemInfo().getLockedMem());
    }
    model.addAttribute("appInfoMap", appInfoMap);
    model.addAttribute("machineCanUseMem", machineCanUseMem);
    model.addAttribute("machineStatsMap", machineStatsMap);
    model.addAttribute("instanceList", instanceList);
    model.addAttribute("instanceStatsMap", instanceStatsMap);
}
Also used : HashMap(java.util.HashMap) InstanceStats(com.sohu.cache.entity.InstanceStats) MachineStats(com.sohu.cache.entity.MachineStats) AppDesc(com.sohu.cache.entity.AppDesc) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 13 with InstanceInfo

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

the class MachineManageController method doMachineInstances.

/**
     * 机器实例展示
     * @param ip
     * @return
     */
@RequestMapping(value = "/machineInstances")
public ModelAndView doMachineInstances(HttpServletRequest request, HttpServletResponse response, Model model, String ip) {
    //机器以及机器下面的实例信息
    MachineInfo machineInfo = machineCenter.getMachineInfoByIp(ip);
    List<InstanceInfo> instanceList = machineCenter.getMachineInstanceInfo(ip);
    List<InstanceStats> instanceStatList = machineCenter.getMachineInstanceStatsByIp(ip);
    //统计信息
    fillInstanceModel(instanceList, instanceStatList, model);
    model.addAttribute("machineInfo", machineInfo);
    model.addAttribute("machineActive", SuccessEnum.SUCCESS.value());
    return new ModelAndView("manage/machine/machineInstances");
}
Also used : MachineInfo(com.sohu.cache.entity.MachineInfo) InstanceStats(com.sohu.cache.entity.InstanceStats) ModelAndView(org.springframework.web.servlet.ModelAndView) InstanceInfo(com.sohu.cache.entity.InstanceInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with InstanceInfo

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

the class InstanceStatsCenterImpl method getInstanceStats.

@Override
public InstanceStats getInstanceStats(long instanceId) {
    InstanceStats instanceStats = instanceStatsDao.getInstanceStatsByInsId(instanceId);
    if (instanceStats == null) {
        logger.error("instanceStats id={} is null", instanceId);
        return null;
    }
    InstanceInfo instanceInfo = instanceDao.getInstanceInfoById(instanceId);
    int type = instanceInfo.getType();
    boolean isRun = isRun(type, instanceInfo.getIp(), instanceInfo.getPort());
    instanceStats.setRun(isRun);
    if (isRun) {
        Map<String, Object> infoMap = getInfoMap(type, instanceInfo.getIp(), instanceInfo.getPort());
        instanceStats.setInfoMap(infoMap);
        if (infoMap == null || infoMap.isEmpty()) {
            instanceStats.setRun(false);
        }
    }
    return instanceStats;
}
Also used : InstanceStats(com.sohu.cache.entity.InstanceStats) InstanceInfo(com.sohu.cache.entity.InstanceInfo)

Example 15 with InstanceInfo

use of com.sohu.cache.entity.InstanceInfo 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)

Aggregations

InstanceInfo (com.sohu.cache.entity.InstanceInfo)45 AppDesc (com.sohu.cache.entity.AppDesc)11 List (java.util.List)7 Jedis (redis.clients.jedis.Jedis)7 InstanceStats (com.sohu.cache.entity.InstanceStats)6 MachineInfo (com.sohu.cache.entity.MachineInfo)5 ArrayList (java.util.ArrayList)5 IdempotentConfirmer (com.sohu.cache.util.IdempotentConfirmer)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 InstanceCommandStats (com.sohu.cache.entity.InstanceCommandStats)2 InstanceSlotModel (com.sohu.cache.entity.InstanceSlotModel)2 AppDetailVO (com.sohu.cache.web.vo.AppDetailVO)2 BaseTest (com.sohu.test.BaseTest)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 HostAndPort (redis.clients.jedis.HostAndPort)2