From 9a55968ed6020ee1182f9b1c0afb7e70f02e32bf Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 29 Sep 2022 13:29:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E6=BA=90=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/task.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/shell/task.sh b/shell/task.sh index 46486efc..7d402026 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -128,18 +128,14 @@ check_server() { disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%") eval echo -e "\#\# 当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \\\n" $cmd - if [[ $cpu_use -gt $cpu_warn ]]; then - notify_api "CPU异常警告" "当前CPU占用 $cpu_use%" - exit 1 - fi + if [[ $cpu_use -gt $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then + echo -e "\#\# 服务器资源占用异常,本次任务跳过执行" $cmd + notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use%" - if [[ $mem_free -lt $mem_warn ]]; then - notify_api "内存异常警告" "当前内存占用 $mem_use%" - exit 1 - fi - - if [[ $disk_use -gt $disk_warn ]]; then - notify_api "磁盘异常警告" "当前磁盘占用 $disk_use%" + end_time=$(date '+%Y-%m-%d %H:%M:%S') + diff_time=$(($end_timestamp - $begin_timestamp)) + [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" + eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd exit 1 fi }