본문 바로가기

Ops/AWS

AWS Gamelift - 자원 사용량 체크 (ansible + jenkins)

반응형

AWS Gamelift - 자원 사용량 체크 (ansible + jenkins)

 

 

 

py 코드를 ansible을 통해 실시간으로 자원을 모니터링 하는 코드입니다. jenkins 및 ansible 세팅은 좋은 참고 자료가 많기 때문에 간략한 yaml 파일만 정리합니다.

 

chk_disk_linux.yml

#checkdiskspaceall.yml
---
- hosts: "{{passed_in_hosts}}"
  vars:
    ansible_user: ec2-user
  become_user: ec2-user
  become: yes
  become_method: sudo
  gather_facts: False
  tasks:
     - name: Test for available disk space
       setup: filter=ansible_mounts
     
     - name: Linux Ensure that free space on the tested volume is greater than 20%
       when: disk_usage_ratio|float > disk_limit|float
       vars:
         mount: "{{ ansible_mounts | selectattr('mount','equalto',item.mount) | list | first }}"
         send: "{{gamecode}} {{ec2_id}} in {{ec2_region}}: {{item.mount}} disk usage {{ disk_usage_s }} of total {{ disk_total_s }} ({{ disk_usage_ratio_s }}) (should be within limit {{ disk_limit_ratio_s }})"
         body: "{ 'key' : {{room_key}}, 'room' : {{room_id}}, 'msg' : test }"
         disk_usage: "{{ mount.size_total - mount.size_available }}"
         disk_usage_ratio: "{{ disk_usage|float / mount.size_total }}"
         disk_usage_s: "{{ (disk_usage|float / 1000000000) | round(1, 'common') }}GB"
         disk_total_s: "{{ (mount.size_total / 1000000000) | round(1, 'common') }}GB"
         disk_usage_ratio_s: "{{ 100 * (disk_usage_ratio|float) | round(1, 'common') }}%"
         disk_limit: "{{limit}}"
         disk_limit_ratio_s: "{{ (100 * disk_limit|float) |round }}%"
       uri:
         url: 
         method: POST
         body_format: form-urlencoded
         body:
           key:            
           msg: 
       with_items:
         - "{{ ansible_mounts }}"

 

 

 


by mkdir-chandler


 

 

 

 

 

728x90
반응형