ansible 基础巡检


1.通过ansible 每天对线上的机器磁盘、内存、负载进行巡检

 

 

[root@BS003 probject]# cat cpu.yaml 

- name: Statistics CPU Memory Disk Utilization

  hosts: zabbix-agent

  tasks:

  become: no

  remote_user: "{{ user }}"

  gather_facts: no

  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

[root@BS003 probject]# 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM