diff --git a/check_php-fpm-status b/check_php-fpm-status new file mode 100755 index 0000000000000000000000000000000000000000..1c00394f86331c6da33a3e9c00fecaf37d84a6c9 --- /dev/null +++ b/check_php-fpm-status @@ -0,0 +1,140 @@ +#!/bin/bash +# ====================================================================== +# +# NAGIOS CLIENT CHECK :: php-fpm requests +# +# ---------------------------------------------------------------------- +# script checks output of fpm "/status" and counts scoreboard chars +# ---------------------------------------------------------------------- +# 2021-09-22 v0.1 <axel.hahn@iml.unibe.ch> initial version +# ====================================================================== + +. `dirname $0`/inc_pluginfunctions + +tmpfile=/tmp/check_fpm_processes_1 + +defaulturl=localhost/status + +# ---------------------------------------------------------------------- +# functions +# ---------------------------------------------------------------------- + +# get a value from fpm status +# +# example output: +# pool: www +# process manager: dynamic +# start time: 21/Sep/2021:16:01:12 +0200 +# start since: 65914 +# accepted conn: 34 +# listen queue: 0 +# max listen queue: 0 +# listen queue len: 0 +# idle processes: 6 +# active processes: 3 +# total processes: 9 +# max active processes: 6 +# max children reached: 0 +# slow requests: 0 +# +# param string variable (part before ":") +function _getvalue(){ + grep "^$1:" $tmpfile | cut -d ":" -f 2 | awk '{ print $1 }' +} + +# ---------------------------------------------------------------------- +# pre checks +# ---------------------------------------------------------------------- +ph.require wget + +# ---------------------------------------------------------------------- +# check params +# ---------------------------------------------------------------------- + +# --- check param -h +if [ "$1" = "-h" ]; then + echo " + Check PHP FPM status + + usage: $0 [-u URL] + + -u url to fpm status page (optional; default: $defaulturl) + -h this help + + " + exit 0 +fi + +# set default / override from command line params +typeset -i iWarnLimit=` ph.getValueWithParam 75 w "$@"` +typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` +url=$( ph.getValueWithParam $defaulturl u "$@" ) + +# --- get /server-status page +wget --no-check-certificate -O $tmpfile $url 2>/dev/null +if [ $? -ne 0 ]; then + rm -f $tmpfile + ph.abort "UNKNOWN: request to url $url failed. `wget --no-check-certificate -O - -S $url`" +fi + +# ---------------------------------------------------------------------- +# get values from status output +# ---------------------------------------------------------------------- + +# --- handled requests per sec +typeset -i iConn=$( _getvalue "accepted conn") +typeset -i iSpeed=$( ph.perfdeltaspeed "fpm-accepted" $iConn ) + +# --- count slots +typeset -i iActive=$( _getvalue "active processes" ) +typeset -i iMaxActive=$( _getvalue "max active processes" ) +typeset -i iIdle=$( _getvalue "idle processes") + +# --- experimental: generate warning / error +typeset -i iQueue=$( _getvalue "listen queue len") +typeset -i iMaxQueue=$( _getvalue "max listen queue") +typeset -i iSlow=$( _getvalue "slow requests") +typeset -i iMaxChilds=$( _getvalue "max children reached") + + +# damn, count of slots is in the config only - not in status output +# iUsage=$iActive*100/$iSlots +# ph.setStatusByLimit $iUsage $iWarnLimit $iCriticalLimit +if [ $iQueue -gt 0 -o $iSlow -gt 0 ]; then + ph.setStatus warning +fi +if [ $iMaxChilds -gt 0 ]; then + ph.setStatus critical +fi + + +# --- output +ph.status "PHP-FPM: active: $iActive (max: $iMaxActive) .. wait: $iIdle .. queue: $iQueue (max: $iMaxQueue) .. speed: $iSpeed req per sec" + +if [ $iQueue -gt 0 ]; then + echo "WARNING: $iQueue queued requests were found" +fi +if [ $iSlow -gt 0 ]; then + echo "WARNING: $iSlow slow requests were found" +fi +if [ $iMaxChilds -gt 0 ]; then + echo "CRITICAL: max. children was reached $iMaxChilds" +fi +echo +cat $tmpfile +echo + +# --- add performnce data +ph.perfadd "php-fpm-active" "${iActive}" "" "" 0 0 +ph.perfadd "php-fpm-maxactive" "${iMaxActive}" "" "" 0 0 +ph.perfadd "php-fpm-idle" "${iIdle}" "" "" 0 0 +ph.perfadd "php-fpm-queue" "${iQueue}" "" "" 0 0 +ph.perfadd "php-fpm-maxqueue" "${iMaxQueue}" "" "" 0 0 +ph.perfadd "php-fpm-slow" "${iSlow}" "" "" 0 0 +ph.perfadd "php-fpm-speed" "${iSpeed}" "" "" 0 0 + +rm -f $tmpfile + +ph.exit + +# ----------------------------------------------------------------------