Compare commits

...

3 Commits

Author SHA1 Message Date
whyour 78f643c50f 更新版本v2.14.7 2022-10-01 23:12:57 +08:00
whyour 2db4f1ba87 修改资源判定逻辑 2022-10-01 23:04:12 +08:00
whyour 5741dbb78c 修复获取task_before参数 2022-09-30 15:32:42 +08:00
2 changed files with 25 additions and 44 deletions
+20 -37
View File
@@ -127,16 +127,10 @@ 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
# eval echo -e "\#\# 当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \\\n" $cmd
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%"
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
local resource = $(top -b -n 1 | grep -v -E 'grep|Mem|idle|Load' | awk '{$2="";$3="";$4="";$5="";$7="";print $0}' | head -n 10)
notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \n资源占用详情 \n\n $resource"
fi
}
@@ -156,6 +150,15 @@ handle_task_before() {
eval . $file_task_before "$@" $cmd
}
handle_task_after() {
eval . $file_task_after "$@" $cmd
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local end_timestamp=$(date "+%s")
local 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
}
## 正常运行单个脚本,$1:传入参数
run_normal() {
local file_param=$1
@@ -163,7 +166,7 @@ run_normal() {
random_delay "$file_param"
fi
handle_task_before
handle_task_before "$@"
cd $dir_scripts
local relative_path="${file_param%/*}"
@@ -174,12 +177,7 @@ run_normal() {
eval $timeoutCmd $which_program $file_param $cmd
eval . $file_task_after "$@" $cmd
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local end_timestamp=$(date "+%s")
local diff_time=$(expr $end_timestamp - $begin_timestamp)
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time" $cmd
handle_task_after "$@"
}
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
@@ -192,7 +190,7 @@ run_concurrent() {
exit 1
fi
handle_task_before
handle_task_before "$@"
local envs=$(eval echo "\$${env_param}")
local array=($(echo $envs | sed 's/&/ /g'))
@@ -232,12 +230,7 @@ run_concurrent() {
[[ -f $single_log_path ]] && rm -f $single_log_path
done
eval . $file_task_after "$@" $cmd
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local end_timestamp=$(date "+%s")
local 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
handle_task_after "$@"
}
run_designated() {
@@ -249,7 +242,7 @@ run_designated() {
exit 1
fi
handle_task_before
handle_task_before "$@"
local envs=$(eval echo "\$${env_param}")
local array=($(echo $envs | sed 's/&/ /g'))
@@ -274,19 +267,14 @@ run_designated() {
fi
eval $timeoutCmd $which_program $file_param $cmd
eval . $file_task_after "$@" $cmd
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local end_timestamp=$(date "+%s")
local 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
handle_task_after "$@"
}
## 运行其他命令
run_else() {
local file_param="$1"
handle_task_before
handle_task_before "$@"
cd $dir_scripts
local relative_path="${file_param%/*}"
@@ -298,12 +286,7 @@ run_else() {
shift
eval $timeoutCmd $which_program "$file_param" "$@" $cmd
eval . $file_task_after "$file_param" "$@" $cmd
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local end_timestamp=$(date "+%s")
local 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
handle_task_after "$@"
}
## 命令检测
+5 -7
View File
@@ -1,8 +1,6 @@
export const version = '2.14.6';
export const changeLogLink = 'https://t.me/jiao_long/333';
export const changeLog = `2.14.6 版本说明
1. 任务执行日志增加资源占用说明
2. 配置文件config.sh增加资源配置参数CpuWarn/MemoryWarn/DiskWarn
3. 修复脚本管理和日志管理搜索
4. 其他bug修复
export const version = '2.14.7';
export const changeLogLink = 'https://t.me/jiao_long/334';
export const changeLog = `2.14.7 版本说明
1. 修复task_before无法获取任务执行参数
2. 修改资源判定逻辑
`;