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

check apache status: remove usage of tmp file

parent 4e8d9779
No related branches found
No related tags found
1 merge request!122Update docs
...@@ -10,14 +10,13 @@ ...@@ -10,14 +10,13 @@
# 2021-03-11 v1.1 <axel.hahn@iml.unibe.ch> more error checks for output data # 2021-03-11 v1.1 <axel.hahn@iml.unibe.ch> more error checks for output data
# 2021-11-18 v1.2 <axel.hahn@iml.unibe.ch> add timeout and max tries; use localhost instead of FQDN # 2021-11-18 v1.2 <axel.hahn@iml.unibe.ch> add timeout and max tries; use localhost instead of FQDN
# 2022-08-31 v1.3 <axel.hahn@iml.unibe.ch> add help; shellfix corrections # 2022-08-31 v1.3 <axel.hahn@iml.unibe.ch> add help; shellfix corrections
# 2022-08-31 v1.4 <axel.hahn@iml.unibe.ch> add help; shellfix corrections
# 2023-06-19 v1.5 <axel.hahn@unibe.ch> no more tmpfile
# ====================================================================== # ======================================================================
. $(dirname $0)/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=1.4 self_APPVERSION=1.5
tmpfile=/tmp/check_apache_processes_1
tmpfile2=/tmp/check_apache_processes_2
# url=`hostname -f`/server-status # url=`hostname -f`/server-status
url=localhost/server-status url=localhost/server-status
...@@ -124,9 +123,8 @@ ph.require wget ...@@ -124,9 +123,8 @@ ph.require wget
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# --- get /server-status page # --- get /server-status page
wget $paramsWget -O $tmpfile $url 2>/dev/null data=$( wget $paramsWget -O - $url 2>/dev/null )
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
rm -f $tmpfile
ph.abort "UNKNOWN: request to url $url failed. $(wget $paramsWget -O - -S $url 2>&1)" ph.abort "UNKNOWN: request to url $url failed. $(wget $paramsWget -O - -S $url 2>&1)"
fi fi
...@@ -136,32 +134,30 @@ typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@") ...@@ -136,32 +134,30 @@ typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@")
# --- extract scoreboard # --- extract scoreboard
iStart=$( grep -n '<pre>' $tmpfile | cut -f 1 -d ':') iStart=$( grep -n '<pre>' <<< "$data" | cut -f 1 -d ':')
iEnd=$( grep -n '</pre>' $tmpfile | cut -f 1 -d ':') iEnd=$( grep -n '</pre>' <<< "$data" | cut -f 1 -d ':')
if [ $iStart -eq 0 -o $iEnd -eq 0 ]; then if [ $iStart -eq 0 -o $iEnd -eq 0 ]; then
rm -f $tmpfile
ph.abort "UNKNOWN: url $url has no PRE tag for apache scroreboard. I guess it is not a server-status page." ph.abort "UNKNOWN: url $url has no PRE tag for apache scroreboard. I guess it is not a server-status page."
fi fi
sed -n "${iStart},${iEnd}p" $tmpfile | sed 's#<.*>##g' | tr -d "\n" >$tmpfile2 dataPre=$( sed -n "${iStart},${iEnd}p" <<< "$data" | sed 's#<.*>##g' | tr -d "\n" )
# --- count slots in the scoreboard # --- count slots in the scoreboard
# total slots available # total slots available
iSlots=$(cat $tmpfile2 | wc -m) iSlots=$( echo -n "$dataPre" | wc -m )
if [ $iSlots -eq 0 ]; then if [ $iSlots -eq 0 ]; then
rm -f $tmpfile $tmpfile2
ph.abort "UNKNOWN: url $url has no count of slots. I guess it is not a server-status page or option for Extended status is off." ph.abort "UNKNOWN: url $url has no count of slots. I guess it is not a server-status page or option for Extended status is off."
fi fi
# running apache processes waiting for a request # running apache processes waiting for a request
iIdle=iCount=$(sed -e "s/[^_]//g" $tmpfile2 | wc -m) iIdle=iCount=$(echo -n "$dataPre" | sed -e "s/[^_]//g" | wc -m)
# count of processes apache still can create # count of processes apache still can create
iUnused=iCount=$(sed -e "s/[^\.]//g" $tmpfile2 | wc -m) iUnused=iCount=$(echo -n "$dataPre" | sed -e "s/[^\.]//g" | wc -m)
# count of actively used slots # count of actively used slots
iActive=$iSlots-$iIdle-$iUnused iActive=$iSlots-$iIdle-$iUnused
...@@ -172,7 +168,7 @@ ph.setStatusByLimit $iUsage $iWarnLimit $iCriticalLimit ...@@ -172,7 +168,7 @@ ph.setStatusByLimit $iUsage $iWarnLimit $iCriticalLimit
# --- output # --- output
ph.status "Apache: $iSlots slots ... active: $iActive wait: $iIdle unused: $iUnused ($iUsage % usage)" ph.status "Apache: $iSlots slots ... active: $iActive wait: $iIdle unused: $iUnused ($iUsage % usage)"
grep "^<dt" $tmpfile | sed 's#<dt>##'| sed 's#</dt>##' grep "^<dt" <<< "$data" | sed 's#<dt>##'| sed 's#</dt>##'
echo echo
# --- add performnce data # --- add performnce data
...@@ -181,16 +177,13 @@ ph.perfadd "apache-active" "${iActive}" "" "" 0 $iSlots ...@@ -181,16 +177,13 @@ ph.perfadd "apache-active" "${iActive}" "" "" 0 $iSlots
echo "Slots:" echo "Slots:"
for mychar in S R W K D C L G I _ . for mychar in S R W K D C L G I _ .
do do
iCount=$(sed -e "s/[^${mychar}]//g" $tmpfile2 | wc -m) iCount=$(echo -n "$dataPre" | sed -e "s/[^${mychar}]//g" | wc -m)
label=$(echo apache-${mychar} | tr [:upper:] [:lower:] | sed "s#_#idle#" | sed "s#\.#unused#") label=$(echo apache-${mychar} | tr [:upper:] [:lower:] | sed "s#_#idle#" | sed "s#\.#unused#")
echo " - ${mychar}: ${iCount}" echo " - ${mychar}: ${iCount}"
ph.perfadd "${label}" "${iCount}" "" "" 0 $iSlots ph.perfadd "${label}" "${iCount}" "" "" 0 $iSlots
done done
rm -f $tmpfile $tmpfile2
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