Fix health check: RAM formula, exclude snap/overlay, use ASCII output
This commit is contained in:
+10
-10
@@ -28,32 +28,32 @@
|
|||||||
gather_facts: true
|
gather_facts: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Get disk usage
|
- name: Get disk usage (excluding snap, overlay, tmpfs)
|
||||||
ansible.builtin.shell: df -h --output=target,size,used,avail,pcent -x tmpfs -x devtmpfs | tail -n +2
|
ansible.builtin.shell: df -h --output=target,size,used,avail,pcent -x tmpfs -x devtmpfs -x squashfs -x overlay | tail -n +2
|
||||||
register: disk_usage
|
register: disk_usage
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Calculate memory percentage
|
- name: Calculate memory usage
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
mem_total_mb: "{{ ansible_memtotal_mb }}"
|
mem_total_mb: "{{ ansible_memtotal_mb }}"
|
||||||
mem_used_mb: "{{ ansible_memtotal_mb - ansible_memfree_mb - (ansible_memory_mb.nocache.free | default(0)) }}"
|
mem_used_mb: "{{ ansible_memory_mb.real.used }}"
|
||||||
mem_pct: "{{ (((ansible_memtotal_mb - ansible_memfree_mb) / ansible_memtotal_mb) * 100) | round(1) }}"
|
mem_pct: "{{ ((ansible_memory_mb.real.used / ansible_memtotal_mb) * 100) | round(1) }}"
|
||||||
swap_total_mb: "{{ ansible_swaptotal_mb }}"
|
swap_total_mb: "{{ ansible_swaptotal_mb }}"
|
||||||
swap_used_mb: "{{ ansible_swaptotal_mb - ansible_swapfree_mb }}"
|
swap_used_mb: "{{ ansible_swaptotal_mb - ansible_swapfree_mb }}"
|
||||||
|
|
||||||
- name: Print report
|
- name: Print report
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
══════════════════════════════════════════════════════
|
======================================================
|
||||||
HOST: {{ inventory_hostname }} ({{ ansible_host }})
|
HOST: {{ inventory_hostname }} ({{ ansible_host }})
|
||||||
OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
|
OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
|
||||||
═���════════════════════════════════════════════════════
|
======================================================
|
||||||
RAM: {{ mem_used_mb }}MB / {{ mem_total_mb }}MB ({{ mem_pct }}%)
|
RAM: {{ mem_used_mb }}MB / {{ mem_total_mb }}MB ({{ mem_pct }}%)
|
||||||
SWAP: {{ swap_used_mb }}MB / {{ swap_total_mb }}MB
|
SWAP: {{ swap_used_mb }}MB / {{ swap_total_mb }}MB
|
||||||
────���─────────────────────────────────��───────────────
|
------------------------------------------------------
|
||||||
DISK USAGE:
|
DISK:
|
||||||
{{ disk_usage.stdout }}
|
{{ disk_usage.stdout }}
|
||||||
══════════════════════════════════════════════════════
|
======================================================
|
||||||
|
|
||||||
- name: Warn on high disk usage (>85%)
|
- name: Warn on high disk usage (>85%)
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
|
|||||||
Reference in New Issue
Block a user