mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 15:43:24 +08:00
添加系统资源消耗提示
This commit is contained in:
parent
654b51e476
commit
5530ce76e3
|
@ -35,8 +35,7 @@ fi
|
||||||
cp -f "$repo_path/jbot/requirements.txt" "$dir_data"
|
cp -f "$repo_path/jbot/requirements.txt" "$dir_data"
|
||||||
|
|
||||||
cd $dir_data
|
cd $dir_data
|
||||||
cat requirements.txt | while read LREAD
|
cat requirements.txt | while read LREAD; do
|
||||||
do
|
|
||||||
if [[ ! $(pip3 show "${LREAD%%=*}" 2>/dev/null) ]]; then
|
if [[ ! $(pip3 show "${LREAD%%=*}" 2>/dev/null) ]]; then
|
||||||
pip3 --default-timeout=100 install ${LREAD}
|
pip3 --default-timeout=100 install ${LREAD}
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -78,6 +78,10 @@ import_config() {
|
||||||
else
|
else
|
||||||
default_cron="$(random_range 0 59) $(random_range 0 23) * * *"
|
default_cron="$(random_range 0 59) $(random_range 0 23) * * *"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cpu_warn=${CpuWarn:-80}
|
||||||
|
mem_warn=${MemoryWarn:-80}
|
||||||
|
disk_warn=${DiskWarn:-90}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_proxy() {
|
set_proxy() {
|
||||||
|
|
|
@ -118,6 +118,47 @@ handle_log_path() {
|
||||||
make_dir "$dir_log/$log_dir"
|
make_dir "$dir_log/$log_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_server() {
|
||||||
|
cpu_idle=$(top -b -n 1 | grep Cpu | awk '{print $8}' | cut -f 1 -d "%")
|
||||||
|
eval echo -e "当前CPU占用 $cpu_use " $cmd
|
||||||
|
if [[ $cpu_use -gt $cpu_warn ]]; then
|
||||||
|
notify_api "CPU异常警告" "当前CPU占用 $cpu_use%"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mem_free=$(free -m | grep "Mem" | awk '{print $3}')
|
||||||
|
mem_total=$(free -m | grep "Mem" | awk '{print $2}')
|
||||||
|
mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%")
|
||||||
|
eval echo -e "内存剩余 $mem_use% " $cmd
|
||||||
|
if [[ $mem_free -lt $mem_warn ]]; then
|
||||||
|
notify_api "内存异常警告" "当前内存占用 $mem_use%"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%")
|
||||||
|
eval echo -e "磁盘占用 $disk_use% \\\n" $cmd
|
||||||
|
if [[ $disk_use -gt $disk_warn ]]; then
|
||||||
|
notify_api "磁盘异常警告" "当前磁盘占用 $disk_use%"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_task_before() {
|
||||||
|
handle_log_path
|
||||||
|
|
||||||
|
begin_time=$(format_time "$time_format" "$time")
|
||||||
|
begin_timestamp=$(format_timestamp "$time_format" "$time")
|
||||||
|
|
||||||
|
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||||
|
|
||||||
|
[[ $is_macos -eq 0 ]] && check_server
|
||||||
|
|
||||||
|
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
||||||
|
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||||
|
eval . $file_task_before "$@" $cmd
|
||||||
|
}
|
||||||
|
|
||||||
## 正常运行单个脚本,$1:传入参数
|
## 正常运行单个脚本,$1:传入参数
|
||||||
run_normal() {
|
run_normal() {
|
||||||
local file_param=$1
|
local file_param=$1
|
||||||
|
@ -125,16 +166,7 @@ run_normal() {
|
||||||
random_delay "$file_param"
|
random_delay "$file_param"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
handle_log_path
|
handle_task_before
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
|
||||||
eval . $file_task_before "$@" $cmd
|
|
||||||
|
|
||||||
cd $dir_scripts
|
cd $dir_scripts
|
||||||
local relative_path="${file_param%/*}"
|
local relative_path="${file_param%/*}"
|
||||||
|
@ -163,6 +195,8 @@ run_concurrent() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
handle_task_before
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
|
@ -178,17 +212,6 @@ run_concurrent() {
|
||||||
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
||||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||||
|
|
||||||
handle_log_path
|
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
|
||||||
eval . $file_task_before "$@" $cmd
|
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
||||||
|
@ -229,10 +252,7 @@ run_designated() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
handle_log_path
|
handle_task_before
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
|
@ -249,12 +269,6 @@ run_designated() {
|
||||||
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
||||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
|
||||||
eval . $file_task_before "$@" $cmd
|
|
||||||
|
|
||||||
cd $dir_scripts
|
cd $dir_scripts
|
||||||
local relative_path="${file_param%/*}"
|
local relative_path="${file_param%/*}"
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
@ -275,15 +289,7 @@ run_designated() {
|
||||||
run_else() {
|
run_else() {
|
||||||
local file_param="$1"
|
local file_param="$1"
|
||||||
|
|
||||||
handle_log_path
|
handle_task_before
|
||||||
|
|
||||||
local begin_time=$(format_time "$time_format" "$time")
|
|
||||||
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
|
||||||
eval . $file_task_before "$@" $cmd
|
|
||||||
|
|
||||||
cd $dir_scripts
|
cd $dir_scripts
|
||||||
local relative_path="${file_param%/*}"
|
local relative_path="${file_param%/*}"
|
||||||
|
@ -306,8 +312,7 @@ run_else() {
|
||||||
## 命令检测
|
## 命令检测
|
||||||
main() {
|
main() {
|
||||||
show_log="false"
|
show_log="false"
|
||||||
while getopts ":l" opt
|
while getopts ":l" opt; do
|
||||||
do
|
|
||||||
case $opt in
|
case $opt in
|
||||||
l)
|
l)
|
||||||
show_log="true"
|
show_log="true"
|
||||||
|
|
|
@ -416,8 +416,7 @@ get_uniq_path() {
|
||||||
main() {
|
main() {
|
||||||
## for ql update
|
## for ql update
|
||||||
show_log="false"
|
show_log="false"
|
||||||
while getopts ":l" opt
|
while getopts ":l" opt; do
|
||||||
do
|
|
||||||
case $opt in
|
case $opt in
|
||||||
l)
|
l)
|
||||||
show_log="true"
|
show_log="true"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user