2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-05 01:48:43 +08:00
Files
panel/scripts/calculate_j.sh
2024-06-18 00:32:47 +08:00

60 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
: '
Copyright (C) 2022 - now HaoZi Technology Co., Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'
# 计算 j 值(通用)
calculate_j() {
export LC_ALL=C
mem=$(free -m | awk '/^Mem:/{print $2}')
swap=$(free -m | awk '/^Swap:/{print $2}')
total=$((mem + swap))
j_value=$((total / 1024))
cpu_cores=$(nproc)
if [ $j_value -eq 0 ]; then
j_value=1
fi
if [ $j_value -gt "$cpu_cores" ]; then
j_value=$cpu_cores
fi
echo "$j_value"
}
# 计算 j 值2倍内存
calculate_j2() {
export LC_ALL=C
mem=$(free -m | awk '/^Mem:/{print $2}')
swap=$(free -m | awk '/^Swap:/{print $2}')
total=$((mem + swap))
j_value=$((total / 2024))
cpu_cores=$(nproc)
if [ $j_value -eq 0 ]; then
j_value=1
fi
if [ $j_value -gt "$cpu_cores" ]; then
j_value=$cpu_cores
fi
echo "$j_value"
}