[root@ecpaase01 ansible]# cat server-cpu-mem-disk-usage.yaml
---
- name: Statistics CPU Memory Disk Utilization
hosts: all
become: no
remote_user: root
gather_facts: no
tasks:
- name: "Statistics CPU Memory Disk Utilization..."
shell: |
top -bn1 | grep Cpu |awk '{printf "Cpu usage: (%.2f%%)\n", 100-$8 }'
register: out
- debug: var=out.stdout_lines
[root@ecpaase01 ansible]# cat cpu.sh
#!/bin/bash
grep -E "=>|Cpu" cpu1.txt >cpu2.txt
sed -n '{N;s/\n/\t/p}' cpu2.txt >cpu3.txt
sed -i 's/[[:space:]]*//g' cpu3.txt
sed -i 's/ok://g' cpu3.txt
sed -i 's/{//g' cpu3.txt
sed -i 's/\[//g' cpu3.txt
sed -i 's/]//g' cpu3.txt
sed -i 's/\"//g' cpu3.txt
sed -i 's/(//g' cpu3.txt
sed -i 's/)//g' cpu3.txt
sed -i 's/>//g' cpu3.txt
sed -i 's/=/_/g' cpu3.txt
sed -i 's/usage/使用率/g' cpu3.txt
[root@ecpaase01 ansible]# cat cpucheck.sh
#/bin/bash
ansible-playbook server-cpu-mem-disk-usage.yaml >cpu1.txt
sh /etc/ansible/cpu.sh
cat /etc/ansible/cpu3.txt
网友评论