From 9059b7a700633d87dfb13d3e62b749a90f13ab01 Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Fri, 13 Oct 2023 10:25:09 +0000 Subject: [PATCH 1/2] Add the monitor role Signed-off-by: Xavi Hernandez --- .../ansible/roles/monitor/tasks/start.yml | 15 +++++++++++++ .../ansible/roles/monitor/tasks/stop.yml | 20 ++++++++++++++++++ playbooks/hosts.update.yml | 1 + playbooks/roles/monitor/tasks/main.yml | 21 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 playbooks/ansible/roles/monitor/tasks/start.yml create mode 100644 playbooks/ansible/roles/monitor/tasks/stop.yml create mode 100644 playbooks/roles/monitor/tasks/main.yml diff --git a/playbooks/ansible/roles/monitor/tasks/start.yml b/playbooks/ansible/roles/monitor/tasks/start.yml new file mode 100644 index 00000000..caae5057 --- /dev/null +++ b/playbooks/ansible/roles/monitor/tasks/start.yml @@ -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 + > >(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 diff --git a/playbooks/ansible/roles/monitor/tasks/stop.yml b/playbooks/ansible/roles/monitor/tasks/stop.yml new file mode 100644 index 00000000..143d0913 --- /dev/null +++ b/playbooks/ansible/roles/monitor/tasks/stop.yml @@ -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" diff --git a/playbooks/hosts.update.yml b/playbooks/hosts.update.yml index d51a2957..70079ef3 100644 --- a/playbooks/hosts.update.yml +++ b/playbooks/hosts.update.yml @@ -9,3 +9,4 @@ - ansible/config.yml roles: - hosts.update + - monitor diff --git a/playbooks/roles/monitor/tasks/main.yml b/playbooks/roles/monitor/tasks/main.yml new file mode 100644 index 00000000..59114052 --- /dev/null +++ b/playbooks/roles/monitor/tasks/main.yml @@ -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 From 3fa8c545d05d05b20e7f75a32ae055a8f0df04b1 Mon Sep 17 00:00:00 2001 From: Xavi Hernandez Date: Fri, 13 Oct 2023 10:30:21 +0000 Subject: [PATCH 2/2] Add monitoring to each executed test Signed-off-by: Xavi Hernandez --- playbooks/ansible/client-test.yml | 2 +- playbooks/ansible/roles/tests/tasks/run-test.yml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/playbooks/ansible/client-test.yml b/playbooks/ansible/client-test.yml index f4346ab1..32bfc711 100644 --- a/playbooks/ansible/client-test.yml +++ b/playbooks/ansible/client-test.yml @@ -1,5 +1,5 @@ --- -- hosts: clients +- hosts: all become: yes become_method: sudo vars_files: diff --git a/playbooks/ansible/roles/tests/tasks/run-test.yml b/playbooks/ansible/roles/tests/tasks/run-test.yml index 6a83ecaa..805b5d08 100644 --- a/playbooks/ansible/roles/tests/tasks/run-test.yml +++ b/playbooks/ansible/roles/tests/tasks/run-test.yml @@ -5,18 +5,27 @@ line: "PREPARING {{ role }}" - name: Prepare test {{ role }} + when: inventory_hostname in groups['clients'] include_role: name: "{{ role }}" tasks_from: prepare/main.yml - name: Process test {{ role }} block: + - name: Start monitoring + include_role: + name: monitor + tasks_from: start.yml + vars: + name: "{{ role }}" + - name: Log test start time include_tasks: log.yml vars: line: "RUNNING {{ role }}" - name: Run test {{ role }} + when: inventory_hostname in groups['clients'] include_role: name: "{{ role }}" @@ -27,6 +36,7 @@ line: "RECOVERING {{ role }}" - name: Recover from failure of {{ role }} + when: inventory_hostname in groups['clients'] include_role: name: "{{ role }}" tasks_from: recover/main.yml @@ -41,7 +51,13 @@ vars: line: "FINISHED {{ role }}" + - name: Stop monitoring + include_role: + name: monitor + tasks_from: stop.yml + - name: Cleanup for {{ role }} + when: inventory_hostname in groups['clients'] include_role: name: "{{ role }}" tasks_from: cleanup/main.yml