use of com.sohu.cache.jmx.ErrorLoggerWatcherMBean in project cachecloud by sohutv.
the class ErrorStatisticsJob method action.
@Override
public void action(JobExecutionContext context) {
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
SchedulerContext schedulerContext;
try {
schedulerContext = context.getScheduler().getContext();
ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
EmailComponent emailComponent = applicationContext.getBean("emailComponent", EmailComponent.class);
ErrorLoggerWatcherMBean errorLoggerWatcher = applicationContext.getBean("errorLoggerWatcher", ErrorLoggerWatcherMBean.class);
// if (errorLoggerWatcher.getTotalErrorCount() == 0L) {
// logger.warn("errorLoggerWatcher.totalErrorCount == 0 -o-");
// return;
// }
String title = "CacheCloud异常统计, 日期:" + dateFormat.format(date) + ";服务器:" + System.getProperty("local.ip") + ";总数:" + errorLoggerWatcher.getTotalErrorCount();
StringBuilder buffer = new StringBuilder();
buffer.append(title + ":<br/>");
for (Map.Entry<String, Long> entry : errorLoggerWatcher.getErrorInfos().entrySet()) {
Long num = entry.getValue();
if (num == 0L) {
continue;
}
String key = entry.getKey();
buffer.append(key + "=" + num + "<br/>");
}
emailComponent.sendMailToAdmin(title, buffer.toString());
//清理异常
errorLoggerWatcher.clear();
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
}
}
Aggregations