Search in sources :

Example 1 with ErrorLoggerWatcherMBean

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);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) SchedulerException(org.quartz.SchedulerException) SchedulerContext(org.quartz.SchedulerContext) EmailComponent(com.sohu.cache.web.component.EmailComponent) ErrorLoggerWatcherMBean(com.sohu.cache.jmx.ErrorLoggerWatcherMBean) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) Date(java.util.Date)

Aggregations

ErrorLoggerWatcherMBean (com.sohu.cache.jmx.ErrorLoggerWatcherMBean)1 EmailComponent (com.sohu.cache.web.component.EmailComponent)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 SchedulerContext (org.quartz.SchedulerContext)1 SchedulerException (org.quartz.SchedulerException)1 ApplicationContext (org.springframework.context.ApplicationContext)1