Skip to content
Snippets Groups Projects
Commit e1aa0a9c authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update php-fpm check using full status now

parent 16bbe108
No related branches found
No related tags found
No related merge requests found
...@@ -7,18 +7,32 @@ ...@@ -7,18 +7,32 @@
# script checks output of fpm "/status" and counts scoreboard chars # script checks output of fpm "/status" and counts scoreboard chars
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 2021-09-22 v0.1 <axel.hahn@iml.unibe.ch> initial version # 2021-09-22 v0.1 <axel.hahn@iml.unibe.ch> initial version
# 2021-10-01 v0.2 <axel.hahn@iml.unibe.ch> fetch full status as json
# ====================================================================== # ======================================================================
. `dirname $0`/inc_pluginfunctions . `dirname $0`/inc_pluginfunctions
tmpfile=/tmp/check_fpm_processes_1 tmpfile=/tmp/check_fpm_processes_1
defaulturl=localhost/status defaulturl=localhost/status
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# functions # functions
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# get service data from json output
function _getServicedata(){
cat $tmpfile | jq | grep '^\ \ "' | grep -v "\[" | cut -f 1 -d ","
}
function _getWorkerStates(){
cat $tmpfile | jq | grep '"state": ' | cut -f 2 -d ":" | cut -f 1 -d "," | sort -u
}
function _getWorkerOfState(){
cat $tmpfile | jq -c ".processes[] | select(.state == \"$1\" )"
}
# get a value from fpm status # get a value from fpm status
# #
# example output: # example output:
...@@ -39,9 +53,11 @@ defaulturl=localhost/status ...@@ -39,9 +53,11 @@ defaulturl=localhost/status
# #
# param string variable (part before ":") # param string variable (part before ":")
function _getvalue(){ function _getvalue(){
grep "^$1:" $tmpfile | cut -d ":" -f 2 | awk '{ print $1 }' # grep "^$1:" $tmpfile | cut -d ":" -f 2 | awk '{ print $1 }'
_getServicedata | grep "^\ \ \"$1\":" | cut -d ":" -f 2 | awk '{ print $1 }'
} }
function showHelp(){ function showHelp(){
cat <<EOF cat <<EOF
______________________________________________________________________ ______________________________________________________________________
...@@ -100,7 +116,7 @@ esac ...@@ -100,7 +116,7 @@ esac
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# pre checks # pre checks
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
ph.require wget ph.require jq wget
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -113,18 +129,13 @@ typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` ...@@ -113,18 +129,13 @@ typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"`
url=$( ph.getValueWithParam $defaulturl u "$@" ) url=$( ph.getValueWithParam $defaulturl u "$@" )
# --- get /server-status page # --- get /server-status page
wget --no-check-certificate -O $tmpfile $url 2>/dev/null wget --no-check-certificate -O $tmpfile "$url?full&json" 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f $tmpfile rm -f $tmpfile
ph.abort "UNKNOWN: request to url $url failed. `wget --no-check-certificate -O - -S $url`" ph.abort "UNKNOWN: request to url $url failed. `wget --no-check-certificate -O - -S $url`"
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# get values from status output
# ----------------------------------------------------------------------
# --- handled requests per sec
typeset -i iConn=$( _getvalue "accepted conn")
typeset -i iSpeed=$( ph.perfdeltaspeed "fpm-accepted" $iConn ) typeset -i iSpeed=$( ph.perfdeltaspeed "fpm-accepted" $iConn )
# --- count slots # --- count slots
...@@ -140,6 +151,11 @@ typeset -i iSlow=$( ph.perfdeltaspeed "fpm-slow" $iSlowTotal ) ...@@ -140,6 +151,11 @@ typeset -i iSlow=$( ph.perfdeltaspeed "fpm-slow" $iSlowTotal )
typeset -i iMaxChilds=$( _getvalue "max children reached") typeset -i iMaxChilds=$( _getvalue "max children reached")
typeset -i iWorkerRunning=$( _getWorkerOfState "Running" | wc -l )
typeset -i iWorkerReading=$( _getWorkerOfState "Reading headers" | wc -l )
typeset -i iWorkerIdle=$( _getWorkerOfState "Idle" | wc -l )
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# set status # set status
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -153,20 +169,30 @@ if [ $iMaxChilds -gt 0 ]; then ...@@ -153,20 +169,30 @@ if [ $iMaxChilds -gt 0 ]; then
# ph.setStatus critical # ph.setStatus critical
ph.setStatus warning ph.setStatus warning
fi fi
if [ $iIdle -eq 0 ]; then if [ $iWorkerIdle -eq 0 ]; then
ph.setStatus critical ph.setStatus warning
fi
if [ $iWorkerReading -eq 0 ]; then
ph.setStatus warning
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# output # output
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
ph.status "PHP-FPM: active: $iActive (max: $iMaxActive) .. idle workers: $iIdle .. queue: $iQueue (max: $iMaxQueue) .. speed: $iSpeed req per sec ... slow: $iSlow req per sec (total: $iSlowTotal)" ph.status "PHP-FPM: active: $iActive (max: $iMaxActive) .. idle workers: $iIdle .. queue: $iQueue (max: $iMaxQueue) .. speed: $iSpeed req per sec ... slow: $iSlow req per sec (total: $iSlowTotal)"
echo Worker states: running: $iWorkerRunning .. Reading headers: $iWorkerReading .. Idle: $iWorkerIdle
echo echo
hint="!! IMPORTANT !! Any non-OK status is still experimmental." hint="!! IMPORTANT !! Any non-OK status is still experimmental."
if [ $iIdle -eq 0 ]; then if [ $iWorkerIdle -eq 0 ]; then
echo $hint
echo "WARNING: No idle workers available."
echo " Maybe there is a current peak only."
echo " Or count of allowed workers (pm.max_children) or spare servers (pm.XXX_spare_servers) is too low."
echo
fi
if [ $iWorkerReading -eq 0 ]; then
echo $hint echo $hint
echo "WARNING: $iIdle idle workers available." echo "WARNING: No reading workers available."
echo " Maybe there is a current peak only." echo " Maybe there is a current peak only."
echo " Or count of allowed workers (pm.max_children) or spare servers (pm.XXX_spare_servers) is too low." echo " Or count of allowed workers (pm.max_children) or spare servers (pm.XXX_spare_servers) is too low."
echo echo
...@@ -187,20 +213,31 @@ if [ $iSlow -gt 0 ]; then ...@@ -187,20 +213,31 @@ if [ $iSlow -gt 0 ]; then
echo echo
fi fi
cat $tmpfile echo "--- Status of service"
_getServicedata
echo
echo "--- workers in state Running"
_getWorkerOfState "Running"
echo echo
# --- add performnce data # --- add performnce data
ph.perfadd "php-fpm-active" "${iActive}" "" "" 0 0 ph.perfadd "php-fpm-active" "${iActive}" "" "" 0 0
ph.perfadd "php-fpm-maxactive" "${iMaxActive}" "" "" 0 0 ph.perfadd "php-fpm-maxactive" "${iMaxActive}" "" "" 0 0
ph.perfadd "php-fpm-idle" "${iIdle}" "" "" 0 0 # ph.perfadd "php-fpm-idle" "${iIdle}" "" "" 0 0
ph.perfadd "php-fpm-queue" "${iQueue}" "" "" 0 0 ph.perfadd "php-fpm-queue" "${iQueue}" "" "" 0 0
ph.perfadd "php-fpm-maxqueue" "${iMaxQueue}" "" "" 0 0 ph.perfadd "php-fpm-maxqueue" "${iMaxQueue}" "" "" 0 0
ph.perfadd "php-fpm-slow" "${iSlow}" "" "" 0 0 ph.perfadd "php-fpm-slow" "${iSlow}" "" "" 0 0
ph.perfadd "php-fpm-speed" "${iSpeed}" "" "" 0 0 ph.perfadd "php-fpm-speed" "${iSpeed}" "" "" 0 0
rm -f $tmpfile # use process infos to count by worker state:
ph.perfadd "php-fpm-idle" "${iWorkerIdle}" "" "" 0 0
ph.perfadd "php-fpm-running" "${iWorkerRunning}" "" "" 0 0
ph.perfadd "php-fpm-reading" "${iWorkerReading}" "" "" 0 0
rm -f $tmpfile
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment