monitors:db_cpu.ksh

Error loading plugin struct
ParseError: syntax error, unexpected 'fn' (T_STRING), expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
More info is available in the error log.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
monitors:db_cpu.ksh [2014/02/27 04:22] – [db_cpu.ksh] vernonmonitors:db_cpu.ksh [2014/02/27 04:37] (current) – [Changelog] vernon
Line 5: Line 5:
 ^ Requirements | Perl, Oracle Database, Solaris | ^ Requirements | Perl, Oracle Database, Solaris |
 ^ Download | None | ^ Download | None |
-^ Last Update | 2013-04-23 |+^ Last Update | <del>2013-04-23</del> 2014-02-27 |
  
 ===== Description ===== ===== Description =====
Line 882: Line 882:
 #!/usr/bin/ksh #!/usr/bin/ksh
 COLOUR=green COLOUR=green
-TOP=/usr/local/bin/top+type top >> /dev/null 
 +ERR=$? 
 +if [ $ERR -eq 0 ] 
 +then 
 +   TOP=$(type top| cut -d\( -f2 | cut -d\) -f1) 
 +else 
 +   [ -x /usr/local/bin/top ] && TOP=/usr/local/bin/top 
 +fi 
 CPU_tmp=$XYMONTMP/db_cpu_list CPU_tmp=$XYMONTMP/db_cpu_list
 TEMPFILE=$XYMONTMP/db_cpu TEMPFILE=$XYMONTMP/db_cpu
Line 911: Line 919:
 # Get the idle figure. Run top -d4, and take the last value to prevent # Get the idle figure. Run top -d4, and take the last value to prevent
 # a possible skewed result from the other xymon tasks that have just kicked off. # a possible skewed result from the other xymon tasks that have just kicked off.
-IDLE=$($TOP -n -d4 | grep "^CPU states" | cut -d"%" -f1 | sed "s/CPU states: //g" | tail -1) +if [ -x $TOP ] 
-IDLE="${IDLE}000"+then 
 +   # We have a working version of top 
 +   IDLE=$($TOP -n -d4 | grep "^CPU states" | cut -d"%" -f1 | sed "s/CPU states: //g" | tail -1) 
 +   IDLE="${IDLE}000" 
 +else 
 +  # No working top. We will have to resort to iostat. 
 +  # Pity. Top is at least accurate to 1 decimal place. 
 +  IDLE=$(iostat -p 2 5 | awk '{ print $NF }' | tail -1) 
 +  IDLE="${IDLE}.0000" 
 +fi
  
 # Set DBID to your oracle identifier. You can use the userID or the username # Set DBID to your oracle identifier. You can use the userID or the username
 # or any value that will identify your oracle processes in a ps | grep # or any value that will identify your oracle processes in a ps | grep
-DBID="oracle"+DBID="^ 0000100"
 # Get a list of all Databases running on the system # Get a list of all Databases running on the system
-DBLIST=$(ps -efa | grep $DBID | grep pmon | cut -d"_" -f3 | sort | uniq)+DBLIST=$(ps -efa | grep "$DBID| grep pmon | cut -d"_" -f3 | sort | uniq)
 if [ -z "$DBLIST" ] if [ -z "$DBLIST" ]
 then then
     echo "No databases found!" >> $TEMPFILE     echo "No databases found!" >> $TEMPFILE
     [ "$NO_DB_ALERT" = "true" ] && COLOUR=$NO_DB_COLOUR     [ "$NO_DB_ALERT" = "true" ] && COLOUR=$NO_DB_COLOUR
-    DB_USED="0.0000" # A reasonable assumption if there are no databases+    DB_USED="0.0000" # A reasonable assumtion if there are no databases
 else else
    # Get a list of all the processes and their CPU utilisation.    # Get a list of all the processes and their CPU utilisation.
Line 956: Line 973:
       fi       fi
       DB_USED=$(echo "$DB_USED+$USAGE" | bc)       DB_USED=$(echo "$DB_USED+$USAGE" | bc)
 +      USAGE=$(echo $USAGE | sed 's/ \./0\./g')
       echo "$DB $USAGE" >> $TEMPFILE.2       echo "$DB $USAGE" >> $TEMPFILE.2
    done    done
 fi fi
- 
 if [ $SHOW_IDLE -eq 1 ] if [ $SHOW_IDLE -eq 1 ]
 then then
Line 968: Line 985:
    # We only change the IDLE and OTHER values though, not the database values.    # We only change the IDLE and OTHER values though, not the database values.
    # Those are real data.    # Those are real data.
-   if [ $OTHER -le 0 ]+   if [ $OTHER -lt 0 ]
    then    then
       IDLE=$(echo ${IDLE}+${OTHER} | bc)       IDLE=$(echo ${IDLE}+${OTHER} | bc)
Line 977: Line 994:
    DB="Other          "    DB="Other          "
    USAGE=$OTHER    USAGE=$OTHER
 +   USAGE=$(echo "$USAGE" |  sed "s/ \./0\./g")
    echo "$DB $USAGE" >> $TEMPFILE.2    echo "$DB $USAGE" >> $TEMPFILE.2
    DB="Idle"    DB="Idle"
    USAGE=$IDLE    USAGE=$IDLE
 +   USAGE=$(echo "$USAGE" |  sed "s/ \./0\./g")
    echo "$DB $USAGE" >> $TEMPFILE.2    echo "$DB $USAGE" >> $TEMPFILE.2
 fi fi
Line 996: Line 1015:
 rm $CPU_tmp rm $CPU_tmp
 rm $TEMPFILE $TEMPFILE.2 rm $TEMPFILE $TEMPFILE.2
- 
  
 </code> </code>
Line 1055: Line 1073:
   * **2013-04-23**   * **2013-04-23**
     * Updated to handle the case of no databases running. Previously, it just didn't bother doing anything, but now it will report there are no databases, and can trigger a colour change if there are no databases found.     * Updated to handle the case of no databases running. Previously, it just didn't bother doing anything, but now it will report there are no databases, and can trigger a colour change if there are no databases found.
 +  * **2014-02-27**
 +    * Updated to run with Solaris 11.
 +    * If top isn't available, (Solaris 10 and earlier) will use iostat to get idle stats.
 +    * Fixed a few display bugs.
  • monitors/db_cpu.ksh.1393474930.txt.gz
  • Last modified: 2014/02/27 04:22
  • by vernon