mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51: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:
parent
b087127c04
commit
dd41152cdd
1 changed files with 7 additions and 8 deletions
|
@ -56,12 +56,11 @@ if [ "$1" = "config" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VAL1=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | wc -l`
|
matched_processes=$(ps auxf | grep -- "$PROCS" | grep "^$USR" | grep -v grep)
|
||||||
|
if [ -n "$matched_processes" ]; then
|
||||||
VAL2=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | awk '{s+=$6} END {print s}'`
|
average_memory=$(printf '%s' "$matched_processes" | awk '{count+=1; sum+=$6} END {print sum/count}')
|
||||||
|
else
|
||||||
VAL3=`expr $VAL2 / $VAL1`
|
average_memory="U"
|
||||||
|
fi
|
||||||
echo "servers.value $VAL3"
|
|
||||||
|
|
||||||
|
|
||||||
|
echo "servers.value $average_memory"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue