My Monitor (CHANGEME)

Author Butch Deal
Compatibility Xymon 4.2
Requirements unix, dmidecode for linux
Download None
Last Update 2009-06-02

Monitors lots of extra CPU and system related bits. Works on Linux (RH & SuSe), Solaris, and now MacOS X (Darwin). Removed the need to install prtdiag on Linux, and added more complete relese version info. Added some support for Solaris 10 zones and for dual core Ultra sparc IV.

Client side

add these lines to hobbitclient.cfg:

UNAME="/bin/uname"
SWAP="/usr/sbin/swap" 
PSRINFO="/usr/sbin/psrinfo"
MPSTAT="/usr/bin/mpstat"

Modify your clientlaunch.cfg, adding:

[cpu2]
	ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
	CMD $HOBBITCLIENTHOME/ext/cpu2.sh
	LOGFILE $HOBBITCLIENTHOME/logs/cpu2.log
	INTERVAL 5m

edit cpu2.sh for proper path to sudo and dmidecode. Set up sudo so that dmidecode can be run without password. (script tried both /usr/local/bin/sudo and /usr/bin/sudo).

Server side

cpu2.sh

Show Code ⇲

Hide Code ⇱

#!/bin/sh
#
# bb-cpu2.sh: Sun Enterprise Server check - BB external script test
#             ^ and now Linux
#
#####  Purpose is to report back to a central server, all "standard"
#####    detailed information about network, disk, volume, cpu, memory
#####    which is not reported thru regular "easy" checks.
#####
#
# version 1.0
# version 2.0 - includes uname and prtdiag checks too
# version 2.1 - properly uses $CAT instead of cat
# version 2.2 - properly uses $MACHINE instead of `uname -n` in bb-hosts check
# version 2.4 - properly uses $THIS_HOST instead of $MACHINE due to fqdn using
#                 comma in name - thanks Craig Cook
# version 3.0 - updates to work properly with BB 1.6
#               properly uses `uname -i` for platform check on E10K
# version 3.1 - changed /tmp to $BBTMP
#                       cpu2 to $TEST
#                       $THIS_HOST to $MACHINE
#               removed code that checked for the existence of "cpu2"
#                 after the server name in bb-hosts
#               moved comment explaining purpose of script to start of code
#               removed <BLOCKQUOTE> statements
# version 3.2 - made swap check optional
#               Applied Todd Jimenez style get_header and get_footer functions
#               added check for bbsys.local vars being set
#               changed wc to $WC
#               restored functionality to check for the existence of "cpu2"
#                 after the server name in bb-hosts, but now optional
#               changed &red and &yellow to variables
# version 3.3 - Added changes suggested by Andrew Clarke
#               - skip tests that involve uname -x on solaris 2.5.1, since it
#                 does not support this switch.
#               - [ "SWAP_INFO" = "Y" ] was missing a $
#               - new comment line for testing
#               - swap -s on solaris 2.51 returns "1"
# version 3.5 - Added support for Linux
#               - physical cpu count for both Solaris and Linux
#               - OS release information for both Solaris and Linux
#               - have not tested SWAP_INFO for Linux
# version 3.6 - Added some support for Mac OS X (Darwin) 
#               - modularised some of the procedures
#               - removed need for prtdiag on Linux
# version 3.9 - Added some support for Solaris zones
#               - added support for dual core Ultra sparc IV
# version 3.9.1 - started support for Sun4v Niagara chips
# version 3.10 - Added more dmidecode entries
#
# BIG BROTHER / XXXXXXXXXXXXXXXX status
#
# Written by Paul A. Luzzi
#  on March 22, 2000
#
# 3.0 Updates by David Levin
#  on January 3, 2001
#
# 3.1 Updates by Craig Cook   26 Apr 2001
# 3.2 Updates by Craig Cook   31 Oct 2001
# 3.3 Updates by Craig Cook   21 Nov 2001
# 3.5 Updates by Richard Deal & Dan Gomez 1 Oct 2004
# 3.6 Updates by Richard Deal 6 Oct 2004
# 3.7 Updates by Daniel Gomez 6 Dec 2004 - update paths
# 3.8 Updates by Daniel Gomez 8/2/05- added /etc/*release
# 3.9 Updates by Richard Deal 9/1/05
# 3.10 Updates by Daniel Gomez 8/18/07

########################################
# NOTE
# This has been tested with BB 1.8c and 1.9e
# 
# Tested on :
#   Sun Solaris, Linux, Darwin
########################################

###########################################################################
# INSTALLATION
#  step 1  - update bb-bbexttab to include this bb-cpu2.sh
#            (older BB versions update EXT section of the bbdef.sh script)
#
#  step 2 - if you want this script to show swap info uncomment
#             SWAP_INFO="Y"
#           NOTE: it does not do any error checking on swap space though
#
#  step 3 - copy lines mentioned to bbsys.local (without the #'s)
#
#  step 4 - if you are using an older version of BB without bb-bbexttab
#             and you don't want this run on every client uncomment
#             CHECK_BB_HOSTS="Y" and add the name of this $TEST to
#             bb-hosts for this client. eg.
#             myserver1.domain.com   # cpu2
#
#  step 5 - restart Big Brother
#
#  *Linux* 
#       install dmidecode to determin actual CPU count
#
# NOTE - the TEST variable in the configuration section, this is the name
#        used as the column header and in the BB-HOSTS file.
###########################################################################

###########################################################################
# For testing, ensure BBHOME is set and uncomment the following line
# BB=""; BBDISP="echo"
###########################################################################

##################################
# CONFIGURE IT HERE
##################################
TEST="cpu2"
BBPROG="$0"; export BBPROG

VERSION="<center><h6>- ID: bb-cpu2.sh, v 3.10 2007/08/24 -</h6></center>"

#
# Start of lines to put in bbsys.local for Solaris
#
# SWAP="/usr/sbin/swap"
# PSRINFO="/usr/sbin/psrinfo"
# MPSTAT="/usr/bin/mpstat"
# UNAME="/sbin/uname"
# PLATFORM_SPEC=`$UNAME -i`
# PRTDIAG_COMMAND="/usr/platform/$PLATFORM_SPEC/sbin/prtdiag"
# PRTDIAG_OPT="-v"
# export SWAP PSRINFO MPSTAT UNAME

#
# Start of lines to put in bbsys.local for Linux
#
# SWAP="/sbin/swapon"
# PSRINFO="cat /proc/cpuinfo"
# MPSTAT="/usr/bin/mpstat -P ALL"
# UNAME="/bin/uname"
# export SWAP PSRINFO MPSTAT UNAME
#
# For Linux this determins actual cpu count
# you can use sudo to run dmidecode if need be
#
if [ -x "/usr/local/bin/sudo" ]; then
  DMIDECODE="/usr/local/bin/sudo /usr/sbin/dmidecode"
else
  DMIDECODE="/usr/bin/sudo /usr/sbin/dmidecode"
fi

#DMIDECODE="/usr/local/bin/sudo /usr/sbin/dmidecode"

#
# Start of lines to put in bbsys.local for Mac OS X Darwin
#
# UNAME="/usr/bin/uname"
# export UNAME

#
# End of lines to put in bbsys.local
#

# define colours for graphics
RED_PIC="&red"
YELLOW_PIC="&yellow"

# don't scan through bb-hosts every time
# this is here for older BB versions without bb-bbexttab
# uncomment to activate
#CHECK_BB_HOSTS=Y

# Uncomment to display swap info
#SWAP_INFO="Y"

##################################
# Start of script
##################################

if test ! "$BBHOME"
then
	echo "template: BBHOME is not set"
	exit 1
fi

if test ! -d "$BBHOME"
then
	echo "template: BBHOME is invalid"
	exit 1
fi

if test ! "$BBTMP"                      # GET DEFINITIONS IF NEEDED
then
         # echo "*** LOADING BBDEF ***"
        . $BBHOME/etc/bbdef.sh          # INCLUDE STANDARD DEFINITIONS
fi

#
# Define header
#
get_header()
{
  echo ""
  echo "<FONT SIZE=+2><b>$1</b></FONT> ($2 $3)"
  echo ""
  #If you do not want the header in a bigger font use line below instead
  #  echo "<b>$1</b> ($2 $3)"
}

#
# Define footer
#
get_footer()
{
  #echo "<BR><BR>"
  echo ""
}

#
# Mac OS X Darwin prtdiag cpu info
#
darwin_prtdiag() {

  printf "CPU\tCPU MHz     L2/L3 Cache     CPU Model  CPU Type\n"
  printf "%b---\t-------    -------------    ---------  --------\n"

  CPUSPEED=`system_profiler SPHardwareDataType | $GREP "CPU Speed" | cut -d ":" -f 2-`
  L2CACHE=`system_profiler SPHardwareDataType | $GREP "L2 Cache" | cut -d ":" -f 2-`
  L3CACHE=`system_profiler SPHardwareDataType | $GREP "L3 Cache" | cut -d ":" -f 2-`
  CPU_MODEL=`system_profiler SPHardwareDataType | $GREP "CPU Type" | $AWK {'print $4'}`
  CPU_TYPE=`hostinfo | $GREP "Processor type" | $AWK {'print $3'}`
  for i in `hostinfo | grep active | cut -d : -f 2-` ; do
    printf " $i\t$CPUSPEED\t  $L2CACHE /$L3CACHE\t$CPU_MODEL\t$CPU_TYPE\n"
  done
} # end darwin_prtdiag

#
# Linux prtdiag cpu info
#
linux_prtdiag() {

  printf "CPU\t    CPU MHz     CACHE (KB)     Bogomips\n"
  printf "%b---\t   ---------    ----------     -------- \n"

  for i in `grep "^[^*]*processor" /proc/cpuinfo | grep -v "ID" |cut -d ":" -f 2| perl -pe 's/^\s+//'`; do
    CPULINE=`grep processor /proc/cpuinfo |grep -v "Physical" |grep -w $i`
    CPUSPEED=`grep -A20 -w "$CPULINE" /proc/cpuinfo |grep "cpu MHz" | cut -d " " -f 3-`
    CPUCACHE=`grep -A20 -w "$CPULINE" /proc/cpuinfo |grep "cache size" | cut -d " " -f 3-`
    BOGOMIPS=`grep -A20 -w "$CPULINE" /proc/cpuinfo |grep "bogomips" | cut -d " " -f 2`
    CPUARCH=`grep -A20 -w "$CPULINE" /proc/cpuinfo |grep "model name" | cut -d " " -f 3-`
    printf " $i\t    $CPUSPEED\t  $CPUCACHE\t$BOGOMIPS  \t$CPUARCH\n"
  done
} # end linux_prtdiag

# Get Setup - check environment
get_setup () {
  #####
  #####  Setup any and all variables before beginning.
  #####
  # Check defaults have been set
  if [ "$UNAME" = "" ]; then
    if [ $BBOSTYPE = "darwin" ] ; then
      UNAME="/usr/bin/uname"
    else
      UNAME="/bin/uname"
    fi
    echo ""
    echo "$YELLOW_PIC UNAME command is not defined in etc/bbsys.local - using default: $UNAME"
  fi

  if [ $BBOSTYPE != "darwin" ] ; then
    if [ "$SWAP" = "" ]; then
      SWAP="/usr/sbin/swap"
      echo ""
      echo "$YELLOW_PIC SWAP command is not defined in etc/bbsys.local - using default: $SWAP"
    fi

    if [ "$PSRINFO" = "" ]; then
      PSRINFO="/usr/sbin/psrinfo"
      echo ""
      echo "$YELLOW_PIC PSRINFO command is not defined in etc/bbsys.local - using default: $PSRINFO"
    fi

    if [ "$MPSTAT" = "" ]; then
      if [ `$UNAME -s` = "Linux" ] ; then
        MPSTAT="/usr/bin/mpstat -P ALL"
      else
        MPSTAT="/usr/bin/mpstat"
      fi
      echo ""
      echo "$YELLOW_PIC MPSTAT command is not defined in etc/bbsys.local - using default: $MPSTAT"
    fi
    if [ `$UNAME -s` != "Linux" ] ; then
      if [ "$PLATFORM_SPEC" = "" ]; then
        PLATFORM_SPEC=`$UNAME -i`
      fi
  
      if [ "$PRTDIAG_COMMAND" = "" ]; then
        PRTDIAG_COMMAND="/usr/platform/$PLATFORM_SPEC/sbin/prtdiag"
      fi
  
      if [ "$PRTDIAG_OPT" = "" ]; then
        PRTDIAG_OPT="-v"
        echo ""
        echo "$YELLOW_PIC PRTDIAG_OPT is not defined in etc/bbsys.local - using default: $PRTDIAG_OPT"
      fi

    fi

  fi # end if darwin
  export COLOR

} # end get_setup

get_procinfo () {
  #####
  #####  List CPU Info. 
  #####

 case $BBOSTYPE in
   darwin )
      get_header "Processor Info" "hostinfo"
      NUM_PROCS=`hostinfo | grep "physically available" |  $AWK {'print $1'}`
      
      hostinfo | $GREP -A3 "configured"

      get_footer
     ;;
   solaris )
      CATCH_COMMAND=` $PSRINFO `

      get_header "Processor Info" "$PSRINFO"
    
      NUM_PROCS=` $PSRINFO | $WC -l `
      if [ "$?" = "0" ]; then
          ON_LINES=`$PSRINFO | $EGREP "on-line|no-intr" | $WC -l`
          if [ "$NUM_PROCS" = "$ON_LINES" ]; then
              echo "$CATCH_COMMAND"
          else
              COLOR="red"
              echo "$RED_PIC Only $ON_LINES of $NUM_PROCS on-line"
              echo "$CATCH_COMMAND"
          fi
      else
          COLOR="red"
          echo "$RED_PIC Problem with some/all processors !!!"
      fi

      get_footer
     ;;
   linux | redhat | debian | \
   * ) ;;
 esac
 export COLOR
   
} # end get_procinfo

get_mpstat () {
  #####
  #####  List more CPU Info. 
  #####

  if [ $BBOSTYPE != "darwin" ] ; then
    CATCH_COMMAND=` $MPSTAT `

    get_header "mpstat info" "$MPSTAT"

    if [ "$?" = "0" ]; then
        echo "$CATCH_COMMAND"
    else
        COLOR="red"
        echo "$RED_PIC Problem with some/all processors !!!"
    fi
    get_footer
  fi
  export COLOR
   
} # end get_mpstat

get_prtdiag () {
  #####
  #####  List still more CPU Info. 
  #####

  if [ "$OS_REL" != "5.5.1" ] ; then
    # Solaris 2.5.1 does not support -X on uname, so skip this test

      case $BBOSTYPE in
        darwin )
          get_header "prtdiag info" "from system_profiler and hostinfo"
          ECHO_COMMAND=`darwin_prtdiag`
          ;;
        solaris )
          ZONENAME=/usr/bin/zonename
          if [ -s "$ZONENAME" ]; then
            ZONE=`$ZONENAME`
          else
            ZONE="global"
          fi
          if  [ "$ZONE" != "global" ] ; then
            get_header "Sub-zone" "$ZONE"
          else
            get_header "prtdiag info" "$PRTDIAG_COMMAND $PRTDIAG_OPT \| $AWK '/CPU.*.CPU/, /^$/ {print $0}'"

            if [ -s "$PRTDIAG_COMMAND" ]; then
              ECHO_COMMAND=` $PRTDIAG_COMMAND $PRTDIAG_OPT |
                             $AWK '/CPU.*.CPU/, /^$/ {print $0}' |
                             $GREP -v "^$" `
              CATCH_COMMAND=` $PRTDIAG_COMMAND $PRTDIAG_OPT |
                              $AWK '/CPU.*.CPU/, /^$/ {print $0}' |
                              $GREP -v "^$" | $TAIL +4 `
              CONFIGURED_PROCS=` $PRTDIAG_COMMAND $PRTDIAG_OPT |
                                 $AWK '/CPU.*.CPU/, /^$/ {print $0}' |
                                 $GREP -v "^$" |
                                 $TAIL +4 |
                                 $WC |
                                 $AWK '{print $NF}' `
              if [ "$OS_REL" = "5.10" ] ; then
                # Solaris 10 supports psrinfo -p and Sparc IV chips
                INSTALLED_CHIPS=` $PSRINFO -p`
                INSTALLED_PROCS=` $PSRINFO -p`
              else
                INSTALLED_PROCS=` $UNAME -X |
                                  $GREP NumCPU |
                                  $AWK '{print $NF}' `
              fi
            else
              echo "No prtdiag installed on this platform - $PLATFORM_SPEC"
            fi
          fi
          ;;
        linux | redhat | debian | \
        * )
          get_header "prtdiag info" "from /proc/cpuinfo"
          ECHO_COMMAND=`linux_prtdiag`
          ;;
      esac
  
      if [ `$UNAME -m` != "sun4v" ] ; then
        if [ "$CONFIGURED_PROCS" != "$INSTALLED_PROCS" ]; then
          COLOR="red"
          echo "$RED_PIC psrinfo reports $INSTALLED_PROCS installed processors, but prtdiag shows only $CONFIGURED_PROCS present."
          echo "Some processors seem to be offline or problematic !!!"
      #  else
      #    echo "$ECHO_COMMAND"
        fi
      fi
      echo "$ECHO_COMMAND"
   
    get_footer

  fi
  export COLOR
} # end get_prtdiag

get_sysinfo () {
 case $BBOSTYPE in
   darwin )
      get_header "uname info" "hostinfo"
      echo "Node = `$UNAME -n`"
      NUM_PROCS=`hostinfo | grep "physically available" |  $AWK {'print $1'}`
      echo "Physical CPUs = $NUM_PROCS"
      system_profiler SPSoftwareDataType | $GREP "System Version"
      $UNAME -v
      
      get_footer
     ;;
   solaris )
      get_header "uname info" "$UNAME -X | $EGREP Node|NumCPU"

      if [ "$OS_REL" != "5.5.1" ] ; then
        # Solaris 2.5.1 does not support -X on uname, so skip this test
         CATCH_COMMAND=` $UNAME -X | $EGREP "Node|NumCPU" `
         if [ "$?" = "0" ]; then
           echo "$CATCH_COMMAND"
         else
           COLOR="red"
           echo "$RED_PIC Problem with uname command.  Cant determine installed processor count !!!"
         fi
         if [ "$OS_REL" = "5.10" ] ; then
           echo "Chips = $INSTALLED_CHIPS"
         fi
      fi
      $GREP Solaris /etc/release
      get_footer
     ;;
   linux | redhat | debian | \
   * )
      get_header "uname info" "$UNAME -X | $EGREP Node|NumCPU"
      echo "Node = `$UNAME -n`"
      echo "System CPUs   = `$GREP processor /proc/cpuinfo | grep -v Physical | $WC -l`"
      if [ "$DMIDECODE" != "" ]; then
        echo "Physical CPUs = `$DMIDECODE  | grep "Central Processor" | wc -l`"
        MANUFACTURER=` $DMIDECODE -s system-manufacturer`
        echo "System Manufacturer = $MANUFACTURER"
        echo "System Product Name = `$DMIDECODE -s system-product-name`"
        echo "System Serial Number = `$DMIDECODE -s system-serial-number`"
        echo "Chassis Serial Number = `$DMIDECODE -s chassis-serial-number`"
        echo "BIOS Version = `$DMIDECODE -s bios-version`"
      fi
      echo "Boot Command = `$CAT /proc/cmdline`"
      echo "Kernel Version = `$CAT /proc/version`"
      echo "Version Release:"
      $CAT /etc/*release
     ;;
 esac
 export COLOR
} # end get_sysinfo

#####
#####  Get Status proc - used to get all responses
#####
get_swap() 
{

  #####
  #####  System Swap and Memory Monitoring
  #####
  if [ "$SWAP_INFO" = "Y" ]; then

    get_header "Swap Info" "$SWAP -l and $SWAP -s"

    CATCH_COMMAND1=` $SWAP -l `

    if [ "$?" = "0" ]; then
      echo "$CATCH_COMMAND1"
    else
      COLOR="red"
      echo "$RED_PIC Problem with swap !!!"
    fi

    # This is the "normal" return value on sucess
    RETURN_VAL=0

    if [ "$OS_REL" = "5.5.1" ] ; then
      # Solaris 2.51 returns "1" from "swap -s"!!
      RETURN_VAL=1
    fi

    CATCH_COMMAND2=` $SWAP -s `

    if [ "$?" = "$RETURN_VAL" ]; then
      echo "$CATCH_COMMAND2"
    else
      COLOR="red"
      echo "$RED_PIC Problem with swap !!!"
    fi
  fi

  export COLOR

} # end get_swap

  #####
  #####  Setup some variables for use later
  #####
  COLOR="green"
  OS_REL=` $UNAME -r `

#####
#####  Main body
#####

if [ "$CHECK_BB_HOSTS" = "Y" ]; then
  # convert "," to "." in the hostname
  MACHINE_WITH_DOTS=`echo $MACHINE | $SED 's/,/\./g'`

  $GREP $MACHINE_WITH_DOTS $BBHOSTS | $GREP "$TEST" |
  while read line
  do
    if [ ! -z "$line" ]; then
      get_status > $BBTMP/$MACHINE.$TEST

      # NOW USE THE BB COMMAND TO SEND THE DATA ACROSS
      $BB $BBDISP "status $BBTMP/$MACHINE.$TEST $COLOR `$DATE` `$CAT $BBTMP/$MACHINE.$TEST` "
    fi
  done
else
  get_setup > $BBTMP/$MACHINE.$TEST
  get_procinfo >> $BBTMP/$MACHINE.$TEST
  get_mpstat >> $BBTMP/$MACHINE.$TEST
  get_prtdiag >> $BBTMP/$MACHINE.$TEST
  get_sysinfo >> $BBTMP/$MACHINE.$TEST
  if [ "$SWAP_INFO" = "Y" ]; then
    get_swap >> $BBTMP/$MACHINE.$TEST
  fi

  # NOW USE THE BB COMMAND TO SEND THE DATA ACROSS

#COLOR="green" # hard code to green till finished.
  $BB $BBDISP "status $MACHINE.$TEST $COLOR `$DATE` `$CAT $BBTMP/$MACHINE.$TEST`
 
$VERSION"
fi

# Clean up our mess
# Checking for existence of files since the whole test may be optional
#   and may not actually run on every client
#
if [ -f $BBTMP/$MACHINE.$TEST ]; then
  $RM $BBTMP/$MACHINE.$TEST
fi

##############################################
# end of script
##############################################
  • Paul A. Luzzi
  • David Levin
  • Craig Cook
  • Butch Deal
  • Daniel Gomez
  • 2000-03-22
    • Initial release …….
  • version 3.5 - Added support for Linux
    1. physical cpu count for both Solaris and Linux
    2. OS release information for both Solaris and Linux
    3. have not tested SWAP_INFO for Linux
  • version 3.6 - Added some support for Mac OS X (Darwin)
    1. modularised some of the procedures
    2. removed need for prtdiag on Linux
  • version 3.9 - Added some support for Solaris zones
    1. added support for dual core Ultra sparc IV
  • version 3.9.1 - started support for Sun4v Niagara chips
  • version 3.10 - Added more dmidecode entries
  • monitors/cpu2.txt
  • Last modified: 2009/11/23 05:42
  • (external edit)