2010-06-02 20:59:43 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# -*- sh -*-
|
|
|
|
#
|
|
|
|
# Plugin to monitor the number of PHP processes on the machine.
|
|
|
|
#
|
|
|
|
# Copyright Khalid Baheyeldin 2009 http://2bits.com
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
#
|
|
|
|
# config (required)
|
|
|
|
# autoconf (optional - used by munin-config)
|
|
|
|
#
|
|
|
|
# Magick markers (optional - used by munin-config and som installation
|
|
|
|
# scripts):
|
|
|
|
#%# family=manual
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
2012-08-24 17:24:40 +02:00
|
|
|
echo "graph_title PHP CGI Memory";
|
|
|
|
echo "graph_vlabel PHP CGI Memory usage in GB";
|
2012-08-24 10:29:55 +02:00
|
|
|
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";
|
2010-06-02 20:59:43 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-08-24 09:44:52 +02:00
|
|
|
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
|
2012-08-24 10:29:55 +02:00
|
|
|
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_cgi_processes.value "
|
|
|
|
ps ax | ${CMD_GREP} -i php-cgi | ${CMD_GREP} -v grep | ${CMD_WC} -l | ${CMD_SED} 's/\t +//' | ${CMD_SED} 's/ *//'
|
2012-08-24 09:44:52 +02:00
|
|
|
|
2012-08-24 10:29:55 +02:00
|
|
|
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
|