• 28/06 cập nhật đăng ký đăng nhập qua Google & Facebook

aaPanel Note

TenHoshi

Administrator
Staff member
Trusted Uploader

1. Tạo file script ramcheck​

Chạy lệnh này trên server:

nano /usr/local/bin/ramcheck

Rồi dán nguyên khối dưới đây vào:

Code:
#!/bin/bash
# ===========================
# ramcheck - Clean RAM Report
# ===========================
# Lấy số liệu từ free -k
read _ total used free shared buff_cache available <<< "$(free -k | awk '/Mem:/ {print $1,$2,$3,$4,$5,$6,$7}')"
swap_used_kb=$(free -k | awk '/Swap:/ {print $3}')
# Đổi KB → MB/GB
fmt() { local kb=$1 if [ "$kb" -ge 1048576 ]; then awk -v v="$kb" 'BEGIN {printf "%.2f GB", v/1048576}' else awk -v v="$kb" 'BEGIN {printf "%.0f MB", v/1024}' fi
}
# Sum RSS theo pattern (case-insensitive)
sum_rss() { ps axo rss,args --no-headers | awk -v p="$1" 'BEGIN{IGNORECASE=1} $0 ~ p {sum+=$1} END{print sum}'
}
# MySQL
mysql_kb=$(sum_rss "mariadbd|mysqld")
# Node.js
node_kb=$(sum_rss " node ")
# PHP-FPM
php_kb=$(sum_rss "php-fpm")
# aaPanel – lọc đúng process, KHÔNG cộng trùng
aapanel_kb=$( ps axo rss,args --no-headers | awk ' BEGIN {sum=0} /\/www\/server\/panel\/pyenv\/bin\/python3/ {sum+=$1; next} /BT-Panel/ {sum+=$1; next} /BT-Task/ {sum+=$1; next} /spawn_main/ && /venv\/bin\/python/ {sum+=$1; next} END {print sum}'
)
# App RAM (không tính cache)
app_used_kb=$(( used - buff_cache ))
[ "$app_used_kb" -lt 0 ] && app_used_kb=0
# RAM unknown
known_kb=$(( mysql_kb + node_kb + php_kb + aapanel_kb ))
others_kb=$(( app_used_kb - known_kb ))
[ "$others_kb" -lt 0 ] && others_kb=0
# Bảng đẹp
line="──────────────────────────────────────────────"
printf "┌$line┬───────────────┐\n"
printf "│ %-44s │ %-13s │\n" "Thành phần" "RAM dùng"
printf "├$line┼───────────────┤\n"
printf "│ %-44s │ %-13s │\n" "MySQL / MariaDB" "$(fmt "$mysql_kb")"
printf "│ %-44s │ %-13s │\n" "Node.js (PM2 / node)" "$(fmt "$node_kb")"
printf "│ %-44s │ %-13s │\n" "PHP-FPM" "$(fmt "$php_kb")"
printf "│ %-44s │ %-13s │\n" "aaPanel Python (BT-Panel/Task)" "$(fmt "$aapanel_kb")"
printf "│ %-44s │ %-13s │\n" "Linux file cache" "$(fmt "$buff_cache")"
printf "│ %-44s │ %-13s │\n" "System + nền tảng khác" "$(fmt "$others_kb")"
printf "│ %-44s │ %-13s │\n" "Swap used" "$(fmt "$swap_used_kb")"
printf "├$line┼───────────────┤\n"
printf "│ %-44s │ %-13s │\n" "Tổng RAM used (theo free)" "$(fmt "$used")"
printf "└$line┴───────────────┘\n"

Save lại:

Ctrl + O → Enter → Ctrl + X

Cấp quyền:

chmod +x /usr/local/bin/ramcheck

Chạy thử:

ramcheck

🎉 Giao diện bạn sẽ nhận được:

┌──────────────────────────────────────────────┬───────────────┐
│ Thành phần │ RAM dùng │
├──────────────────────────────────────────────┼───────────────┤
│ MySQL / MariaDB │ 430 MB │
│ Node.js (PM2 / node) │ 458 MB │
│ PHP-FPM │ 184 MB │
│ aaPanel Python (BT-Panel/Task) │ 360 MB │
│ Linux file cache │ 1.7 GB │
│ System + nền tảng khác │ 1.8 GB │
│ Swap used │ 908 MB │
├──────────────────────────────────────────────┼───────────────┤
│ Tổng RAM used (theo free) │ 5.8 GB │
└──────────────────────────────────────────────┴───────────────┘
 

Guest Post 2022

Bài viết gần đây

Top