-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_huge_pages_free.sh
executable file
·49 lines (42 loc) · 1.8 KB
/
check_huge_pages_free.sh
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
#!/usr/bin/env bash
# check if the configured percentage of huge pages is free
# Author: gricertg
# License: The MIT License (MIT)
PATH="/usr/bin:/usr/sbin:/bin:/sbin"
LIBEXEC="/usr/lib/nagios/plugins"
. $LIBEXEC/utils.sh
print_help() {
echo 'check if the configured percentage of huge pages is free'
echo 'PARAMETER DESCRIPTION'
echo '-w WARNING percentage value for free memory'
echo '-c CRITICAL percentage value for free memory'
}
while getopts 'w:c:h--help' OPT; do
case $OPT in
w) WARNING=$OPTARG;;
c) CRITICAL=$OPTARG;;
h) print_help; exit $STATE_OK;;
--help) print_help; exit $STATE_OK;;
*) print_help; exit $STATE_WARNING;;
esac
done
[ $# -gt 0 ] || { print_help; exit $STATE_WARNING; }
[ "${WARNING}" ] || { echo "You must define a Warning value"; exit $STATE_WARNING; }
[ "${CRITICAL}" ] || { echo "You must define a Critical value"; exit $STATE_WARNING; }
[ "${WARNING}" -lt 99 ] || { echo "Warning can't be greater than 99%"; exit $STATE_WARNING; }
[ "${CRITICAL}" -lt 99 ] || { echo "Critical can't be greater than 99%"; exit $STATE_WARNING; }
[ "${WARNING}" -gt "${CRITICAL}" ] || { echo "Warning can't be smaller than Critical"; exit $STATE_WARNING; }
TOTAL=$(grep HugePages_Total /proc/meminfo | awk '{print $2}')
FREE=$(grep HugePages_Free /proc/meminfo | awk '{print $2}')
PERCENT=$(echo "scale=2; ${FREE}/${TOTAL}*100" | bc)
PERCENT=${PERCENT%.*}
if [ "${PERCENT}" -lt "${CRITICAL}" ]; then
echo "CRITICAL - ${PERCENT}% Huge_Pages free | free=${PERCENT}%;${WARNING};${CRITICAL}"
exit $STATE_CRITICAL
elif [ "${PERCENT}" -lt "${WARNING}" ]; then
echo "WARNING - ${PERCENT}% Huge_Pages free | free=${PERCENT}%;${WARNING};${CRITICAL}"
exit $STATE_WARNING
else
echo "OK - ${PERCENT}% Huge_Pages free | free=${PERCENT}%;${WARNING};${CRITICAL}"
exit $STATE_OK
fi