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

Merge branch 'update-docs' into 'master'

Update docs

See merge request !122
parents a845a970 36a30c40
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
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
______________________________________________________________________ ______________________________________________________________________
CHECK_APACHE_REQUESTS CHECK_APACHE_REQUESTS
v1.4 v1.5
(c) Institute for Medical Education - University of Bern (c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
# 2023-04-24 v1.8 <axel.hahn@unibe.ch> fix unit conversion # 2023-04-24 v1.8 <axel.hahn@unibe.ch> fix unit conversion
# 2023-05-05 v1.9 <axel.hahn@unibe.ch> user specific counter directory # 2023-05-05 v1.9 <axel.hahn@unibe.ch> user specific counter directory
# 2023-05-17 v1.10 <axel.hahn@unibe.ch> ph.getOS searches in os-release first # 2023-05-17 v1.10 <axel.hahn@unibe.ch> ph.getOS searches in os-release first
# 2023-06-22 v1.11 <axel.hahn@unibe.ch> fix ph.toUnit with float values; shell fixes
# ====================================================================== # ======================================================================
...@@ -45,13 +46,9 @@ typeset -i ph_cfg__EXIT_WARNING=1 ...@@ -45,13 +46,9 @@ typeset -i ph_cfg__EXIT_WARNING=1
typeset -i ph_cfg__EXIT_CRITICAL=2 typeset -i ph_cfg__EXIT_CRITICAL=2
typeset -i ph_cfg__EXIT_UNKNOWN=3 typeset -i ph_cfg__EXIT_UNKNOWN=3
declare ph_perfdatafile= typeset -i ph_cfg__EXIT_CODE
# declare -a ph_perfdata
typeset -i ph_perfcounter=0
# save command line params
ph_cmd__params="$@"
declare ph_perfdatafile=
# abort a check and exit with status "unknown" # abort a check and exit with status "unknown"
function ph.abort(){ function ph.abort(){
...@@ -86,24 +83,24 @@ function ph.exit(){ ...@@ -86,24 +83,24 @@ function ph.exit(){
function ph.getOS(){ function ph.getOS(){
local distro= local distro=
if [ -z $distro ]; then if [ -z "$distro" ]; then
# centos7, debian, manjaro, ubuntu # centos7, debian, manjaro, ubuntu
distro=$( grep "^ID=" /etc/os-release | cut -f 2 -d "=" ) distro=$( grep "^ID=" /etc/os-release | cut -f 2 -d "=" )
fi fi
if [ -z $distro ]; then if [ -z "$distro" ]; then
distro=$( grep "^ID=" /etc/*-release | cut -f 2 -d "=" ) distro=$( grep "^ID=" /etc/*-release | cut -f 2 -d "=" )
fi fi
if [ -z $distro ]; then if [ -z "$distro" ]; then
# debian6,7, ubuntu 10,12 .. maybe unneeded. # debian6,7, ubuntu 10,12 .. maybe unneeded.
distro=$( head -1 /etc/issue | grep "^[a-zA-Z]" | cut -f 1 -d " " ) distro=$( head -1 /etc/issue | grep "^[a-zA-Z]" | cut -f 1 -d " " )
fi fi
# sanitize: lowercase, remove " # sanitize: lowercase, remove "
distro=$( echo $distro | tr -d '"' | tr [:upper:] [:lower:] ) distro=$( echo "$distro" | tr -d '"' | tr [:upper:] [:lower:] )
if [ -z $distro ]; then if [ -z "$distro" ]; then
ph.abort "UNKNOWN: distro was not detected." ph.abort "UNKNOWN: distro was not detected."
fi fi
...@@ -190,19 +187,19 @@ function ph.hasParamoption(){ ...@@ -190,19 +187,19 @@ function ph.hasParamoption(){
# param integer|string 0..3 or ok|warning|critical|unknown # param integer|string 0..3 or ok|warning|critical|unknown
function ph.setStatus(){ function ph.setStatus(){
case $1 in case $1 in
$ph_cfg__EXIT_OK|"ok"): "$ph_cfg__EXIT_OK"|"ok"):
ph_cfg__EXIT_CODE=$ph_cfg__EXIT_OK ph_cfg__EXIT_CODE=$ph_cfg__EXIT_OK
ph_cfg__EXIT_STATUS="OK" ph_cfg__EXIT_STATUS="OK"
;; ;;
$ph_cfg__EXIT_WARNING|"warning"): "$ph_cfg__EXIT_WARNING"|"warning"):
ph_cfg__EXIT_CODE=$ph_cfg__EXIT_WARNING ph_cfg__EXIT_CODE=$ph_cfg__EXIT_WARNING
ph_cfg__EXIT_STATUS="WARNING" ph_cfg__EXIT_STATUS="WARNING"
;; ;;
$ph_cfg__EXIT_CRITICAL|"critical"): "$ph_cfg__EXIT_CRITICAL"|"critical"):
ph_cfg__EXIT_CODE=$ph_cfg__EXIT_CRITICAL ph_cfg__EXIT_CODE=$ph_cfg__EXIT_CRITICAL
ph_cfg__EXIT_STATUS="CRITICAL" ph_cfg__EXIT_STATUS="CRITICAL"
;; ;;
$ph_cfg__EXIT_UNKNOWN|"unknown"): "$ph_cfg__EXIT_UNKNOWN"|"unknown"):
ph_cfg__EXIT_CODE=$ph_cfg__EXIT_UNKNOWN ph_cfg__EXIT_CODE=$ph_cfg__EXIT_UNKNOWN
ph_cfg__EXIT_STATUS="UNKNOWN" ph_cfg__EXIT_STATUS="UNKNOWN"
;; ;;
...@@ -267,7 +264,7 @@ function ph.status(){ ...@@ -267,7 +264,7 @@ function ph.status(){
# param value with ending scale [none]=1 K=Kilo M=Mega G=Giga # param value with ending scale [none]=1 K=Kilo M=Mega G=Giga
function ph._getExp(){ function ph._getExp(){
local _unit local _unit
_unit=$( echo $1 | sed "s#[0-9]##g" ) _unit=${1//[0-9\.]/}
test -z "$_unit" && echo 1 test -z "$_unit" && echo 1
...@@ -300,11 +297,11 @@ function ph.toUnit(){ ...@@ -300,11 +297,11 @@ function ph.toUnit(){
local _value=$1 local _value=$1
local _unit=$2 local _unit=$2
local _multiply=`ph._getExp $_value` local _multiply; _multiply=$( ph._getExp "$_value" )
local _divisor=`ph._getExp $_unit` local _divisor; _divisor=$( ph._getExp "$_unit" )
# echo "DEBUG ... $_divisor .. $_multiply" # echo "DEBUG ... $_divisor .. $_multiply"
echo "$(echo $_value | tr -d "[:alpha:]" )*${_multiply}/$_divisor" | bc echo "$(echo "$_value" | tr -d "[:alpha:]" )*${_multiply}/$_divisor" | bc
} }
...@@ -346,7 +343,7 @@ function ph._getStorefile(){ ...@@ -346,7 +343,7 @@ function ph._getStorefile(){
function ph._savecounter() { function ph._savecounter() {
local varName=$1 local varName=$1
local value=$2 local value=$2
local sStoreFile=$(ph._getStorefile "${varName}") local sStoreFile; sStoreFile=$(ph._getStorefile "${varName}")
#echo "DEBUG: `date +%s`:${value} \> ${sStoreFile}" #echo "DEBUG: `date +%s`:${value} \> ${sStoreFile}"
# echo "`date +%s`:${value}" > "${sStoreFile}" # echo "`date +%s`:${value}" > "${sStoreFile}"
echo ${value} > "${sStoreFile}" echo ${value} > "${sStoreFile}"
...@@ -357,7 +354,7 @@ function ph._savecounter() { ...@@ -357,7 +354,7 @@ function ph._savecounter() {
# param string varName variable name of a value to store # param string varName variable name of a value to store
function ph._getageoflastvalue() { function ph._getageoflastvalue() {
local varName=$1 local varName=$1
local sStoreFile=$(ph._getStorefile "${varName}") local sStoreFile; sStoreFile=$(ph._getStorefile "${varName}")
ph.getFileAge "${sStoreFile}" ph.getFileAge "${sStoreFile}"
# local ilast=`cat "${sStoreFile}" 2>/dev/null | cut -f 1 -d ":" ` # local ilast=`cat "${sStoreFile}" 2>/dev/null | cut -f 1 -d ":" `
# local inow=`date +%s` # local inow=`date +%s`
...@@ -368,7 +365,7 @@ function ph._getageoflastvalue() { ...@@ -368,7 +365,7 @@ function ph._getageoflastvalue() {
# param string varName variable name of a value to store # param string varName variable name of a value to store
function ph._readlastvalue(){ function ph._readlastvalue(){
local varName=$1 local varName=$1
local sStoreFile=$(ph._getStorefile "${varName}") local sStoreFile; sStoreFile=$(ph._getStorefile "${varName}")
# cat "${sStoreFile}" 2>/dev/null | cut -f 2 -d ":" # cat "${sStoreFile}" 2>/dev/null | cut -f 2 -d ":"
cat "${sStoreFile}" 2>/dev/null cat "${sStoreFile}" 2>/dev/null
} }
...@@ -420,11 +417,11 @@ function ph.perfdeltaspeed(){ ...@@ -420,11 +417,11 @@ function ph.perfdeltaspeed(){
# retvalue="[reset data]" # retvalue="[reset data]"
retvalue="" retvalue=""
else else
local iage=$(ph._getageoflastvalue "${varName}") local iage; iage=$(ph._getageoflastvalue "${varName}")
test $iage = 0 && iage=1 test "$iage" = "0" && iage=1
local delta=$(echo "${value}-$lastvalue" | bc $bcParam ) local delta; delta=$(echo "${value}-$lastvalue" | bc $bcParam )
local deltaspeed=$(echo "${delta}*${deltaFactor}/(${iage})" | bc $bcParam) local deltaspeed; deltaspeed=$(echo "${delta}*${deltaFactor}/(${iage})" | bc $bcParam)
retvalue=$deltaspeed retvalue=$deltaspeed
fi fi
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment