Skip to content

Commit

Permalink
Add the monitor role
Browse files Browse the repository at this point in the history
Signed-off-by: Xavi Hernandez <[email protected]>
  • Loading branch information
xhernandez committed Oct 13, 2023
1 parent f03565a commit 561bc45
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions playbooks/ansible/roles/monitor/tasks/start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Stop monitoring if enabled
include_tasks: stop.yml

- name: Launch background sadc monitoring
shell:
executable: /bin/bash
cmd: >-
nohup /usr/lib64/sa/sadc -S XALL 1 </dev/null 2>/dev/null
> >(nohup xz - >{{ config.statedir }}/sadc_{{ name }}.xz 2>/dev/null) &
echo ${!} >/tmp/sadc.pid
- name: Wait few seconds to monitor idle activity
pause:
seconds: 5
20 changes: 20 additions & 0 deletions playbooks/ansible/roles/monitor/tasks/stop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Check if sadc is running
stat:
path: /tmp/sadc.pid
get_attributes: false
get_checksum: false
get_mime: false
register: sadc_pid

- name: Stop sadc if running
when: sadc_pid.stat.exists
block:
- name: Wait few seconds to monitor idle activity
pause:
seconds: 5

- name: Stop sadc
shell:
executable: /bin/bash
cmd: "kill -TERM $(cat /tmp/sadc.pid) && rm -f /tmp/sadc.pid"
1 change: 1 addition & 0 deletions playbooks/hosts.update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
- ansible/config.yml
roles:
- hosts.update
- monitor
21 changes: 21 additions & 0 deletions playbooks/roles/monitor/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Install sysstat
yum:
name: sysstat
state: latest

- name: Disable sysstat service and timers
systemd:
name: "{{ item }}"
enabled: false
masked: true
state: stopped
loop:
- sysstat
- sysstat-collect.timer
- sysstat-summary.timer

- name: Make sure statedir is present
file:
path: "{{ config.statedir }}"
state: directory

0 comments on commit 561bc45

Please sign in to comment.