Browse Source

1.修改日志配置
2.修改报警通知范围

luxueshi 3 years ago
parent
commit
6508463ac4

+ 7 - 3
src/main/java/MinitorApplication.java

@@ -17,7 +17,9 @@ public class MinitorApplication {
 
     private static final String MINITOR_ALARM_CONTENT = "定时监控程序运行异常";
 
-    private static final String ADMIN_PHONE = "18618105263";
+    private static final String SDK_MINITOR_ADMIN_PHONE = "18618105263";
+
+    private static final String SDK_ADMIN_PHONE = "18592030302";
 
     public static void main(String[] args) {
         TimerTask timerTask = new TimerTask() {
@@ -27,7 +29,9 @@ public class MinitorApplication {
                     log.info("---调度监控程序---");
                     if (errorTimes == 5 && requestTimes == 5) {
                         //钉钉群通知,报警
-                        boolean alarmResult = AlarmUtil.alarmByDingDing(ALARM_CONTENT, true, null);
+                        List<String> mobileList = new ArrayList<>();
+                        mobileList.add(SDK_ADMIN_PHONE);
+                        boolean alarmResult = AlarmUtil.alarmByDingDing(ALARM_CONTENT, false, mobileList);
                         log.info("钉钉报警发送结果:" + alarmResult);
                         errorTimes = 0;
                         requestTimes = 0;
@@ -43,7 +47,7 @@ public class MinitorApplication {
                     }
                 } catch (Exception e) {
                     List<String> mobileList = new ArrayList<>();
-                    mobileList.add(ADMIN_PHONE);
+                    mobileList.add(SDK_MINITOR_ADMIN_PHONE);
                     AlarmUtil.alarmByDingDing(MINITOR_ALARM_CONTENT, false, mobileList);
                     log.error("定时任务执行异常,", e);
                 }

+ 3 - 1
src/main/java/RequestUtil.java

@@ -13,7 +13,9 @@ public class RequestUtil {
             String requestFullUrl = SDK_URL + port + path;
             log.info("请求路径:" + requestFullUrl + ",请求入参:" + requestStr);
             String result = HttpUtil.post(requestFullUrl, requestStr);
-            return JSONUtil.isJson(result);
+            log.info("接口返回:" + result);
+            boolean isJson = JSONUtil.isJson(result);
+            return isJson;
         } catch (Exception e) {
             log.error("SDK接口调用异常", e);
             return false;

+ 0 - 18
src/main/resources/log4j.properties

@@ -1,18 +0,0 @@
-#priority:debug<info<warn<error
-log4j.rootLogger=info,error,stdout
-
-#console
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=[%d{yyyy-MM-ddHH:mm:ssa}]:%p%l%m%n
-log4j.appender.stdout.encoding=UTF-8
-
-#error
-log4j.logger.error=error
-log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.error.DatePattern='_'yyyy-MM-dd'.log'
-log4j.appender.error.File=D:/minitor-logs/error.log
-log4j.appender.error.Append=true
-log4j.appender.error.Threshold=ERROR
-log4j.appender.error.layout=org.apache.log4j.PatternLayout
-log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ssa}[Thread:%t][Class:%c>>Method:%l]%n%p:%m%n

+ 45 - 0
src/main/resources/log4j.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
+<log4j:configuration>
+    <!--输出到控制台-->
+    <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
+        <param name="Threshold" value="DEBUG"/>
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
+        </layout>
+    </appender>
+
+    <!--输出到文件(info)-->
+    <!--将生成“info.log.2014-06-11”这样的日志文件-->
+    <appender name="fileAppenderInfo" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="D:/minitor-logs/info.log" />
+        <param name="DatePattern" value=".yyyy-MM-dd" />
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
+        </layout>
+        <filter class="org.apache.log4j.varia.LevelRangeFilter">
+            <param name="LevelMin" value="INFO" />
+            <param name="LevelMax" value="INFO" />
+        </filter>
+    </appender>
+
+    <!--输出到文件(error)-->
+    <appender name="fileAppenderError" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="D:/minitor-logs/error.log" />
+        <param name="DatePattern" value=".yyyy-MM-dd" />
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
+        </layout>
+        <filter class="org.apache.log4j.varia.LevelRangeFilter">
+            <param name="LevelMin" value="ERROR" />
+            <param name="LevelMax" value="ERROR" />
+        </filter>
+    </appender>
+
+    <root>
+        <level value="ALL"/>
+        <appender-ref ref="consoleAppender" />
+        <appender-ref ref="fileAppenderInfo" />
+        <appender-ref ref="fileAppenderError" />
+    </root>
+</log4j:configuration>

+ 1 - 1
start.bat

@@ -1,2 +1,2 @@
 @echo off
-start sdk-minitor -jar -Xms16m -Xmx32m sdk-minitor-1.0-RELEASE.jar 8808 ["基础对象"]
+start sdk-minitor -jar -Xms16m -Xmx32m sdk-minitor-1.0-RELEASE.jar 8808 [\"基础对象\"]