Solaris环境下性能采集脚本C


#--------------------------------------
#Show simple usage information
#--------------------------------------
usage()
{
echo "Usage:    sh ./collectMan.sh [-process] processName [-cpu] [-memory] [-diskio] diskName [-net] netif [-summary]"
echo "Example:  sh ./collectMan.sh -q -period 10 -process dataserver IPMSDm DCServer EnpowerDm -cpu -memory -diskio c1t0d0s0 c1t1d0s6 c1t2d0s6 -net -summary"
echo "!!! For simply use, just input 'sh ./collectMan.sh'. This will collect data for all CMF CBB. !!!"
}

#--------------------------------------
#Print an error and exit
#--------------------------------------
error()
{
   echo "$1"
   exit 1
}

#--------------------------------------
#Print debug information
#--------------------------------------
debug()
{
   if [ $COLLECT_DEBUG = "Y" ]
   then
       echo "$1"
   fi
}


#--------------------------------------
#get cpu id from command line and save it to cpuid.cfg
#--------------------------------------
get_cpuid()
{
    #Use iostat to get cpu usage for whole system
    echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_iostat_cpu.txt
    nohup iostat -c $COLLECT_PERIOD >> ./report/temp_iostat_cpu.txt &

    #Use mpstat to get cpu usage for each cpu
    echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_mpstat.txt
    nohup mpstat $COLLECT_PERIOD >> ./report/temp_mpstat.txt &

    if [ -f ./cpuid.cfg ]
    then
        rm ./cpuid.cfg
    fi
   
    while [ -n "$1" ]; do
    case $1 in
       -*) break;; # no more cpuid input
       *) echo $1 >> ./cpuid.cfg; shift 1;;
    esac
    done
}

#--------------------------------------
#Collect memory information
#--------------------------------------
get_memory()
{
    echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_vmstat.txt
    nohup vmstat $COLLECT_PERIOD >> ./report/temp_vmstat.txt &
}

#--------------------------------------
#get disk id from command line and save it to disk.cfg
#--------------------------------------
get_disk()
{
    #use iostat get disk io information
    echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_iostat.txt
    nohup iostat -xpn $COLLECT_PERIOD >> ./report/temp_iostat.txt &

    if [ -f ./disk.cfg ]
    then
        rm ./disk.cfg
    fi
   
    while [ -n "$1" ]; do
    case $1 in
       -*) break;; # no more disk input
       *) echo $1 >> ./disk.cfg; shift 1;;
    esac
    done

    #If not input parameter, get all disk partition in df -k list (but summary report just use first three partition)
    if [ ! -f ./disk.cfg ]
    then
    df -k |grep dsk |awk '{print $1}' > ./temp_disk.cfg
    while read LINE
    do
        basename  $LINE >> ./disk.cfg
       
        done < ./temp_disk.cfg
        rm ./temp_disk.cfg
    fi

    return 0
}

猜你喜欢

转载自customer.iteye.com/blog/658160