...
|
...
|
@@ -17,6 +17,7 @@ import com.monitor.model.response.NewJavaApiInfoRep; |
|
|
import com.monitor.mysql.mapper.MObjectInfoMapper;
|
|
|
import com.monitor.mysql.mapper.MTypeInfoMapper;
|
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -366,13 +367,29 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService { |
|
|
@Override
|
|
|
public void sendAlarmMsg()
|
|
|
{
|
|
|
List<Map> list = serviceAccessMapper.getAlarmData();
|
|
|
//获取aws和qq所有机器ip
|
|
|
List<MObjectInfo> mObjectInfos = mObjectInfoMapper.selectAllDistinctHostIP();
|
|
|
List<String> distinctIpList = new ArrayList<>();
|
|
|
for(MObjectInfo mObjectInfo : mObjectInfos){
|
|
|
distinctIpList.add(mObjectInfo.getMoHostIp());
|
|
|
}
|
|
|
|
|
|
//获取报警阀值
|
|
|
Integer costThreshold = snsMobileConfig.getJavaServiceCostThreshold();
|
|
|
if(costThreshold == null){
|
|
|
costThreshold = 200;
|
|
|
}
|
|
|
String nowString = DateTime.now().toString("yyyy-MM-dd HH:mm:ss");
|
|
|
List<Map> list = serviceAccessMapper.getAlarmData(costThreshold);
|
|
|
//获取cpu、内存、带宽使用情况
|
|
|
Map vmInfoMap = vmInfoMapper.getVMInfo();
|
|
|
String costMsgContentTemplate = "服务名:%s,ip:%s,平均耗时%dms,CPU使用率:%s,可用内存/总内存(MB):%s";
|
|
|
String bandWidthContentTemplate = "ip:%s,输入带宽 :%.2fMbps,输出带宽:%.2fMbps";
|
|
|
String costMsgContentTemplate = "时间:%s,服务名:%s,ip:%s,平均耗时%dms,CPU使用率:%s,可用内存/总内存(MB):%s";
|
|
|
String bandWidthContentTemplate = "时间:%s,ip:%s,输入带宽 :%.2fMbps,输出带宽:%.2fMbps";
|
|
|
for(Map map : list){
|
|
|
String hostAddress = (String)map.get("hostAddress");
|
|
|
if(!distinctIpList.contains(hostAddress)){
|
|
|
continue;
|
|
|
}
|
|
|
String serviceName = (String)map.get("serviceName");
|
|
|
Integer mean = ((Double)map.get("mean")).intValue();
|
|
|
String cpuRate = "";
|
...
|
...
|
@@ -383,7 +400,7 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService { |
|
|
memoryRate = "" + vmList.get(2) + "/" + vmList.get(3);
|
|
|
}
|
|
|
|
|
|
String costMsgContent = String.format(costMsgContentTemplate,serviceName,hostAddress,mean,cpuRate,memoryRate);
|
|
|
String costMsgContent = String.format(costMsgContentTemplate,nowString,serviceName,hostAddress,mean,cpuRate,memoryRate);
|
|
|
log.info("sendAlarmMsg costMsgContent is {}",costMsgContent);
|
|
|
boolean result = alarmMsgService.sendSms("JavaServiceAlarm",costMsgContent,snsMobileConfig.getJavaServiceMobile());
|
|
|
log.info("sendAlarmMsg result is {}",result);
|
...
|
...
|
@@ -399,7 +416,7 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService { |
|
|
Double inBandwidth = (Double)vmList.get(4);
|
|
|
Double outBandwidth = (Double)vmList.get(5);
|
|
|
if(inBandwidth > 300 || outBandwidth > 300){
|
|
|
String bandWidthContent = String.format(bandWidthContentTemplate,ip,inBandwidth,outBandwidth);
|
|
|
String bandWidthContent = String.format(bandWidthContentTemplate,nowString,ip,inBandwidth,outBandwidth);
|
|
|
log.info("sendAlarmMsg bandWidthContent is {}",bandWidthContent);
|
|
|
boolean result = alarmMsgService.sendSms("JavaServiceAlarm",bandWidthContent,snsMobileConfig.getJavaServiceMobile());
|
|
|
log.info("sendAlarmMsg result is {}",result);
|
...
|
...
|
|