背景:web訪問過慢,服務器內存搞
cpu 60%
內存 利用率
硬盤 利用率
TCP鏈接狀態web
#!/bin/bash function cpu(){ util=$(vmstat | awk '{if(NR==3)print $13+$14}') iowait=$(vmstat | awk '{if(NR==3)print $16}') echo "CPU -使用率:${util}% ,等待磁盤IO相應使用率:${iowait}:${iowait}%" } function memory (){ total=`free -m |awk '{if(NR==2)printf "%.1f",$2/1024}'` used=`free -m |awk '{if(NR==2) printf "%.1f",($2-$NF)/1024}'` available=`free -m |awk '{if(NR==2) printf "%.1f",$NF/1024}'` echo "內存 - 總大小: ${total}G , 使用: ${used}G , 剩餘: ${available}G" } disk(){ fs=$(df -h |awk '/^\/dev/{print $1}') for p in $fs; do mounted=$(df -h |awk '$1=="'$p'"{print $NF}') size=$(df -h |awk '$1=="'$p'"{print $2}') used=$(df -h |awk '$1=="'$p'"{print $3}') used_percent=$(df -h |awk '$1=="'$p'"{print $5}') echo "硬盤 - 掛載點: $mounted , 總大小: $size , 使用: $used , 使用率: $used_percent" done } function tcp_status() { summary=$(ss -antp |awk '{status[$1]++}END{for(i in status) printf i":"status[i]" "}') echo "TCP鏈接狀態 - $summary" } cpu memory disk tcp_status