1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| cat > /root/panel_cn.sh << 'EOF'
export LC_ALL=C printf '\033[2J' printf '\033[1;36m══════════════════════════════════════════════\033[0m\n' printf '\033[1;36m 系统资源面板 (每2秒刷新)\033[0m\n' printf '\033[1;36m══════════════════════════════════════════════\033[0m\n'
hostname=$(hostname) kernel=$(uname -r) uptime_str=$(awk '{print int($1)}' /proc/uptime) uptime_h=$((uptime_str/3600)) uptime_m=$(( (uptime_str%3600)/60 )) cpu_model="骁龙 410 " cores=$(nproc) freq=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq 2>/dev/null) if [ -n "$freq" ]; then freq=$((freq/1000))" MHz" else freq="未知" fi
printf "\033[1;37m主机名:\033[0m %-10s \033[1;37m内核:\033[0m %-16s \033[1;37m运行时间:\033[0m %d小时%d分\n" "$hostname" "$kernel" $uptime_h $uptime_m printf "\033[1;37mCPU 型号:\033[0m %-10s \033[1;37m核心数:\033[0m %d \033[1;37m频率:\033[0m %s\n" "$cpu_model" $cores "$freq"
read cpu a b c idle rest < /proc/stat sleep 0.3 read cpu a2 b2 c2 idle2 rest2 < /proc/stat total1=$((a+b+c+idle)) total2=$((a2+b2+c2+idle2)) idle_diff=$((idle2-idle)) total_diff=$((total2-total1)) if [ $total_diff -gt 0 ]; then cpu_pct=$((100*(total_diff-idle_diff)/total_diff)) usr_pct=$((100*(a2-a)/total_diff)) sys_pct=$((100*(b2-b)/total_diff)) idle_pct=$((100*idle_diff/total_diff)) else cpu_pct=0; usr_pct=0; sys_pct=0; idle_pct=100 fi bars=$((cpu_pct/10)) printf "\033[1;37mCPU 使用率:\033[0m [" for i in $(seq 1 $bars); do printf "\033[1;32m█\033[0m"; done for i in $(seq $((10-bars))); do printf "░"; done printf "] %d%%\t用户 %d%% 系统 %d%% 空闲 %d%%\n" $cpu_pct $usr_pct $sys_pct $idle_pct
printf "\033[1;37m──────────────────────────────────────────────\033[0m\n"
mem_line=$(free | awk '/^Mem|^内存/{print $2,$3,$4,$5,$6,$7}') [ -z "$mem_line" ] && mem_line=$(free | awk '/^Mem:/{print $2,$3,$4,$5,$6,$7}') total_kb=$(echo $mem_line | awk '{print $1}') used_kb=$(echo $mem_line | awk '{print $2}') free_kb=$(echo $mem_line | awk '{print $3}') shared_kb=$(echo $mem_line | awk '{print $4}') cache_kb=$(echo $mem_line | awk '{print $5}') avail_kb=$(echo $mem_line | awk '{print $6}') conv() { kb=$1 if [ $kb -ge 1048576 ]; then printf "%.1fGi" $(echo "scale=1; $kb/1048576" | bc 2>/dev/null || echo "0") elif [ $kb -ge 1024 ]; then printf "%.0fMi" $(echo "scale=0; $kb/1024" | bc 2>/dev/null || echo "0") else printf "%.0fKi" $kb fi } printf "\033[1;33m▶ 内存\033[0m\n" printf " %-6s %-6s %-6s %-6s %-10s %-6s\n" "总计" "已用" "空闲" "共享" "缓冲/缓存" "可用" printf " %-6s %-6s %-6s %-6s %-10s %-6s\n" "$(conv $total_kb)" "$(conv $used_kb)" "$(conv $free_kb)" "$(conv $shared_kb)" "$(conv $cache_kb)" "$(conv $avail_kb)"
swap_line=$(free | awk '/^Swap|^交换/{print $2,$3}') if [ -n "$swap_line" ]; then swap_total_kb=$(echo $swap_line | awk '{print $1}') swap_used_kb=$(echo $swap_line | awk '{print $2}') [ $swap_total_kb -gt 0 ] && swap_pct=$((100*swap_used_kb/swap_total_kb)) || swap_pct=0 printf "交换: %s / %s (%d%%)\n" "$(conv $swap_used_kb)" "$(conv $swap_total_kb)" $swap_pct fi
printf "\033[1;37m──────────────────────────────────────────────\033[0m\n"
disk_line=$(df -h / | tail -1) printf "\033[1;33m▶ 根目录磁盘 /\033[0m 总:%s 已用:%s 可用:%s (%s)\n" $(echo $disk_line | awk '{print $2,$3,$4,$5}')
printf "\033[1;37m──────────────────────────────────────────────\033[0m\n"
iface=$(ip route show default 2>/dev/null | awk '{print $5}' | head -1) [ -z "$iface" ] && iface=$(ls /sys/class/net/ | grep -v lo | head -1) if [ -n "$iface" ]; then ip_addr=$(ip -4 addr show $iface | grep inet | awk '{print $2}' | head -1) rx1=$(cat /sys/class/net/$iface/statistics/rx_bytes 2>/dev/null || echo 0) tx1=$(cat /sys/class/net/$iface/statistics/tx_bytes 2>/dev/null || echo 0) sleep 0.3 rx2=$(cat /sys/class/net/$iface/statistics/rx_bytes 2>/dev/null || echo 0) tx2=$(cat /sys/class/net/$iface/statistics/tx_bytes 2>/dev/null || echo 0) rx_speed=$(( (rx2-rx1)*10/3 )) tx_speed=$(( (tx2-tx1)*10/3 )) format_speed() { speed=$1 if [ $speed -gt 1048576 ]; then printf "%.1f MB/s" $(echo "scale=1; $speed/1048576" | bc 2>/dev/null || echo "0") elif [ $speed -gt 1024 ]; then printf "%.1f KB/s" $(echo "scale=1; $speed/1024" | bc 2>/dev/null || echo "0") else printf "%d B/s" $speed fi } printf "\033[1;33m▶ 网络 (%s)\033[0m IP: %s\n" "$iface" "$ip_addr" printf " 接收: %s 发送: %s\n" "$(format_speed $rx_speed)" "$(format_speed $tx_speed)" else printf "\033[1;33m▶ 网络\033[0m 无活动接口\n" fi
printf "\033[1;37m──────────────────────────────────────────────\033[0m\n"
load=$(cat /proc/loadavg | awk '{print $1,$2,$3}') printf "\033[1;33m▶ 负载 (1/5/15min):\033[0m %s\n" "$load"
temp=$(cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null) if [ -n "$temp" ]; then printf "\033[1;33m▶ CPU 温度:\033[0m %d°C\n" $((temp/1000)) else printf "\033[1;33m▶ CPU 温度:\033[0m 无传感器\n" fi
printf "\033[1;37m──────────────────────────────────────────────\033[0m\n"
printf "\033[1;33m▶ 最耗 CPU 的 3 个进程\033[0m\n" ps aux --sort=-%cpu | grep -vE "watch|ttyd|panel_cn|grep|ps" | awk 'NR>1{printf " %-10s %5.1f%%\n", $11, $3}' | head -3 printf "\033[1;33m▶ 最耗内存的 3 个进程\033[0m\n" ps aux --sort=-%mem | grep -vE "watch|ttyd|panel_cn|grep|ps" | awk 'NR>1{printf " %-10s %6s\n", $11, $6}' | head -3 EOF
chmod +x /root/panel_cn.sh
|