The threshold we felt for slow disk speed is when it takes more than 0.10 secs to read and write 3000 lines for which we used the below play and get the real time it took.
- name: Extracting last 3000 lines from logs on "{{ inventory_hostname }}"
shell: "time tail -3000 {{ item }} > {{ item }}_last3klines"
register: diskspeed
loop: "{{ log }}"
- include_tasks: "{{ playbook_dir }}/printdiskspeed.yml"
loop: "{{ diskspeed.results }}"
loop_control:
loop_var: files
cat printdiskspeed.yml
- debug:
msg: "{{ files.stderr_lines[1].split()[1] }}"
Output:
TASK [debug] ******************************************************************
Wednesday 05 April 2023 23:54:18 -0500 (0:00:00.056) 0:00:17.689 *******
ok: [host3] => {
"msg": "0m0.03s"
}
TASK [debug] ******************************************************************
Wednesday 05 April 2023 23:54:18 -0500 (0:00:00.020) 0:00:17.709 *******
ok: [host3] => {
"msg": "0m0.02s"
}
TASK [debug] ******************************************************************
Wednesday 05 April 2023 23:54:18 -0500 (0:00:00.019) 0:00:17.729 *******
ok: [host3] => {
"msg": "0m0.02s"
}
TASK [debug] ******************************************************************
Wednesday 05 April 2023 23:54:18 -0500 (0:00:00.025) 0:00:17.754 *******
ok: [host1] => {
"msg": "0m0.02s"
}
TASK [debug] ******************************************************************
Wednesday 05 April 2023 23:54:18 -0500 (0:00:00.024) 0:00:17.779 *******
ok: [host1] => {
"msg": "0m0.01s"
}
TASK [debug] ******************************************************************
Wednesday 05 April 2023 23:54:18 -0500 (0:00:00.025) 0:00:17.804 *******
ok: [host1] => {
"msg": "0m0.02s"
}
I need help on how to compare and check if the time in the output above is greater than 0m0.10s?
I tried the below but it errors
- debug:
msg: "DISK SLOW"
when: "{{ files.stderr_lines[1].split()[1] }}" > "0m0.10s"
Output:
TASK [include_tasks] ****************************************************************************************************************************************
Wednesday 05 April 2023 23:36:24 -0500 (0:00:00.064) 0:00:18.779 *******
fatal: [host3]: FAILED! => {"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: Expecting value: line 1 column 4 (char 3)\n\nSyntax Error while loading YAML.\n did not find expected comment or line break\n\nThe error appears to be in '/web/playbooks/automation/printdiskspeed.yml': line 8, column 55, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n msg: \"DISK SLOW\"\n when: \"{{ files.stderr_lines[1].split()[1] }}\" > \"0m0.02s\"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}
Can you please suggest the right syntax / solution?