Browse Source

监控脚本

shensong 5 years ago
parent
commit
65df4acf2e
2 changed files with 22 additions and 6 deletions
  1. 13 3
      app/Console/Commands/ErrorLogMonitor.php
  2. 9 3
      app/Console/Commands/SyncMjWarehouse.php

+ 13 - 3
app/Console/Commands/ErrorLogMonitor.php

@@ -25,8 +25,17 @@ class ErrorLogMonitor extends Command {
25 25
     {
26 26
         //本地测试路径
27 27
 //        $path = dirname(__FILE__).'\..\..\..\public';
28
-$path = '\log\seafood_log\error';
29
-        $fileName = '\\'.date('Y-m-d',time()).'.txt';
28
+        $path1 = '/log/seafood_log/error';
29
+        $res1 = $this->chargeFile($path1);
30
+        $path2 = '/log/seafood_log/script_error';
31
+        $res2 = $this->chargeFile($path2);
32
+        if($res1 || $res2){
33
+            $this->sendMsg('13161864516');
34
+        }
35
+    }
36
+
37
+    public function chargeFile($path){
38
+        $fileName = '/'.date('Y-m-d',time()).'.txt';
30 39
         //判断文件是否存在
31 40
         $fileName = $path.$fileName;
32 41
         $fileRes = file_exists($fileName);
@@ -39,9 +48,10 @@ $path = '\log\seafood_log\error';
39 48
             //判断最后一行时间是否在3分钟内
40 49
             if(time()-$time <= 180){
41 50
                 //报警
42
-                $this->sendMsg('13161864516');
51
+                return true;
43 52
             }
44 53
         }
54
+        return false;
45 55
     }
46 56
 
47 57
     //获取文件最后一行内容

+ 9 - 3
app/Console/Commands/SyncMjWarehouse.php

@@ -32,7 +32,10 @@ class SyncMjWarehouse extends Command {
32 32
     {
33 33
         try {
34 34
             $this->SyncMjWarehouse();
35
-//            $this->diffRealPriceSkuListArr = array('banjiexia-03','csxpxx-01');
35
+//            $this->diffRealPriceSkuListArr = array(
36
+//                0=>array('code'=>'banjiexia-03','oldPrice'=>'10','newPrice'=>'20'),
37
+//                1=>array('code'=>'csxpxx-01','oldPrice'=>'100','newPrice'=>'50'),
38
+//            );
36 39
             if (count($this->diffRealPriceSkuListArr) > 0) {
37 40
                 $this->skuRealPriceMonitor();
38 41
             }
@@ -102,7 +105,10 @@ class SyncMjWarehouse extends Command {
102 105
                         if($oldRealPrice != 0){
103 106
                             $result = $this->getNumberDiffAbs($newRealPrice,$oldRealPrice);
104 107
                             if($result >= 0.1){
105
-                                $this->diffRealPriceSkuListArr[] = $code;
108
+                                $json['code'] = $code;
109
+                                $json['oldPrice'] = $oldRealPrice;
110
+                                $json['newPrice'] = $newRealPrice;
111
+                                $this->diffRealPriceSkuListArr[] = $json;
106 112
                             }
107 113
                         }
108 114
                     }
@@ -129,7 +135,7 @@ class SyncMjWarehouse extends Command {
129 135
         #发送验证码报警
130 136
         $this->sendMsg('13161864516',$text);
131 137
         $this->sendMsg('18410900527',$text);
132
-        error_log(date('Y-m-d H:i:s',time()).' skuList:'.$text." \n ",3,"/log/seafood_log/script_success/".date('Y-m-d',time()).'MonitorRealPrice.log');
138
+//        error_log(date('Y-m-d H:i:s',time()).' skuList:'.$text." \n ",3,"/log/seafood_log/script_success/".date('Y-m-d',time()).'MonitorRealPrice.log');
133 139
 
134 140
     }
135 141