package com.securityControl.task.service.impl; import com.securityControl.common.core.utils.DateUtils; import com.securityControl.task.domain.vo.WarningLogVo; import com.securityControl.task.mapper.LogWarningMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.net.InetAddress; import java.net.UnknownHostException; @Slf4j @Service public class LogWarningService { @Resource private LogWarningMapper mapper; public void logWarn() { String maxLogSize = mapper.getMaxLogSize(); String usedMaxSize = mapper.getUsedMaxSize(); BigDecimal b1 = new BigDecimal(maxLogSize); BigDecimal b2 = new BigDecimal(usedMaxSize); double rate = b2.divide(b1, RoundingMode.HALF_UP).doubleValue(); if (rate >= 0.95) { log.warn("内存报警发送邮件!!!"); waringLog("容量告警", "基建视频安全管控系统日志容量已超过95%"); } } private void waringLog(String title, String detail) { InetAddress address = null; String hostAddress = ""; try { address = InetAddress.getLocalHost(); hostAddress = address.getHostAddress(); } catch (UnknownHostException e1) { log.warn("====获取服务器ip异常===="); e1.printStackTrace(); } WarningLogVo warningLog = new WarningLogVo(); warningLog.setOperateType(title); warningLog.setOperationIp(hostAddress); warningLog.setOperateTitle("日志容量上限告警"); warningLog.setOperateDetails(detail); warningLog.setOperateJb("2");//5致命,4严重,3中等,2一般,1轻微 warningLog.setFastTime(DateUtils.getTime()); warningLog.setOperationName("定时任务"); mapper.insertWarningLog(warningLog); } }