Authored by fanzelei

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

... ... @@ -2,15 +2,20 @@ package com.monitor.middleware.rabbitmq.component;
import com.monitor.common.config.SnsMobileConfig;
import com.monitor.common.service.AlarmMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by yoho on 2016/7/6.
*/
@Component
public class AlarmMsgComp {
public static final Logger DEBUG = LoggerFactory.getLogger(AlarmMsgComp.class);
@Autowired
AlarmMsgService alarmMsgService;
... ... @@ -18,7 +23,13 @@ public class AlarmMsgComp {
SnsMobileConfig snsMobileConfig;
public void doAlarm(String subject, String content) {
alarmMsgService.sendSms(subject, content, snsMobileConfig.getBaseMobile());
}
try {
alarmMsgService.sendSms(subject, content, snsMobileConfig.getBaseMobile());
} catch (Exception e) {
DEBUG.error("Failed to alarm , error {}", e);
return;
}
}
}
... ...
... ... @@ -57,7 +57,7 @@ public interface InterVar {
String DBTAG = "moId";
int MONIT_TIMEOUT = 10;
int MONIT_TIMEOUT = 30;
String RETENTION_POLICY = "default";
... ...
... ... @@ -51,7 +51,7 @@ public class RabbitMonitTask {
@Autowired
AlarmMsgComp alarmMsgComp;
@Scheduled(fixedRate = 3 * 60 * 1000L)
@Scheduled(fixedRate = 2 * 60 * 1000L)
public void doTask() {
synchronized (InterVar.LOCK.intern()) {
for (Map.Entry<Integer, MObjectInfo> entry : InterVar.moMaps.entrySet()) {
... ...
package com.monitor.middleware.rabbitmq.task;
import com.model.MObjectInfo;
import com.model.RabbitAlertInfo;
import com.model.TypeInfo;
import com.monitor.cmdb.service.IMObjectInfoService;
import com.monitor.cmdb.service.ITypeInfoService;
import com.monitor.middleware.rabbitmq.constant.InterVar;
import com.monitor.mysql.mapper.RabbitAlertMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
... ... @@ -14,6 +16,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
... ... @@ -29,14 +32,16 @@ public class RabbitScanTask implements Runnable {
@Autowired
ITypeInfoService typeService;
@Autowired
RabbitAlertMapper rabbitAlertMapper;
@PostConstruct
public void init()
{
public void init() {
InterVar.EXECUTOR_SERVICE.submit(this);
}
//自动发现rabbit监控对象
@Scheduled(fixedRate = 60*1000L)
@Scheduled(fixedRate = 60 * 1000L)
public void doTask() {
List<TypeInfo> typeInfosList = typeService.queryAllTypesInfo();
... ... @@ -51,13 +56,30 @@ public class RabbitScanTask implements Runnable {
}
}
synchronized (InterVar.LOCK.intern())
{
synchronized (InterVar.LOCK.intern()) {
for (MObjectInfo info : mObjectInfoList) {
InterVar.moMaps.put(info.getMoId(), info);
}
for (RabbitAlertInfo info : rabbitAlertMapper.getAllAlertsInfo()) {
HashMap<String, Integer> alertMap = new HashMap<>();
if (InterVar.alertMaps.containsKey(info.getMoId())) {
alertMap = InterVar.alertMaps.get(info.getMoId());
}
alertMap.put(info.getQueueName(), info.getAlertHigh());
InterVar.alertMaps.put(info.getMoId(), alertMap);
}
}
}
... ...
... ... @@ -93,6 +93,12 @@ public class QueueViewJob implements Callable {
return;
}
catch (Exception e)
{
DEBUG.error("Failed to execute monitor task , error {} ",e);
return;
}
if (null != oneView) {
... ... @@ -106,7 +112,7 @@ public class QueueViewJob implements Callable {
private void checkAlert(String moId, QueueInfo queueInfo) {
synchronized (moId.intern()) {
HashMap<String, Integer> alertMaps = InterVar.alertMaps.get(moId);
HashMap<String, Integer> alertMaps = InterVar.alertMaps.get(Integer.parseInt(moId));
if (null != alertMaps) {
... ... @@ -123,7 +129,7 @@ public class QueueViewJob implements Callable {
alarmMsgComp.doAlarm(InterVar.ALARM_QUEUE, msg);
//ui alert
InterVar.overViewMaps.get(this.moId).setState(0);
InterVar.overViewMaps.get(Integer.parseInt(moId)).setState(0);
}
}
}
... ...