#!/usr/bin/ksh ############################################################################### # # Module: hp_busy_disk1.sh # Author: Peter R. Schmidt # Description: Which disks are the most busy ? # # Change Log # # Date Name Description................. # 02/25/00 Peter R. Schmidt Start Program # 07/28/00 Peter R. Schmidt Account for unused/unallocated # logical volumes # ############################################################################### SLEEP_TIME=10 TMP1=busy_disk_tmp1.tmp TMP2=busy_disk_tmp2.tmp VG_FILE=busy_disk_vg.tmp LV_FILE=busy_disk_lv.tmp DEV_FILE=busy_disk_dev.tmp CHUNK_FILE=busy_disk_chunks.tmp LINK_FILE=busy_disk_links.tmp UNIXFS_FILE=busy_disk_unixfs.tmp REPEAT=N PAUSE=N HELP=N USE_EXISTING=U for ARG do case "$ARG" in -r) REPEAT=Y;; -p) PAUSE=Y;; -h) HELP=Y;; -y) USE_EXISTING=Y;; -n) USE_EXISTING=N;; esac done if [ $HELP = Y ] then echo "Usage: hp_busy_disk1.sh [ -r (REPEAT) ] [ -y (USE EXISTING) ] " exit fi MACHINE=`uname -n` ################################################################################ get_informix_links () { rm -f $CHUNK_FILE rm -f $LINK_FILE rm -f $UNIXFS_FILE echo "Collecting dbs/chunk info from the sysmaster database..." dbaccess << EOF database sysmaster; unload to '$CHUNK_FILE' delimiter " " select --syschktab.dbsnum, --syschktab.chknum, --syschktab.chksize, --syschktab.nfree, --(chksize - nfree) nused, --syschktab.flags, syschktab.fname, sysdbstab.name from syschktab, sysdbstab where syschktab.dbsnum = sysdbstab.dbsnum and sysdbstab.name <> "sysmaster" order by 1,2 EOF echo "Getting Unix links..." while read CHUNK DBSPACE do LINK=`ls -l $CHUNK | cut -d">" -f2 | awk '{print $1}' | sed -e 's/rlvol/lvol/g'` echo "$LINK|$CHUNK|$DBSPACE|" >> $LINK_FILE done < $CHUNK_FILE echo "Getting Unix Filesystems..." bdf > $UNIXFS_FILE while read filesystem kbytes used avail used mountpoint do echo "$filesystem|$mountpoint||" >> $LINK_FILE done < $UNIXFS_FILE } ################################################################################ get_disk_devices () { rm -f $TMP1 rm -f $VG_FILE rm -f $LV_FILE rm -f $DEV_FILE echo "Gathering volume groups..." vgdisplay -v | awk ' /VG Name/ { n=split ($3,a,"/") vg1=a[n]; vg2=$3; printf "vg|%s|%s|\n",vg1,vg2; } /LV Name/ { n=split ($3,a,"/") lv1=a[n]; lv2=$3; printf "lv|%s|%s|%s|%s|\n",vg1,vg2,lv1,lv2; } ' > $VG_FILE echo "Gathering logical volumes..." for LV in `grep "^lv|" $VG_FILE | cut -d"|" -f5 | sort` do echo "Checking Logical Volume $LV" lvdisplay -v $LV > $TMP1 LV2=`echo $LV | cut -d"/" -f4` FOUND=`grep -c "Distribution of logical volume" $TMP1` if [ $FOUND -ge 1 ] then START=`grep -n "Distribution of logical volume" $TMP1 | cut -d":" -f1` START=`expr $START + 2` #echo $START else echo "Error: Can't find string 'Distribution of logical volume in output of lvdisplay -v" exit 1 fi FOUND=`grep -c "Logical extents" $TMP1` if [ $FOUND -ge 1 ] then END=`grep -n "Logical extents" $TMP1 | cut -d":" -f1` #echo $END else echo "Error: Can't find string '--- Distribution of logical volume ---' in output of lvdisplay -v" exit 1 fi if [ $END -gt $START ] then LENGTH=`expr $END - $START` #echo $LENGTH else echo "Error: starting position is not before the ending position." exit 1 fi for DEVICE in `tail +$START $TMP1 | head -$LENGTH | cut -d"/" -f4 | cut -d" " -f1` do echo "$DEVICE|$LV2|$LV|" >> $DEV_FILE done done } ################################################################################ # MAIN ################################################################################ . /elite/custom/run.elite if [ -f $DEV_FILE ] then if [ $USE_EXISTING = Y ] then answer=y echo "Note: using existing devices info." else while true do echo "Use existing devices info ? (y/n)" read answer case $answer in Y|y|N|n) break;; esac done fi else answer=n fi if [ $answer = n -o $answer = N ] then get_disk_devices fi ################################################################################ if [ -f $CHUNK_FILE ] then if [ $USE_EXISTING = Y ] then answer=y echo "Note: using existing informix info." else while true do echo "Use existing Informix chunk info ? (y/n)" read answer case $answer in Y|y|N|n) break;; esac done fi else answer=n fi if [ $answer = n -o $answer = N ] then get_informix_links fi ################################################################################ while true do XDATE=`date +%D-%T` rm -f $TMP1 rm -f $TMP2 echo "Getting sar statistics..." sar -d 1 1 | egrep -v "^HP-UX|device" | cut -c 12-99 | sort -r -n +1 > $TMP1 if [ ! -s $TMP1 ]; then echo "No disk activity - try again..." sleep $SLEEP_TIME continue fi echo "Joining disks with chunks and logical volumes..." while read device busy avque rws blks avwait avserv do if [ "x$device" = "x" ] then continue # Blank Line fi for LVOL1 in `egrep "^$device\|" $DEV_FILE` do LVOL2=`echo $LVOL1 | cut -d "|" -f3` CHUNK=`egrep "^$LVOL2\|" $LINK_FILE | cut -d"|" -f2` DBSPACE=`egrep "^$LVOL2\|" $LINK_FILE | cut -d"|" -f3` if [ "${CHUNK}x" = "x" ] then CHUNK="* unused LVOL" fi echo "$device|$busy|$LVOL2|$CHUNK|$DBSPACE" >> $TMP2 done done < $TMP1 if [ ! -s $TMP2 ]; then echo "No disk activity - try again..." sleep $SLEEP_TIME continue fi echo "Formatting report..." echo "________________________________________________________________________________" echo awk ' \ BEGIN { FS="|" PREVIOUS="" } { if (NR == 1) { split (xdate,b,"-") udate=b[1] utime=b[2] printf "%s %s Which disks are the most busy for %s@%s\n",udate,utime,server,machine printf "\n" printf " Percent \n" printf "Device Busy Logical Volume Chunk/Unix-FS DBspace\n" } } { if ($1 == PREVIOUS) { printf "%-8s %-6s %-20s %-15s %-15s\n","","",$3,$4,$5 } else { printf "\n" printf "%-8s %6.2f %-20s %-15s %-15s\n",$1,$2,$3,$4,$5 } PREVIOUS=$1 } ' xdate=$XDATE server=$INFORMIXSERVER machine=$MACHINE < $TMP2 | head -20 if [ $REPEAT = Y ] then echo echo "________________________________________________________________________________" echo if [ $PAUSE = Y ] then echo "Press to repeat, Q to Quit." read answer case $answer in q|Q) exit;; esac else sleep $SLEEP_TIME continue fi else exit fi done ################################################################################