Search in sources :

Example 1 with AppClientValueDistriStatTotal

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

the class ClientReportValueDistriServiceImplV2 method batchSave.

@Override
public void batchSave(ClientReportBean clientReportBean) {
    try {
        // 1.client上报
        final long collectTime = clientReportBean.getCollectTime();
        final long reportTime = clientReportBean.getReportTimeStamp();
        final List<Map<String, Object>> datas = clientReportBean.getDatas();
        if (datas == null || datas.isEmpty()) {
            logger.warn("datas field {} is empty", clientReportBean);
            return;
        }
        // 3.解析
        for (Map<String, Object> map : datas) {
            Integer clientDataType = MapUtils.getInteger(map, ClientReportConstant.CLIENT_DATA_TYPE, -1);
            ClientCollectDataTypeEnum clientCollectDataTypeEnum = ClientCollectDataTypeEnum.MAP.get(clientDataType);
            if (clientCollectDataTypeEnum == null) {
                continue;
            }
            if (ClientCollectDataTypeEnum.VALUE_LENGTH_DISTRI_TYPE.equals(clientCollectDataTypeEnum)) {
                AppClientValueDistriStatTotal appClientValueDistriStat = generate(collectTime, reportTime, map);
                if (appClientValueDistriStat != null) {
                    appClientValueStatDao.save(appClientValueDistriStat);
                }
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ClientCollectDataTypeEnum(com.sohu.tv.jedis.stat.enums.ClientCollectDataTypeEnum) Map(java.util.Map) AppClientValueDistriStatTotal(com.sohu.cache.entity.AppClientValueDistriStatTotal)

Example 2 with AppClientValueDistriStatTotal

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

the class ClientReportValueDistriServiceImplV2 method generate.

private AppClientValueDistriStatTotal generate(long collectTime, long reportTime, Map<String, Object> map) {
    String valueDistri = MapUtils.getString(map, ClientReportConstant.VALUE_DISTRI, "");
    ValueSizeDistriEnum valueSizeDistriEnum = ValueSizeDistriEnum.getByValue(valueDistri);
    if (valueSizeDistriEnum == null) {
        logger.warn("valueDistri {} is wrong, not in enums {}", valueDistri, ValueSizeDistriEnum.values());
    }
    // 次数
    Integer count = MapUtils.getInteger(map, ClientReportConstant.VALUE_COUNT, 0);
    // 命令
    String command = MapUtils.getString(map, ClientReportConstant.VALUE_COMMAND, "");
    if (StringUtils.isBlank(command)) {
        logger.warn("command is empty!");
        return null;
    }
    if (excludeCommands.contains(command)) {
        return null;
    }
    // 实例host:port
    String hostPort = MapUtils.getString(map, ClientReportConstant.VALUE_HOST_PORT, "");
    if (StringUtils.isEmpty(hostPort)) {
        logger.warn("hostPort is empty", hostPort);
        return null;
    }
    int index = hostPort.indexOf(":");
    if (index <= 0) {
        logger.warn("hostPort {} format is wrong", hostPort);
        return null;
    }
    String host = hostPort.substring(0, index);
    int port = NumberUtils.toInt(hostPort.substring(index + 1));
    // 实例信息
    InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
    if (instanceInfo == null) {
        // host, port);
        return null;
    }
    AppClientValueDistriStatTotal stat = new AppClientValueDistriStatTotal();
    stat.setAppId(instanceInfo.getAppId());
    stat.setCollectTime(collectTime);
    stat.setUpdateTime(new Date());
    stat.setCommand(command);
    stat.setDistributeType(valueSizeDistriEnum.getType());
    stat.setCount(count);
    return stat;
}
Also used : ValueSizeDistriEnum(com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum) InstanceInfo(com.sohu.cache.entity.InstanceInfo) AppClientValueDistriStatTotal(com.sohu.cache.entity.AppClientValueDistriStatTotal) Date(java.util.Date)

Aggregations

AppClientValueDistriStatTotal (com.sohu.cache.entity.AppClientValueDistriStatTotal)2 InstanceInfo (com.sohu.cache.entity.InstanceInfo)1 ClientCollectDataTypeEnum (com.sohu.tv.jedis.stat.enums.ClientCollectDataTypeEnum)1 ValueSizeDistriEnum (com.sohu.tv.jedis.stat.enums.ValueSizeDistriEnum)1 Date (java.util.Date)1 Map (java.util.Map)1