From 361a5316c75625639f0014fdcfba14829998c74a Mon Sep 17 00:00:00 2001 From: Jens Jahnke Date: Fri, 24 Aug 2012 09:44:52 +0200 Subject: [PATCH 1/4] Don't use hard coded paths to the used command line tools. The tools grep, sed and wc may have a different path. Therefore they are now evaluated via "which". If a command is not found the script exits with an error message and the exit code 1. --- plugins/php/php-cgi | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/php/php-cgi b/plugins/php/php-cgi index a761f9eb..0aa81748 100755 --- a/plugins/php/php-cgi +++ b/plugins/php/php-cgi @@ -32,5 +32,21 @@ echo 'php_processes.info The current number of php-cgi processes.' exit 0 fi +CMD_GREP=`which grep` +if [ ! -e ${CMD_GREP} ]; then + echo "Command grep (${CMD_GREP}) not found!" + exit 1 +fi +CMD_SED=`which sed` +if [ ! -e ${CMD_SED} ]; then + echo "Command sed (${CMD_SED}) not found!" + exit 1 +fi +CMD_WC=`which wc` +if [ ! -e ${CMD_WC} ]; then + echo "Command wc (${CMD_WC}) not found!" + exit 1 +fi + echo -n "php_processes.value " -/bin/ps ax | /usr/bin/grep -i php-cgi | /usr/bin/grep -v grep | /usr/bin/wc -l | /usr/bin/sed 's/\t +//' | /usr/bin/sed 's/ *//' +/bin/ps ax | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_WC} -l | ${CMD_SED} 's/\t +//' | ${CMD_SED} 's/ *//' From 123d91cf70892aa657a7615294915d01b7ceb9bb Mon Sep 17 00:00:00 2001 From: Jens Jahnke Date: Fri, 24 Aug 2012 10:29:55 +0200 Subject: [PATCH 2/4] Added output of memory usage to graph. The memory consumption of all processes (not threads) is calculated in GB and added to the graph. --- plugins/php/php-cgi | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/plugins/php/php-cgi b/plugins/php/php-cgi index 0aa81748..d41dd1af 100755 --- a/plugins/php/php-cgi +++ b/plugins/php/php-cgi @@ -21,14 +21,14 @@ exit 0 fi if [ "$1" = "config" ]; then -echo 'graph_title Number of php-cgi processes' -echo 'graph_args --base 1000 -l 0 ' -echo 'graph_vlabel number of php-cgi processes' -echo 'graph_category apache' -echo 'graph_info This graph shows the number of php-cgi processes in the system.' -echo 'php_processes.label php-cgi' -echo 'php_processes.draw LINE2' -echo 'php_processes.info The current number of php-cgi processes.' + echo "graph_title PHP CGI [GB]"; + echo "graph_vlabel PHP CGI Memory usage"; + echo "graph_category apache"; + echo "graph_args -l 0"; + echo "php_cgi_ram.label PHP CGI Used RAM"; + echo "php_cgi_ram.draw LINE2"; + echo "php_cgi_processes.info Number of PHP CGI processes"; + echo "php_cgi_processes.label processes"; exit 0 fi @@ -47,6 +47,23 @@ if [ ! -e ${CMD_WC} ]; then echo "Command wc (${CMD_WC}) not found!" exit 1 fi +CMD_AWK=`which awk` +if [ ! -e ${CMD_AWK} ]; then + echo "Command awk (${CMD_AWK}) not found!" + exit 1 +fi +CMD_BC=`which bc` +if [ ! -e ${CMD_BC} ]; then + echo "Command bc (${CMD_BC}) not found!" + exit 1 +fi -echo -n "php_processes.value " -/bin/ps ax | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_WC} -l | ${CMD_SED} 's/\t +//' | ${CMD_SED} 's/ *//' +echo -n "php_cgi_processes.value " +ps ax | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_WC} -l | ${CMD_SED} 's/\t +//' | ${CMD_SED} 's/ *//' + +MEMORY=0 +for mem in `ps avx | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_GREP} "Ss" | ${CMD_AWK} '{ print $7 }'`; do + MEMORY=$(($MEMORY + $mem)) +done +echo -n "php_cgi_ram.value " +echo "scale=4;${MEMORY}/1024/1024" | bc From f25c788c3de15f6b45ea2296d3ca051db04b6e67 Mon Sep 17 00:00:00 2001 From: Jens Jahnke Date: Fri, 24 Aug 2012 17:24:40 +0200 Subject: [PATCH 3/4] Remove "[GB]" from graph title. --- plugins/php/php-cgi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/php/php-cgi b/plugins/php/php-cgi index d41dd1af..6d7f205a 100755 --- a/plugins/php/php-cgi +++ b/plugins/php/php-cgi @@ -21,8 +21,8 @@ exit 0 fi if [ "$1" = "config" ]; then - echo "graph_title PHP CGI [GB]"; - echo "graph_vlabel PHP CGI Memory usage"; + echo "graph_title PHP CGI Memory"; + echo "graph_vlabel PHP CGI Memory usage in GB"; echo "graph_category apache"; echo "graph_args -l 0"; echo "php_cgi_ram.label PHP CGI Used RAM"; From d0d36f4926ee0628029c8a6664cac19b0f4413a0 Mon Sep 17 00:00:00 2001 From: Jens Jahnke Date: Fri, 24 Aug 2012 17:33:41 +0200 Subject: [PATCH 4/4] Use ${CMD_...} only to check if command exists and use the real command e.g. grep, sed, etc. in the command line. --- plugins/php/php-cgi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/php/php-cgi b/plugins/php/php-cgi index 6d7f205a..69545d15 100755 --- a/plugins/php/php-cgi +++ b/plugins/php/php-cgi @@ -34,35 +34,35 @@ fi CMD_GREP=`which grep` if [ ! -e ${CMD_GREP} ]; then - echo "Command grep (${CMD_GREP}) not found!" + echo "Command grep not found!" exit 1 fi CMD_SED=`which sed` if [ ! -e ${CMD_SED} ]; then - echo "Command sed (${CMD_SED}) not found!" + echo "Command sed not found!" exit 1 fi CMD_WC=`which wc` if [ ! -e ${CMD_WC} ]; then - echo "Command wc (${CMD_WC}) not found!" + echo "Command wc not found!" exit 1 fi CMD_AWK=`which awk` if [ ! -e ${CMD_AWK} ]; then - echo "Command awk (${CMD_AWK}) not found!" + echo "Command awk not found!" exit 1 fi CMD_BC=`which bc` if [ ! -e ${CMD_BC} ]; then - echo "Command bc (${CMD_BC}) not found!" + echo "Command bc not found!" exit 1 fi echo -n "php_cgi_processes.value " -ps ax | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_WC} -l | ${CMD_SED} 's/\t +//' | ${CMD_SED} 's/ *//' +ps ax | grep -i php-cgi | grep -v grep | wc -l | sed 's/\t +//' | sed 's/ *//' MEMORY=0 -for mem in `ps avx | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_GREP} "Ss" | ${CMD_AWK} '{ print $7 }'`; do +for mem in `ps avx | grep -i php-cgi | grep -v grep | grep "Ss" | awk '{ print $7 }'`; do MEMORY=$(($MEMORY + $mem)) done echo -n "php_cgi_ram.value "