bb-swap.sh

Author Galen Johnson
Compatibility Xymon 4.2
Requirements Unix, Linux
Download
Last Update 2007-09-30

A script to monitor the amount of free swap space.

Client side

- Install bb-swap.sh into the $HOBBITCLIENTHOME/ext/ directory - Modify/install bb-swap.cfg into $HOBBITCLIENTHOME/etc directory

# Configuration file for bb-swap.sh external script
#
# Change History:
#
#       1.5-CP  07/27/2000      First release
#
# Edit variables below for your needs
#
# Set thresholds for free swap space remaining
#
SWAPWARN="25"       # GO YELLOW AT THIS LEVEL
SWAPPANIC="15"      # GO RED AND PAGE AT THIS LEVEL

- Modify your clientlaunch.cfg, adding:

[bbswap]
        ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
        CMD $HOBBITCLIENTHOME/ext/bb-swap.sh
        LOGFILE $HOBBITCLIENTHOME/logs/bb-swap.log
        INTERVAL 5m

Server side

- For NCV Graphs:

  1. hobbitgraph.cfg, add:
    [bbswap]
            TITLE Swap Utilization
            YAXIS % Free
            DEF:free=bbswap.rrd:PercentFree:AVERAGE
            LINE2:free#0000FF:% Swap free
            -u 100
            -b 1024
            GPRINT:free:LAST: \: %5.1lf (cur)
            GPRINT:free:MAX: \: %5.1lf (max)
            GPRINT:free:MIN: \: %5.1lf (min)
            GPRINT:free:AVERAGE: \: %5.1lf (avg)\n
    
  1. hobbitserver.cfg, you'll be modifying TEST2RRD and adding a variable named NCV_bbswap:
    TEST2RRD="[...],bbswap=ncv"
    NCV_bbswap="PercentFree:GAUGE,*:NONE"
  1. (optional)add the following to add the bbswap info to the trends coloumn:
    TRENDS:*,[...],bbswap

bb-swap.sh

Show Code ⇲

Hide Code ⇱

#!/bin/sh
#
# bb-swap.sh - Xymon extension script to monitor swap space.
#
#       Based on bb-swap.sh (http://www.deadcat.net/viewfile.php?fileid=810)
#       from deadcat.net
#
###############################################################################
#--------1---------2---------3---------4---------5--------6---------7---------8
#
# Scripts in the $HOBBITCLIENT/ext directory are only run if
# they are defined in the clientlaunch.cfg for the current host
# Add the following to your clientlaunch.cfg:
#
#[bbswap]
#        ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
#        CMD $HOBBITCLIENTHOME/ext/bb-swap.sh
#        LOGFILE $HOBBITCLIENTHOME/logs/bb-swap.log
#        INTERVAL 5m
#
#
 
 
# Set up Column Name for display
#
TEST="bbswap"
 
#
# The name of the configuration file
#
BBSWAPCONFIG=$HOBBITCLIENTHOME/etc/bb-swap.cfg
 
if [ ! -r $BBSWAPCONFIG ]
then
        echo "Configuration file $BBSWAPCONFIG not found... exiting"
        exit 1
else
        # echo "*** LOADING $BBSWAPCONFIG ***"
        . $BBSWAPCONFIG
fi
 
#=====================================================================
# NOTIFY ON SWAP SPACE UTILIZATION
#=====================================================================
#
# echo "*** SWAP SPACE TEST ***"
 
COLOR="green"
 
case "$BBOSTYPE"
in
        aix)            # For AIX [from Tom Kauffman (kauffmanT@nibco.com) 11/19/1999]
                MSG=`/usr/sbin/lsps -l | $GREP "%" | /usr/bin/tr -cd '[0-9] \012' | $AWK '{
                USED = $2 / 100 * $1
                FREE = $1 - USED
                print  "                   Total    Used    Free  %Free"
                printf "swap             %7d %7d %7d %3d%%\n", $1, USED, FREE, 100 - $2
                }' -`
                used=`/usr/sbin/lsps -s | $GREP "%" | $AWK '{ print $2 }' |  cut -d% -f1`
                SWAPPCT=`echo "scale=2;100 - $used" | bc`
                ;;
        dynix)          # For Sequent DYNIX/ptx [from Stephen Couch (couch@freemontcomp.com) 12/16/1999]
                total=`/etc/swap -l | $GREP "dsk" | $AWK '{blks=blks+$4};END{print blks}'`
                free=`/etc/swap -f | $GREP "used" | $AWK '{print $3}'`
                dec=`echo "scale=2;$free / $total * 100" | bc`
                SWAPPCT=`echo $dec|cut -d. -f1`
                ;;
        freebsd)        # For FreeBSD [from Rick Owens (owens@fvcc.cc.mt.us) 12/22/1999]
                SWAPPCT=`/usr/sbin/swapinfo | /usr/bin/tail -1 | $AWK '{print 100 - $5}'`
                ;;
        hp-ux)          # For HP UNIX [from Jason Armbruster (armbrust@cusys.edu) 02/28/1999]
                MSG=`/usr/sbin/swapinfo -t | $GREP total | /usr/bin/tr -cd '[0-9] \012' | $AWK '{
                print  "               Total     Used     Free     %Used"
                printf "swap           %7d %7d %7d %4d%%\n", $1, $2, $3, 100 * $2 / $1
                }' -`
                used=`/usr/sbin/swapinfo -t | $GREP "total" | $AWK '{ print substr($5,0,2) }'`
                SWAPPCT=`echo "scale=2;100 - $used" | bc`
                ;;
        irix)           # For IRIX [from Christian Perrier (christian.perrier@onera.fr) 09/11/2000]
                avail=`/sbin/swap -lbfn | $GREP -v '^ #' | $AWK '{ print $7 }'`
                total=`/sbin/swap -lbfn | $GREP -v '^ #' | $AWK '{ print $8 }'`
                dec=`echo "scale=2;$avail / $total * 100" | bc`
                SWAPPCT=`echo $dec | cut -d. -f1`
                ;;
        linux|redhat|debian)            # For Debian Linux : free lives in /usr/bin
                MSG=`/usr/bin/free | $GREP "Swap" | /usr/bin/tr -cd '[0-9] \012' | $AWK '{
                print  "                   Total        Used   Free     %Free"
                printf "swap             %9d %9d %9d %3d%%\n", $1, $2, $3, 100 * $3 / $1
                }' -`
                free=`/usr/bin/free | $GREP "Swap:" | $AWK '{ print $4 }' | cut -dk -f1`
                total=`/usr/bin/free | $GREP "Swap:" | $AWK '{ print $2 }' | cut -dk -f1`
                dec=`echo "scale=2;$free / $total * 100" | bc`
                SWAPPCT=`echo $dec | cut -d. -f1`
                ;;
        openbsd|netbsd) # For OpenBSD/netbsd [from Josh Rivel (jrivel@dti.net)
                SWAPPCT=`/sbin/swapctl -l | /usr/bin/tail -1 | $AWK '{ print 100 - $5 }'`
                ;;
        osf)            # For Compaq Tru64 UNIX/Digital UNIX/ Digital OSF/1
                SWAPPCT=`/usr/sbin/swapon -s | $GREP "Available" | $AWK '{ print substr($6,0,2) }'`
                ;;
        sco|unixware)   # For SCO 5 & unixware v2 [from Nicolas Chuche (nchuche@teaser.fr) 02/16/2000)
                free=`/etc/swap -l | $GREP -v path | $AWK '{ print $5 }'`
                total=`/etc/swap -l | $GREP -v path | $AWK '{ print $5 }'`
                dec=`echo "scale=2;$free / $total * 100" | bc`
                SWAPPCT=`echo $dec | cut -d. -f1`
                ;;
        sunos|solaris)  # For Solaris and SunOS
                MSG=`/usr/sbin/swap -s | /usr/bin/tr -cd '[0-9] \012' | $AWK '{ TOT = $3 + $4
                print "                 Total    Used    Free      % Free"
                printf "swap             %7d %7d %7d %5d%%\n", TOT, $3, $4, 100 * $4 / TOT
                }' -`
                used=`/usr/sbin/swap -s | $AWK '{ print $9 }' | cut -dk -f1`
                avail=`/usr/sbin/swap -s | $AWK '{ print $11 }' | cut -dk -f1`
                total=`expr $used + $avail`
                dec=`echo "scale=2;$avail / $total * 100" | bc`
                SWAPPCT=`echo $dec | cut -d. -f1`
                ;;
        *)              # For Unknown Operating Systems
                SWAPPCT=100
                ;;
esac
 
MSG="
 
Percent Free: ${SWAPPCT}%
 
${MSG}"
 
if test "$SWAPPCT" -le "$SWAPPANIC"
then
        COLOR="red"
elif test "$SWAPPCT" -le "$SWAPWARN"
then
        COLOR="yellow"
else
        COLOR="green"
fi
 
#
# Now send this information to the Xymon server
#
 
$BB $BBDISP "status $MACHINE.$TEST $COLOR `$DATE` ${MSG} "
  • update format for missing OSes
  • 2007-09-30
    • Initial release
  • monitors/bbswap.txt
  • Last modified: 2009/11/23 05:18
  • (external edit)