From 1b25ccc30d47ed9660d5f4294178f44c2b19af6b Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Mon, 28 Nov 2022 19:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=AD=E6=B3=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/DeliverTask.php | 1 - app/Console/Tasks/ServerMonitorTask.php | 44 ++++++++++++++++--------- app/Library/Utils/ServerInfo.php | 4 +-- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index 41608ae9..1e34d458 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -60,7 +60,6 @@ class DeliverTask extends Task break; default: $this->noMatchedHandler($order); - break; } $order->status = OrderModel::STATUS_FINISHED; diff --git a/app/Console/Tasks/ServerMonitorTask.php b/app/Console/Tasks/ServerMonitorTask.php index 897d5999..1ac2e14b 100644 --- a/app/Console/Tasks/ServerMonitorTask.php +++ b/app/Console/Tasks/ServerMonitorTask.php @@ -10,7 +10,7 @@ namespace App\Console\Tasks; use App\Library\Benchmark; use App\Models\User as UserModel; use App\Services\Logic\Notice\External\DingTalk\ServerMonitor as ServerMonitorNotice; -use App\Services\Search\UserSearcher; +use App\Services\Search\CourseSearcher; use GatewayClient\Gateway; class ServerMonitorTask extends Task @@ -56,6 +56,8 @@ class ServerMonitorTask extends Task if ($load[1] > $cpuCount * 0.8) { return sprintf("cpu负载超过%s", $load[1]); } + + return null; } protected function checkMemory() @@ -64,25 +66,27 @@ class ServerMonitorTask extends Task $total = null; - if (preg_match('/MemTotal\:\s+(\d+) kB/', $memInfo, $totalMatches)) { + if (preg_match('/MemTotal:\s+(\d+) kB/', $memInfo, $totalMatches)) { $total = $totalMatches[1]; } - if ($total === null) return; + if ($total === null) return null; $available = null; - if (preg_match('/MemAvailable\:\s+(\d+) kB/', $memInfo, $avaMatches)) { + if (preg_match('/MemAvailable:\s+(\d+) kB/', $memInfo, $avaMatches)) { $available = $avaMatches[1]; } - if ($available === null) return; + if ($available === null) return null; $left = 100 * ($available / $total); if ($left < 20) { return sprintf("memory剩余不足%s%%", round($left)); } + + return null; } protected function checkDisk() @@ -95,6 +99,8 @@ class ServerMonitorTask extends Task if ($left < 20) { return sprintf("disk剩余不足%s%%", round($left)); } + + return null; } protected function checkMysql() @@ -111,8 +117,8 @@ class ServerMonitorTask extends Task $elapsedTime = $benchmark->getElapsedTime(); - if ($user === false) { - return sprintf("mysql查询失败"); + if (!$user) { + return "mysql查询失败"; } if ($elapsedTime > 1) { @@ -120,8 +126,10 @@ class ServerMonitorTask extends Task } } catch (\Exception $e) { - return sprintf("mysql可能存在异常"); + return "mysql可能存在异常"; } + + return null; } protected function checkRedis() @@ -139,7 +147,7 @@ class ServerMonitorTask extends Task $elapsedTime = $benchmark->getElapsedTime(); if (empty($site)) { - return sprintf("redis查询失败"); + return "redis查询失败"; } if ($elapsedTime > 1) { @@ -147,8 +155,10 @@ class ServerMonitorTask extends Task } } catch (\Exception $e) { - return sprintf("redis可能存在异常"); + return "redis可能存在异常"; } + + return null; } protected function checkXunsearch() @@ -159,16 +169,16 @@ class ServerMonitorTask extends Task $benchmark->start(); - $searcher = new UserSearcher(); + $searcher = new CourseSearcher(); - $user = $searcher->search('id:10000'); + $user = $searcher->search('id:1'); $benchmark->stop(); $elapsedTime = $benchmark->getElapsedTime(); if (empty($user)) { - return sprintf("xunsearch搜索失败"); + return "xunsearch搜索失败"; } if ($elapsedTime > 1) { @@ -176,8 +186,10 @@ class ServerMonitorTask extends Task } } catch (\Exception $e) { - return sprintf("xunsearch可能存在异常"); + return "xunsearch可能存在异常"; } + + return null; } protected function checkWebsocket() @@ -203,8 +215,10 @@ class ServerMonitorTask extends Task } } catch (\Exception $e) { - return sprintf("websocket可能存在异常"); + return "websocket可能存在异常"; } + + return null; } protected function getCpuCount() diff --git a/app/Library/Utils/ServerInfo.php b/app/Library/Utils/ServerInfo.php index ea3603fa..4d8b6b4f 100644 --- a/app/Library/Utils/ServerInfo.php +++ b/app/Library/Utils/ServerInfo.php @@ -31,13 +31,13 @@ class ServerInfo $total = 0; - if (preg_match('/MemTotal\:\s+(\d+) kB/', $mem, $totalMatches)) { + if (preg_match('/MemTotal:\s+(\d+) kB/', $mem, $totalMatches)) { $total = $totalMatches[1]; } $free = 0; - if (preg_match('/MemFree\:\s+(\d+) kB/', $mem, $freeMatches)) { + if (preg_match('/MemFree:\s+(\d+) kB/', $mem, $freeMatches)) { $free = $freeMatches[1]; }