mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-08-05 22:11:40 +08:00
优化语法结构
This commit is contained in:
parent
46beccb67a
commit
1b25ccc30d
@ -60,7 +60,6 @@ class DeliverTask extends Task
|
||||
break;
|
||||
default:
|
||||
$this->noMatchedHandler($order);
|
||||
break;
|
||||
}
|
||||
|
||||
$order->status = OrderModel::STATUS_FINISHED;
|
||||
|
@ -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()
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user