From 536bd24438799a15686415b054f57676b053702d Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 30 Sep 2021 23:32:45 +0200 Subject: move --- plugins/check_pressure | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 plugins/check_pressure (limited to 'plugins/check_pressure') 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[@]}" -- cgit v1.2.3