Skip to content
Snippets Groups Projects
Select Git revision
  • 40a1685c14870a7e18a96146e1c78bbc4b1e1353
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_onehost

Blame
  • check_apache_requests 3.32 KiB
    #!/bin/bash
    # ======================================================================
    #
    # NAGIOS CLIENT CHECK :: apache requests
    #
    # ----------------------------------------------------------------------
    # script checks output of "/server-status" and counts scoreboard chars
    # ----------------------------------------------------------------------
    # 2020-04-09  v1.0  <axel.hahn@iml.unibe.ch>
    # ======================================================================
    
    . `dirname $0`/inc_pluginfunctions
    
    tmpfile=/tmp/check_apache_processes_1
    tmpfile2=/tmp/check_apache_processes_2
    url=`hostname -f`/server-status
    
    typeset -i iStart=0
    typeset -i iEnd
    typeset -i iCount=0
    
    typeset -i iSlots=0
    typeset -i iActive=0
    typeset -i iIdle=0
    typeset -i iUnused=0
    typeset -i iUsage=0
    
    
    # ----------------------------------------------------------------------
    # pre checks
    # ----------------------------------------------------------------------
    ph.reqire wget
    
    # ----------------------------------------------------------------------
    # check output
    # ----------------------------------------------------------------------
    
    # --- get /server-status page
    wget --no-check-certificate -O $tmpfile $url 2>/dev/null
    if [ $? -ne 0 ]; then
        ph.abort "UNKNOWN: url $url did not respond a server status. `wget --no-check-certificate -O - -S $url`"
    	exit 1
    fi
    
    
    # set default / override from command line params
    typeset -i iWarnLimit=`     ph.getValueWithParam 75 w "$@"`
    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 ':'`
    
    sed -n "${iStart},${iEnd}p" $tmpfile | sed 's#<.*>##g' | tr -d "\n" >$tmpfile2
    
    # <p>Scoreboard Key:<br />
    # "<b><code>_</code></b>" Waiting for Connection, 
    # "<b><code>S</code></b>" Starting up, 
    # "<b><code>R</code></b>" Reading Request,<br />
    # "<b><code>W</code></b>" Sending Reply, 
    # "<b><code>K</code></b>" Keepalive (read), 
    # "<b><code>D</code></b>" DNS Lookup,<br />
    # "<b><code>C</code></b>" Closing connection, 
    # "<b><code>L</code></b>" Logging, 
    # "<b><code>G</code></b>" Gracefully finishing,<br /> 
    # "<b><code>I</code></b>" Idle cleanup of worker, 
    # "<b><code>.</code></b>" Open slot with no current process<br />
    
    
    # --- count slots in the scoreboard
    
    # total slots available
    iSlots=`cat $tmpfile2 | wc -m`
    
    # running apache processes waiting for a request
    iIdle=iCount=`sed -e "s/[^_]//g" $tmpfile2 | wc -m`
    
    # count of processes apache still can create
    iUnused=iCount=`sed -e "s/[^\.]//g" $tmpfile2 | wc -m`
    
    # count of actively used slots
    iActive=$iSlots-$iIdle-$iUnused
    
    iUsage=$iActive*100/$iSlots
    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>##'
    echo
    
    # --- add performnce data
    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`
      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
    
    # ----------------------------------------------------------------------