customer 发表于 2013-1-28 23:52:19

Solaris环境下性能采集脚本D

#--------------------------------------
#get netif from command line and save it to cpuid.cfg
#--------------------------------------
get_netif()
{
    #delete netif.cfg
    if [ -f ./netif.cfg ]
    then
      rm ./netif.cfg
    fi
   
    #Input from command line
    while [ -n "$1" ]; do
    case $1 in
       -*) break;; # no more netif input
       *) echo $1 >> ./netif.cfg; shift 1;;
    esac
    done
   
    #If not input parameter, collect all netif
    if [ ! -f ./netif.cfg ]
    then
      netstat -i |/usr/xpg4/bin/grep -vE 'loopback|Name' | awk '{print $1}' > ./netif.cfg
    fi

    #get netstat for each netinterface
      while read NETIF
      do
            if [ ! "$NETIF" = "" ]
            then
                debug "add netif: $NETIF"
                echo "collectMan start to get data from : `date '+%m/%d/%y-%H:%M:%S'`" > ./report/temp_netstat_$NETIF.txt
                nohup netstat -i $collect_if -I $NETIF $COLLECT_PERIOD >> ./report/temp_netstat_$NETIF.txt &
            fi
      done < ./netif.cfg

}

#--------------------------------------
#Add a backgroud process to monitor for each daemon
#--------------------------------------
add_process_monitor()
{
    if [ -f ./process.cfg ]
    then
      rm ./process.cfg
    fi
   
    while [ -n "$1" ]#loop for all daemon name input from command line
    do
      
      case $1 in
         -*) return 0;;
         *) debug "daemon name: $1 ";;
      esac

      if [ `ps -ef |grep $1|/usr/xpg4/bin/grep -cvE 'grep|collectMan'` -eq 0 ]   #check if daemon is running
      then
            echo "Process '$1' dose not running." | tee -a collectMan.log
            if [ $COLLECT_NOTRUNNING_DAEMON = "N" ]
            then
                  echo "Can't collect this process, if daemon will startup later and you want collect this information, please set COLLECT_NOTRUNNING_DAEMON to Y."
                  shift 1
                  continue
            fi
      else
            echo "Start to collect '$1' daemon information ..." >> collectMan.log
            
      fi
      
      #Add a backgroud collectMan process for monitor daemon information   
      nohup sh ./collectMan.sh -process_monitor $1 > /dev/null &
      echo $1 >> ./process.cfg;
      shift 1
    done
}

#--------------------------------------
#Add a backgroud process to monitor for server information
#--------------------------------------
add_server_monitor()
{
    if [ $COLLECT_CPU = "N" -o COLLECT_MEMORY = "N" -o COLLECT_IO = "N" -o COLLECT_NET = "N" ]
    then
      echo "If you want get summary report, please use -cpu -diskio -memory -net at same time to collect necessary data." | tee -a collectMan.log
      return 0
    else
      nohup sh ./collectMan.sh -server_summary_report > /dev/null &
    fi
}

#--------------------------------------
#Loop to get process information
#--------------------------------------
process_monitor()
{
    while [ 1 ]
    do
      #check parameter
      if [ $# -ne 1 ]
      then
          echo "Parameter not accord the assert."
          exit 0
      fi
      
      #Create file and input report head      
      if [ ! -f ./report/PS_$1.txt ]
      then
            echo "DATETIME\tSIZE\tRSS\tCPU\tTIME\tNLWP\tPID" > ./report/PS_$1.txt
      fi
      
      #use prstat get process information
      echo "`prstat -n 200 1 1 |grep $1` `date '+%m/%d/%y-%H:%M:%S'`" |awk '{printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",$11,$3,$4,$9,$8,$10,$1}' >> ./report/PS_$1.txt
      
      #zip and separate file
      zipfile ./report/PS_$1.txt

      #wait for next period
      sleep $COLLECT_PERIOD         
    done
}
页: [1]
查看完整版本: Solaris环境下性能采集脚本D