Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update check_mem.pl memory array values to match output of free from procps-ng 3.3.17 and 4.04 #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VGerris
Copy link

@VGerris VGerris commented May 22, 2024

Tested on Ubuntu 22.04.
I noticed when running the check, the swap values were incorrect on a machine with no swap. After investigating it turned out the values of the output seem to be mapped incorrectly ( for mentioned versions ).

This PR corrects that.

…procps-ng 3.3.17 and free from procps-ng 4.0.4
@VGerris
Copy link
Author

VGerris commented May 22, 2024

Tested :

root@gitlab-server:/usr/lib/nagios/plugins# free -mt
               total        used        free      shared  buff/cache   available
Mem:            7937        4403         173          16        3360        3213
Swap:           2047           1        2046
Total:          9985        4404        2220

root@gitlab-server:/usr/lib/nagios/plugins# ./check_mem.pl -w 90,25 -c 95,50
OK: Memory Usage (W> 90, C> 95): 56% <br>Swap Usage (W> 25, C> 50): 0%|MemUsed=56%;90;95 SwapUsed=0%;25;50

root@gitlab-server:/usr/lib/nagios/plugins# swapoff /mnt/swapfile
root@gitlab-server:/usr/lib/nagios/plugins# free -mt
               total        used        free      shared  buff/cache   available
Mem:            7937        4420         174          17        3342        3195
Swap:              0           0           0
Total:          7937        4420         174
root@gitlab-server:/usr/lib/nagios/plugins# ./check_mem.pl -w 90,25 -c 95,50
OK: Memory Usage (W> 90, C> 95): 56% <br>Swap Usage (W> 25, C> 50): 0%|MemUsed=56%;90;95 SwapUsed=0%;25;50

Printed mapping of the memory array in the script :

0 : total
1 : used
2 : free
3 : shared
4 : buff/cache
5 : available
6 : Mem:
7 : 7937
8 : 4411
9 : 168
10 : 16
11 : 3358
12 : 3205
13 : Swap:
14 : 2047
15 : 1
16 : 2046
17 : Total:
18 : 9985
19 : 4412
20 : 2215

So before the change, swap would be calculated as the total of mem and swap :

root@gitlab-server:/usr/lib/nagios/plugins# ./check_mem.pl -w 90,25 -c 95,50
<b>CRITICAL: Memory Usage (W> 90, C> 95): 56% <br>Swap Usage (W> 25, C> 50): 56%</b>|MemUsed=56%;90;95 SwapUsed=56%;25;50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant