diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-07-17 11:33:57 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-07-17 11:33:57 +0200 |
commit | 3bc32d9ebd9b0900eeef756122ad28f8857f8bfe (patch) | |
tree | ff92459e654fde6fe559dfd383d6a76e05a347cf /modules/private/monitoring/plugins/check_mem.sh | |
parent | e886ea19877fa0d4de32d35939f69e9c18681d59 (diff) | |
download | Nix-3bc32d9ebd9b0900eeef756122ad28f8857f8bfe.tar.gz Nix-3bc32d9ebd9b0900eeef756122ad28f8857f8bfe.tar.zst Nix-3bc32d9ebd9b0900eeef756122ad28f8857f8bfe.zip |
Add monitoring modules via naemon
Diffstat (limited to 'modules/private/monitoring/plugins/check_mem.sh')
-rwxr-xr-x | modules/private/monitoring/plugins/check_mem.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_mem.sh b/modules/private/monitoring/plugins/check_mem.sh new file mode 100755 index 0000000..cc97ae2 --- /dev/null +++ b/modules/private/monitoring/plugins/check_mem.sh | |||
@@ -0,0 +1,29 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then | ||
4 | FreeM=`free -m` | ||
5 | memTotal_m=`echo "$FreeM" |grep Mem |awk '{print $2}'` | ||
6 | memUsed_m=`echo "$FreeM" |grep Mem |awk '{print $3}'` | ||
7 | memFree_m=`echo "$FreeM" |grep Mem |awk '{print $4}'` | ||
8 | memBuffer_m=`echo "$FreeM" |grep Mem |awk '{print $6}'` | ||
9 | memCache_m=`echo "$FreeM" |grep Mem |awk '{print $7}'` | ||
10 | memUsedPrc=`echo $((($memUsed_m*100)/$memTotal_m))||cut -d. -f1` | ||
11 | if [ "$memUsedPrc" -ge "$4" ]; then | ||
12 | echo "Memory: CRITICAL Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|TOTAL=$memTotal_m;;;; USED=$memUsed_m;;;; CACHE=$memCache_m;;;; BUFFER=$memBuffer_m;;;;" | ||
13 | exit 2 | ||
14 | elif [ "$memUsedPrc" -ge "$2" ]; then | ||
15 | echo "Memory: WARNING Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used!|TOTAL=$memTotal_m;;;; USED=$memUsed_m;;;; CACHE=$memCache_m;;;; BUFFER=$memBuffer_m;;;;" | ||
16 | exit 1 | ||
17 | else | ||
18 | echo "Memory: OK Total: $memTotal_m MB - Used: $memUsed_m MB - $memUsedPrc% used|TOTAL=$memTotal_m;;;; USED=$memUsed_m;;;; CACHE=$memCache_m;;;; BUFFER=$memBuffer_m;;;;" | ||
19 | exit 0 | ||
20 | fi | ||
21 | else # If inputs are not as expected, print help. | ||
22 | sName="`echo $0|awk -F '/' '{print $NF}'`" | ||
23 | echo -e "\n\n\t\t### $sName Version 2.0###\n" | ||
24 | echo -e "# Usage:\t$sName -w <warnlevel> -c <critlevel>" | ||
25 | echo -e "\t\t= warnlevel and critlevel is percentage value without %\n" | ||
26 | echo "# EXAMPLE:\t/usr/lib64/nagios/plugins/$sName -w 80 -c 90" | ||
27 | echo -e "\nCopyright (C) 2012 Lukasz Gogolin (lukasz.gogolin@gmail.com), improved by Nestor 2015\n\n" | ||
28 | exit | ||
29 | fi | ||