aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_mem
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-30 23:32:45 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-30 23:32:45 +0200
commit536bd24438799a15686415b054f57676b053702d (patch)
treeac5b93d2a342166c3d2d11a867934ec725b7273e /plugins/check_mem
parentcf666ed055e1e76c5acf0d323d87438bfb8342d6 (diff)
downloadmonitoring_custom-536bd24438799a15686415b054f57676b053702d.tar.gz
move
Diffstat (limited to 'plugins/check_mem')
-rwxr-xr-xplugins/check_mem51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/check_mem b/plugins/check_mem
new file mode 100755
index 0000000..09b4ba8
--- /dev/null
+++ b/plugins/check_mem
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+if [ $# -ne 2 ]; then
+ cat << EOF
+Check memory usage. Values: used%
+USAGE: $0 <WARN> <CRIT>
+Note: USED=TOTAL-AVAILABLE
+EOF
+ exit 3
+fi
+
+WARN=$1
+CRIT=$2
+
+if ! which free > /dev/null; then
+ echo UNKNOWN: free command not found.
+ exit 3
+fi
+
+TOTAL=0
+USED=0
+AVAIL=0
+
+while read line; do
+ ARR=( $line )
+ [ ${ARR[0]} != "Mem:" ] && continue
+
+ TOTAL=${ARR[1]}
+ AVAIL=${ARR[6]}
+ USED=$(($TOTAL-$AVAIL))
+
+ break
+done <<< $(free | tail -n -2)
+
+PERCENT_USED=$(echo "scale=4; $USED / $TOTAL * 100 " | bc -l)
+PERCENT_USED=${PERCENT_USED%00}
+PERCENT_USED_INT=${PERCENT_USED%.*}
+
+if [ $PERCENT_USED_INT -ge $CRIT ]; then
+ RET=2
+ echo -n "Memory CRITICAL: "
+elif [ $PERCENT_USED_INT -ge $WARN ]; then
+ RET=1
+ echo -n "Memory WARNING: "
+else
+ RET=0
+ echo -n "Memory OK: "
+fi
+
+echo "$PERCENT_USED% Used | percent_used=$PERCENT_USED% total=$TOTAL available=$AVAIL"
+exit $RET