nagios-nrpe : handle the case where cached_mem is in GB to convert it in MB in check_free_mem.sh

This commit is contained in:
Jérémy Dubois 2022-03-31 10:07:40 +02:00
parent eb96fd41b2
commit 40ed5b0437
2 changed files with 9 additions and 1 deletions

View File

@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- base: fix shell configuration, increase $HISTSIZE, and change history alias so it displays full history
- nagios-nrpe : handle the case where cached_mem is in GB to convert it in MB in check_free_mem.sh
### Removed

View File

@ -67,7 +67,14 @@ tot_mem=$(( `/sbin/sysctl -n hw.physmem` / BYTES_IN_MB))
{% if ansible_distribution_version is version_compare("6.2",'<') %}
free_mem=$(( `/usr/bin/vmstat | /usr/bin/tail -1 | /usr/bin/awk '{ print $5 }'` / KB_IN_MB ))
{% else %}
free_mem=$(($(/usr/bin/vmstat | /usr/bin/tail -1 | /usr/bin/awk '{ print $4 }' | tr -d 'M') + $(top -n | grep Memory | awk '{print $8}' | tr -d 'M')))
if [ "$(top -n | grep Memory | awk '{print $8}' | tr -d 'M')" == "$(top -n | grep Memory | awk '{print $8}' | tr -d 'G')G" ]; then
# If cached_mem = XG then cached_mem = X*1024M
cached_mem=$(($(top -n | grep Memory | awk '{print $8}' | tr -d 'G') * 1024))
else
# Else, cached_mem = XM
cached_mem=$(top -n | grep Memory | awk '{print $8}' | tr -d 'M')
fi
free_mem=$(($(/usr/bin/vmstat | /usr/bin/tail -1 | /usr/bin/awk '{ print $4 }' | tr -d 'M') + $cached_mem))
{% endif %}
# Free memory size (in percentage)
free_mem_perc=$(( free_mem * 100 / tot_mem ))