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 @@
# 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
# 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
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=1.4
tmpfile=/tmp/check_apache_processes_1
tmpfile2=/tmp/check_apache_processes_2
self_APPVERSION=1.5
# url=`hostname -f`/server-status
url=localhost/server-status
......@@ -124,9 +123,8 @@ ph.require wget
# ----------------------------------------------------------------------
# --- get /server-status page
wget $paramsWget -O $tmpfile $url 2>/dev/null
data=$( wget $paramsWget -O - $url 2>/dev/null )
if [ $? -ne 0 ]; then
rm -f $tmpfile
ph.abort "UNKNOWN: request to url $url failed. $(wget $paramsWget -O - -S $url 2>&1)"
fi
......@@ -136,32 +134,30 @@ typeset -i iCriticalLimit=$( ph.getValueWithParam 90 c "$@")
# --- extract scoreboard
iStart=$( grep -n '<pre>' $tmpfile | cut -f 1 -d ':')
iEnd=$( grep -n '</pre>' $tmpfile | cut -f 1 -d ':')
iStart=$( grep -n '<pre>' <<< "$data" | cut -f 1 -d ':')
iEnd=$( grep -n '</pre>' <<< "$data" | cut -f 1 -d ':')
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."
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
# total slots available
iSlots=$(cat $tmpfile2 | wc -m)
iSlots=$( echo -n "$dataPre" | wc -m )
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."
fi
# 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
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
iActive=$iSlots-$iIdle-$iUnused
......@@ -172,7 +168,7 @@ ph.setStatusByLimit $iUsage $iWarnLimit $iCriticalLimit
# --- output
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
# --- add performnce data
......@@ -181,16 +177,13 @@ ph.perfadd "apache-active" "${iActive}" "" "" 0 $iSlots
echo "Slots:"
for mychar in S R W K D C L G I _ .
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#")
echo " - ${mychar}: ${iCount}"
ph.perfadd "${label}" "${iCount}" "" "" 0 $iSlots
done
rm -f $tmpfile $tmpfile2
ph.exit
# ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment