use of com.sohu.cache.entity.AppClientExceptionStat in project cachecloud by sohutv.
the class AppClientDataShowController method doException.
/**
* 客户端异常查询
*/
@RequestMapping("/exception")
public ModelAndView doException(HttpServletRequest request, HttpServletResponse response, Model model) {
// 1.1 应用信息
Long appId = NumberUtils.toLong(request.getParameter("appId"));
if (appId <= 0) {
return new ModelAndView("");
}
AppDesc appDesc = appService.getByAppId(appId);
model.addAttribute("appDesc", appDesc);
// 1.2 异常类型
int type = NumberUtil.toInt(request.getParameter("type"));
model.addAttribute("type", type);
// 1.3 客户端ip
String clientIp = request.getParameter("clientIp");
model.addAttribute("clientIp", clientIp);
// 1.4 日期格式转换
TimeBetween timeBetween = new TimeBetween();
try {
timeBetween = fillWithClientExceptionTime(request, model);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
// 2. 分页查询异常
int totalCount = clientReportExceptionService.getAppExceptionCount(appId, timeBetween.getStartTime(), timeBetween.getEndTime(), type, clientIp);
int pageNo = NumberUtils.toInt(request.getParameter("pageNo"), 1);
int pageSize = NumberUtils.toInt(request.getParameter("pageSize"), 10);
Page page = new Page(pageNo, pageSize, totalCount);
model.addAttribute("page", page);
List<AppClientExceptionStat> appClientExceptionList = clientReportExceptionService.getAppExceptionList(appId, timeBetween.getStartTime(), timeBetween.getEndTime(), type, clientIp, page);
model.addAttribute("appClientExceptionList", appClientExceptionList);
return new ModelAndView("client/clientException");
}
use of com.sohu.cache.entity.AppClientExceptionStat in project cachecloud by sohutv.
the class ClientReportExceptionServiceImpl method generate.
private AppClientExceptionStat generate(String clientIp, long collectTime, long reportTime, Map<String, Object> map) {
// 异常信息
String exceptionClass = MapUtils.getString(map, ClientReportConstant.EXCEPTION_CLASS, "");
Long exceptionCount = MapUtils.getLong(map, ClientReportConstant.EXCEPTION_COUNT, 0L);
int exceptionType = MapUtils.getInteger(map, ClientReportConstant.EXCEPTION_TYPE, ClientExceptionType.REDIS_TYPE.getType());
String host = null;
Integer port = null;
Integer instanceId = null;
long appId;
if (ClientExceptionType.REDIS_TYPE.getType() == exceptionType) {
// 实例host:port
String hostPort = MapUtils.getString(map, ClientReportConstant.EXCEPTION_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;
}
host = hostPort.substring(0, index);
port = NumberUtils.toInt(hostPort.substring(index + 1));
// 实例信息
InstanceInfo instanceInfo = clientReportInstanceService.getInstanceInfoByHostPort(host, port);
if (instanceInfo == null) {
// logger.warn("instanceInfo is empty, host is {}, port is {}", host, port);
return null;
}
// 实例id
instanceId = instanceInfo.getId();
// 应用id
appId = instanceInfo.getAppId();
} else {
List<AppClientVersion> appClientVersion = appClientVersionDao.getByClientIp(clientIp);
if (CollectionUtils.isNotEmpty(appClientVersion)) {
appId = appClientVersion.get(0).getAppId();
} else {
appId = 0;
}
}
// 组装AppClientExceptionStat
AppClientExceptionStat stat = new AppClientExceptionStat();
stat.setAppId(appId);
stat.setClientIp(clientIp);
stat.setReportTime(new Date(reportTime));
stat.setCollectTime(collectTime);
stat.setCreateTime(new Date());
stat.setExceptionClass(exceptionClass);
stat.setExceptionCount(exceptionCount);
stat.setInstanceHost(host);
stat.setInstancePort(port);
stat.setInstanceId(instanceId);
stat.setType(exceptionType);
return stat;
}
use of com.sohu.cache.entity.AppClientExceptionStat in project cachecloud by sohutv.
the class ClientReportExceptionServiceImpl method batchSave.
@Override
public void batchSave(ClientReportBean clientReportBean) {
try {
// 1.client上报
final String clientIp = clientReportBean.getClientIp();
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;
}
// 2.结果集
List<AppClientExceptionStat> appClientExceptionStatList = new ArrayList<AppClientExceptionStat>();
// 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.EXCEPTION_TYPE.equals(clientCollectDataTypeEnum)) {
AppClientExceptionStat appClientExceptionStat = generate(clientIp, collectTime, reportTime, map);
if (appClientExceptionStat != null) {
appClientExceptionStatList.add(appClientExceptionStat);
}
}
}
// 4.批量保存
if (CollectionUtils.isNotEmpty(appClientExceptionStatList)) {
appClientExceptionStatDao.batchSave(appClientExceptionStatList);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
Aggregations