Projet

Général

Profil

Révision dd41152c

IDdd41152cdd6e5a12dd43dc4df03f4e5e46924b65
Parent b087127c
Enfant 1ac5fbdf

Ajouté par Lars Kruse il y a plus de 5 ans

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"

Voir les différences:

plugins/apache/apache_memmory
56 56
    exit 0
57 57
fi
58 58

  
59
VAL1=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | wc -l`
60

  
61
VAL2=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | awk '{s+=$6} END {print s}'`
62

  
63
VAL3=`expr $VAL2 / $VAL1`
64

  
65
echo "servers.value $VAL3"
66

  
59
matched_processes=$(ps auxf | grep -- "$PROCS" | grep "^$USR" | grep -v grep)
60
if [ -n "$matched_processes" ]; then
61
    average_memory=$(printf '%s' "$matched_processes" | awk '{count+=1; sum+=$6} END {print sum/count}')
62
else
63
    average_memory="U"
64
fi
67 65

  
66
echo "servers.value $average_memory"

Formats disponibles : Unified diff