ansible playbook,统计服务器 CPU、内存、磁盘利用率,3 条 shell 脚本实现统计
CPU 利用率统计:
top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'
内存利用率统计:
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
磁盘利用率统计(列出每块磁盘利用率):
df -h -t ext2 -t ext4 | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print "Disk Usage:"" " $1 " " $3"/"$2" ""("$5")"}'
[x@iZ2zed99h19kmb7fgbjcghZ ansible]$ cat server-cpu-mem-disk-usage.yml - hosts: hosts tasks: - name: "Statistics CPU Memory Disk Utilization..." shell: | free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }' df -h -t ext2 -t ext4 | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print "Disk Usage:"" " $1 " " $3"/"$2" ""("$5")"}' top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}' register: out - debug: var=out.stdout_lines
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论