diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-09-30 23:32:45 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-09-30 23:32:45 +0200 |
commit | 536bd24438799a15686415b054f57676b053702d (patch) | |
tree | ac5b93d2a342166c3d2d11a867934ec725b7273e /plugins/check_pressure | |
parent | cf666ed055e1e76c5acf0d323d87438bfb8342d6 (diff) | |
download | monitoring_custom-536bd24438799a15686415b054f57676b053702d.tar.gz |
move
Diffstat (limited to 'plugins/check_pressure')
-rwxr-xr-x | plugins/check_pressure | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/plugins/check_pressure b/plugins/check_pressure new file mode 100755 index 0000000..787827c --- /dev/null +++ b/plugins/check_pressure @@ -0,0 +1,72 @@ +#!/bin/bash + +#USAGE: check_pressure cpu|io|memory some|full [--10 w,c] [--60 w,c] [--300 w,c] + +RESULTS=(OK WARNING CRITICAL UNKNOWN) + +fail() { + local RET=$1 + shift + echo "$@" + exit $RET +} + +float_compare() { + [ $# -ne 2 ] && return 1 + + (( $(echo "$1 > $2" | bc -l ) )) && return 0 + return 1 +} + +# pressure is a relatively new feature. Ignore if not present. +[ ! -e "/proc/pressure" ] && fail 0 pressure API not present + +RESOURCE="$1" +[ ! -e "/proc/pressure/$RESOURCE" ] && fail 3 invalid resource \""$RESOURCE"\" +shift + +( echo "$1" | grep "^some$\|^full$" > /dev/null ) \ + || fail 3 \""$1"\" invalid. must be \"some\" or \"full\" +MODE="$1" + +while shift; do + case "$1" in + "--10") + VAL[0]="$2" + shift;; + "--60") + VAL[1]="$2" + shift;; + "--300") + VAL[2]="$2" + shift;; + "");; + *) + fail 3 "Unkown argument: \"$1\"" + ;; + esac +done + +[ "${#VAL[@]}" -eq 0 ] && fail 3 "At least one set of threshholds must be set" + +read MD avg10 avg60 avg300 catch < <(grep "$MODE" "/proc/pressure/$RESOURCE") \ + || fail 3 "Parsing of file failed. Does $RESOURCE support $MODE?" + +AVG=( "$avg10" "$avg60" "$avg300" ) +WARNING_OFFENDERS=() +CRITICAL_OFFENDERS=() + +for i in 0 1 2; do + [ -z "${VAL[$i]}" ] && continue + IFS=',' read WARN CRIT <<< "${VAL[$i]}" + IFS='=' read KEY VALUE <<< "${AVG[$i]}" + + float_compare "$VALUE" "$CRIT" && CRITICAL_OFFENDERS+=("$KEY($VALUE)=C") && continue + float_compare "$VALUE" "$WARN" && WARNING_OFFENDERS+=("$KEY($VALUE)=W") +done + +WORST=0 +[ ${#WARNING_OFFENDERS[@]} -gt 0 ] && WORST=1 +[ ${#CRITICAL_OFFENDERS[@]} -gt 0 ] && WORST=2 + +echo "PRESSURE ${RESULTS[$WORST]}: ${CRITICAL_OFFENDERS[@]} ${WARNING_OFFENDERS[@]} | ${AVG[@]}" |