forked from whereisaaron/linux-check-mem-nagios-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_mem
49 lines (41 loc) · 1.91 KB
/
check_mem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# check_mem modified for use on debian stretch
if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then
memTotal_m=$(awk '$1~/^MemTotal/{print $2}' /proc/meminfo )
memFree_m=$(awk '$1~/^MemFree/{print $2}' /proc/meminfo )
memBuffer_m=$(awk '$1~/^Buffers/{print $2}' /proc/meminfo )
memCache_m=$(awk '$1~/^Cached/{print $2}' /proc/meminfo )
memUsed_m=$(($memTotal_m-$memFree_m-$memBuffer_m-$memCache_m))
memUsedPrc=$((($memUsed_m*100)/$memTotal_m))
warn=$(((($memTotal_m*100)-($memTotal_m*(100-$2)))/100))
crit=$(((($memTotal_m*100)-($memTotal_m*(100-$4)))/100))
memTotal_b=$(($memTotal_m*1024))
memFree_b=$(($memFree_m*1024))
memUsed_b=$(($memUsed_m*1024))
memBuffer_b=$(($memBuffer_m*1024))
memCache_b=$(($memCache_m*1024))
minmax="0;$memTotal_b";
data="TOTAL=$memTotal_b;;;$minmax USED=$memUsed_b;$warn;$crit;$minmax CACHE=$memCache_b;;;$minmax BUFFER=$memBuffer_b;;;$minmax"
if [ "$memUsedPrc" -ge "$4" ]; then
echo "MEMORY CRITICAL - Total: $memTotal_m KB - Used: $memUsed_m KB - $memUsedPrc% used!|$data"
$(exit 2)
elif [ "$memUsedPrc" -ge "$2" ]; then
echo "MEMORY WARNING - Total: $memTotal_m KB - Used: $memUsed_m KB - $memUsedPrc% used!|$data"
$(exit 1)
else
echo "MEMORY OK - Total: $memTotal_m KB - Used: $memUsed_m KB - $memUsedPrc% used|$data"
$(exit 0)
fi
else
echo "check_mem v1.3"
echo ""
echo "Usage:"
echo "check_mem.sh -w <warnlevel> -c <critlevel>"
echo ""
echo "warnlevel and critlevel is percentage value without %"
echo ""
echo "v1.1 Copyright (C) 2012 Lukasz Gogolin (lukasz.gogolin@gmail.com)"
echo "v1.2 Modified 2014 by Aaron Roydhouse (aaron@roydhouse.com)"
echo "v1.3 Modified 2015 by Aaron Roydhouse (aaron@roydhouse.com)"
exit
fi