Browse Source

动态传入接口入参、端口号

luxueshi 3 years ago
parent
commit
239f5b4557

+ 5 - 5
src/main/java/MinitorApplication.java

@@ -24,16 +24,16 @@ public class MinitorApplication {
             @Override
             public void run() {
                 try {
+                    log.info("---调度监控程序---");
                     if (errorTimes == 5 && requestTimes == 5) {
                         //钉钉群通知,报警
-//                        boolean alarmResult = AlarmUtil.alarmByDingDing(ALARM_CONTENT, true, null);
-//                        log.info("钉钉报警发送结果:" + alarmResult);
-                        log.error("发送报警");
+                        boolean alarmResult = AlarmUtil.alarmByDingDing(ALARM_CONTENT, true, null);
+                        log.info("钉钉报警发送结果:" + alarmResult);
                         errorTimes = 0;
                         requestTimes = 0;
                     } else {
                         //访问SDK接口
-                        boolean sdkResult = RequestUtil.requestSDK();
+                        boolean sdkResult = RequestUtil.requestSDK(args[0], args[1]);
                         requestTimes++;
 
                         if (!sdkResult) {
@@ -52,6 +52,6 @@ public class MinitorApplication {
         // 计时器
         Timer timer = new Timer();
         // 添加执行任务(延迟 0s 执行,每 60s 执行一次)
-        timer.schedule(timerTask, 0, 5000);
+        timer.schedule(timerTask, 0, 60000);
     }
 }

+ 6 - 4
src/main/java/RequestUtil.java

@@ -5,12 +5,14 @@ import org.apache.log4j.Logger;
 public class RequestUtil {
 
     private final static Logger log = Logger.getLogger(RequestUtil.class);
-    private static final String SDK_URL = "http://localhost:8808/post";
-    private static final String REQUEST_STR = "[\"基础对象\"]";
+    private static final String SDK_URL = "http://localhost:";
+    private static final String path = "/post";
 
-    public static boolean requestSDK() {
+    public static boolean requestSDK(String port, String requestStr) {
         try {
-            String result = HttpUtil.post(SDK_URL, REQUEST_STR);
+            String requestFullUrl = SDK_URL + port + path;
+            log.info("请求路径:" + requestFullUrl + ",请求入参:" + requestStr);
+            String result = HttpUtil.post(requestFullUrl, requestStr);
             return JSONUtil.isJson(result);
         } catch (Exception e) {
             log.error("SDK接口调用异常", e);

+ 4 - 1
src/main/resources/log4j.properties

@@ -1,9 +1,12 @@
 #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
@@ -12,4 +15,4 @@ 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
+log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ssa}[Thread:%t][Class:%c>>Method:%l]%n%p:%m%n

+ 0 - 1
start-up.bat

@@ -1 +0,0 @@
-javaw -jar -Xms16m -Xmx32m sdk-minitor-1.0-RELEASE.jar

+ 1 - 0
start.bat

@@ -0,0 +1 @@
+javaw -jar -Xms16m -Xmx32m sdk-minitor-1.0-RELEASE.jar 8808 ["基础对象"]

+ 1 - 1
stop.bat

@@ -1,3 +1,3 @@
 set pid = wmic process where "name like '%javaw%' and commandline like '%[sdk-minitor-1.0-RELEASE]%' " get processid
-echo pid
+echo %pid%
 taskkill -F /pid %pid%