简单脚本统计
#!/bin/bash
# 获取磁盘使用率
disk_usage=$(df -h --total | tail -n 1 | awk '{print $5}')
#echo "磁盘使用率: ${disk_usage}"
cpuch=$(top -b -n 1 | awk '/^%Cpu/ {
total_usage = $2 + $4
print total_usage
}')
free_sum=`free -m|grep Mem:|awk '{print $3/$2 }'`
result=$(echo "$free_sum * 100" | bc)
#printf "内存使用率: %.2f%%\n" $result
memin=$(printf "%.2f%%\n" $result)
cpu_cores=$(nproc)
#echo "CPU核数: $cpu_cores"
total_disk=$(df -h --total | tail -n 1 | awk '{print $2}')
#echo "磁盘总量: $total_disk"
mem_count=$(free -m|grep Mem|awk '{print $2}')
echo "cpu使用率 磁盘使用率 内存使用率 cpu核数 内存总大小M 磁盘总大小
${cpuch}% ${disk_usage} ${memin} $cpu_cores ${mem_count}M ${total_disk}"