#!/bin/bash #获取逻辑CPU个数 processors=`cat /proc/cpuinfo | grep "processor" | wc -l` function cpu() { NUM=1 while [ $NUM -le $processors ]; do util=`vmstat |awk '{if(NR==3)print 100-$15"%"}'` user=`vmstat |awk '{if(NR==3)print $13"%"}'` sys=`vmstat |awk '{if(NR==3)print $14"%"}'` iowait=`vmstat |awk '{if(NR==3)print $16"%"}'` echo "CPU - 使用率: $util , 等待磁盘IO响应使用率: $iowait" let NUM++ sleep 1 done } function memory() { total=`free -g |awk '{if(NR==2)printf "%.1f",$2}'` used=`free -g |awk '{if(NR==2) printf "%.1f",$2-$NF}'` available=`free -g |awk '{if(NR==2) printf "%.1f",$NF}'` echo "内存 - 总大小: ${total}G , 使用: ${used}G , 剩余: ${available}G" } function 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
标签:status,used,df,awk,memory,print,NR,disk,cpu From: https://www.cnblogs.com/daizichuan/p/17489048.html