1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Plugin apache_memory: properly quote patterns and simplify calculation

Previously the calculation had some issues:
* patterns with whitespace caused errors
* the number of processes could change between the steps for
  counting and averaging
* handle "no match" properly (returning "U" - unknown - instead of an
  error)
* avoid calculation based on unsafe "eval"
This commit is contained in:
Lars Kruse 2020-04-21 19:41:42 +02:00
parent b087127c04
commit dd41152cdd

View file

@ -56,12 +56,11 @@ if [ "$1" = "config" ]; then
exit 0
fi
VAL1=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | wc -l`
VAL2=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | awk '{s+=$6} END {print s}'`
VAL3=`expr $VAL2 / $VAL1`
echo "servers.value $VAL3"
matched_processes=$(ps auxf | grep -- "$PROCS" | grep "^$USR" | grep -v grep)
if [ -n "$matched_processes" ]; then
average_memory=$(printf '%s' "$matched_processes" | awk '{count+=1; sum+=$6} END {print sum/count}')
else
average_memory="U"
fi
echo "servers.value $average_memory"