#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # perf720 src/perf/cmdperft/usr/bin/pmcfg/pmcfg 1.11.1.25 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2009,2014 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)98 1.11.1.17 src/perf/cmdperft/usr/bin/pmcfg/pmcfg, PMAIX, perf71H 8/15/12 09:09:05 ######################################################################### # Purpose: # # pmcfg is configuration script for Performance Management # # # # Functions: # # Usage # # Configure_Environment # # Parse_Inputs # # GetVersion # # ListAllStatsFile # # PrintStatsPath # # envstat # # dustat # # ProcessStat # # cinfo # # copyPMData # # Clean_Data # # CollectAllData # # DoManualTransmission # # main # ######################################################################### LANG=C INPUT_ARG=$* set _NDELAYOPEN=5 Usage() { echo "Usage: pmcfg [-D timestamp| -s | -A | -v ] " echo "-D [YYYYMMDD | 0 ] " echo "-s Prints the absolute path of the pm_stats.send file" echo "-A Lists all the pm_stats files in Data Directory, except pm_stats.send file" echo "-v prints the version" } # This function is to pre-process before the pmcfg performance its action # For example, if pmcfg has to re-transmit PM output, the PM output is in # compressed format, this function will uncompress the PM output, once the # pmcfg re-transmits the PM output, those files again will be compressed. # PMCFG_EXT_CONFIG() { # If argument is passed if [[ $# -ne 0 ]] then PreOrPost=$1 if [[ ${HAS_EXT} -eq 0 && ${#INPUT_ARG} -gt 0 ]] then # Call pmcfg_ext to pre or post process ${PMCFG_EXT} ${PreOrPost} $INPUT_ARG fi fi } Grace_Exit() { Exit_Code=$1 # Do pmcfg_ext post-configuration PMCFG_EXT_CONFIG "-post" exit ${Exit_Code} } Configure_Environment() { # ------------------------------------------------------------ # Get the hostname from uname and append to the data directory # ----------------------------------------------------------- HOSTNAME=`/usr/bin/hostname -s` DATADIR=/var/perf/pm/daily/${HOSTNAME} TODAY=`/usr/bin/date +%Y.%m.%d.%a` PROGRAM=pmcfg LOGFILE=/var/perf/pm/daily/pmcfg.log # -------------------------------------------------------------- # Set the default flags # -------------------------------------------------------------- # If set to 'True', it copies the pm_stats.YYYY.MM.DD.DAY file to pm_stats.send. # Default is 'False' Enable_Data_Transmission=False # If a user wants to transmit the old recording , 'Is_Regeneration_Required' # is set to 'True'. User retransmit the old recording using SMIT Is_Regeneration_Required=False # It is default location to look for the binary recording file from # topasrec Binary_Rec_Location=/var/perf/daily/ # It has the location of the pmconf file. This file contains customer information # and data retention value. PMCONF=/var/perf/pm/config/pmconf # Check if # PMExt is present in pmconf file to identify whether it exists /usr/bin/grep "# PMExt" ${PMCONF} 2>&1 >/dev/null HAS_EXT=$? #It has the location of pmcfg_ext file. This file contains all additional data #collection that need to be done PMCFG_EXT=/var/perf/pm/bin/pmcfg_ext # Print steps for manual transmission Print_Manual=True # Do pmcfg_ext pre-configuration PMCFG_EXT_CONFIG "-pre" } # Parse the input flags and set the appropriate flags Parse_Inputs() { while getopts 'D:sAvPn' flag 2>/dev/null do case ${flag} in D) date=${OPTARG} if [[ -n ${date} ]] then Is_Regeneration_Required=True else echo "Please enter the Date in 'YYYYMMDD' format" Usage Grace_Exit 1 fi ;; s) # Calling PrintStatsPath function PrintStatsPath ;; v) # Call GetVersion function GetVersion ;; A) # Call ListAllStatsFile function ListAllStatsFile ;; P) # Collect Process related statistics and exit # Call ProcessStat function ProcessStat ;; n) # Don't Print Manual Transmission Information Print_Manual=False ;; [?]) # Even if a wrong option is entered, it should print the absolute path # of the pm_stats.send file PrintStatsPath ;; esac done } # GetVersion function is used to print the version of bos.perf.tools # It is invoked if pmcfg is called with '-v' flag GetVersion() { Version=`/usr/bin/lslpp -l bos.perf.tools | /usr/bin/grep bos.perf.tools | /usr/bin/awk '{print $2}' | /usr/bin/head -1` echo "${Version}" Grace_Exit 0 } # ListAllStatsFile lists all the pm_stats file in Data Directory # This function is invoked if pmcfg is called with '-A' flag ListAllStatsFile() { for file in `/usr/bin/ls ${DATADIR:?}/pm_stats.[0-9][0-9]*` do echo $file done Grace_Exit 0 } # Print the absolute path of the pm_stats.send file # 'pmcfg -s' calls this function PrintStatsPath() { if [ ${Enable_Data_Transmission} = "False" ] then echo "PM Data transmission is not enabled" Grace_Exit 1 fi # ESA and HMC looks for pm_stats.send file with /var/adm/perfmgr as the base. HOSTNAME=`/usr/bin/hostname -s` DATADIR=/var/adm/perfmgr/daily/${HOSTNAME} if [[ -f ${DATADIR:?}/pm_stats.send ]] then echo "${DATADIR:?}/pm_stats.send" Grace_Exit 0 else Grace_Exit 1 fi } # ================================================================= # Collect the environment statistics and put it in a temporary file # ================================================================= envstat() { statsfile=`/usr/bin/ls ${DATADIR:?}/pm_stats.${TODAY}` #Start the data collection. Put the starting tag here echo "" >> ${statsfile} 2>&4 date=`/usr/bin/date +%Y-%m-%d` version=`/usr/bin/grep version ${statsfile} 2>&4 | /usr/bin/head -1 | /usr/bin/awk '{print $3}'` echo "$date PMCollectionLevel ${version}" >> ${statsfile} 2>&4 echo "$date oslevel `/usr/bin/oslevel -s`" >> ${statsfile} 2>&4 systemid=`/usr/sbin/lsattr -El sys0 | /usr/bin/grep systemid | /usr/bin/tr -s " "| /usr/bin/cut -d " " -f 2` echo "$date systemid $systemid" >> ${statsfile} 2>&4 cpumodel=`/usr/sbin/lsattr -El sys0 | /usr/bin/grep modelname | /usr/bin/tr -s " "| /usr/bin/cut -d " " -f 2` echo "$date cpumodel $cpumodel" >> ${statsfile} 2>&4 # Get Serial number serial=`/usr/sbin/lscfg -vpl sysplanar0 |/usr/bin/grep -p "System:" |/usr/bin/grep "Machine/Cabinet"` if [[ $? -eq 0 ]]; then serial=${serial##*.} else serial=`/usr/sbin/lscfg -vpl sysplanar0 |/usr/bin/grep -p "System VPD:" |/usr/bin/grep "Machine/Cabinet"` if [[ $? -eq 0 ]]; then serial=${serial##*.} else serial=`/usr/bin/uname -u | /usr/bin/cut -d "," -f 2 | /usr/bin/sed 's/..//'` if [[ $? -ne 0 ]]; then noserial=1 fi fi fi echo "$date Serial Number ${serial}" >>${statsfile} 2>&4 disks=`/usr/sbin/lspv | /usr/bin/wc -l | /usr/bin/tr -s " " ` echo "$date disks $disks" >> ${statsfile} 2>&4 cpus=`/usr/sbin/lsdev -Cc processor 2>&4 | /usr/bin/grep "Available" | /usr/bin/wc -l | /usr/bin/tr -s " "` echo "$date cpus $cpus" >> ${statsfile} 2>&4 cpuspeed=`/usr/sbin/prtconf -s 2>&4 | /usr/bin/cut -d ":" -f 2 |/usr/bin/tr -d " " 2>&4` echo "$date cpuspeed ${cpuspeed}" >> ${statsfile} 2>&4 echo "$date timezone $TZ" >> ${statsfile} 2>&4 echo "$date pagesize `/usr/bin/pagesize`" >> ${statsfile} 2>&4 /usr/sbin/lsps -s 2>&4 | /usr/bin/tail -1 | /usr/bin/awk 'BEGIN{ OFS=" " } { print "'"$date"'","pageswap",$1}' >> ${statsfile} 2>&4 msize=$(( `/usr/sbin/lsattr -El sys0 -a realmem -F value 2>&4` / 1024 )) echo "$date ram ${msize}MB" >> ${statsfile} 2>&4 echo "\n" >> ${statsfile} 2>&4 echo "#date,disk name,disk_location,disk_product" >> ${statsfile} 2>&4 /usr/sbin/lsdev -Cc disk -F 'name,location,description' 2>&4| /usr/bin/awk '{ print "'"$date"'",$0}' >> ${statsfile} 2>&4 echo "\n" >> ${statsfile} 2>&4 echo "#date,adapter name,adapter_location,adapter_product" >> ${statsfile} 2>&4 /usr/sbin/lsdev -Cc adapter -F 'name,location,description' 2>&4 | /usr/bin/awk '{ print "'"$date"'",$0}' >> ${statsfile} 2>&4 echo "\n" >> ${statsfile} 2>&4 echo "#date, pageing space device name,swapdev_pv,swapdev_vg,swapdev_type,swapdev_size,swapdev_used%" >> ${statsfile} 2>&4 /usr/sbin/lsps -a|/usr/bin/tail +2 | /usr/bin/awk 'BEGIN {OFS = ","} { print "'"$date"'" " "$1,$2,$3,$8,$4,$5 }' >> ${statsfile} 2>&4 echo "\n" >> ${statsfile} 2>&4 echo "#lparstat -i output #" >> ${statsfile} 2>&4 /usr/bin/lparstat -i | while read line;do key=`echo $line | /usr/bin/awk 'BEGIN{FS = ":"} {print $1}'` val=`echo $line | /usr/bin/awk 'BEGIN{FS = ":"} {print $2}'` key=`echo $key|/usr/bin/tr -s " " "_" ` val=`echo $val|/usr/bin/tr -d " " ` echo "$date $key $val" >> ${statsfile} 2>&4 done # If Partition_Name is empty( meaning that the machine is standalone), then use the Node Name as Partitions Name Partition_Name=`/usr/bin/awk '/Partition_Name/ {print $3}' ${statsfile} 2>&4` if [[ ${Partition_Name} = "-" ]] then Node_Name=`/usr/bin/awk '/Node_Name/ {print $3}' ${statsfile} 2>&4` if ! ex -c "%s/Partition_Name.*/Partition_Name ${Node_Name}/ :wq" ${statsfile} then echo "Error: Not able to populate the data for Partition_Name" >&4 fi fi /usr/bin/vmstat -v | /usr/bin/grep "pending disk I/Os blocked with no pbuf" | /usr/bin/awk 'BEGIN{ OFS=" " }{ print "'"$date"'","diskio_blk_nopbuf",$1 }' >> ${statsfile} 2>&4 /usr/bin/vmstat -v | /usr/bin/grep "paging space I/Os blocked with no psbuf" | /usr/bin/awk 'BEGIN{ OFS=" " }{ print "'"$date"'","psio_blk_nopsbuf",$1 }' >> ${statsfile} 2>&4 /usr/bin/vmstat -v | /usr/bin/grep "filesystem I/Os blocked with no fsbuf" | /usr/bin/grep -v -e client -e external| /usr/bin/awk 'BEGIN{ OFS=" " }{ print "'"$date"'","fsio_blk_nofsbuf",$1 }' >> ${statsfile} 2>&4 echo "$date `/usr/bin/uptime`" >> ${statsfile} 2>&4 # Done with the data collection. Put the ending tag here echo "" >>${statsfile} } # ============================ # Collects the DU statistics # ============================ dustat() { #set -x statsfile=`/usr/bin/ls ${DATADIR:?}/pm_stats.${TODAY}` # Add the starting tag for dustat echo "" >> ${statsfile:?} # Lets find out the hdisks which are from SAN. # Q. Which is a SAN Disk. # A. A disk which is connected to fscsi* adapter belongs to SAN typeset -A isSAN TMP_DIR=`/usr/lib/instl/libinst_mkworkdir 2>/dev/null` TMP_FILE=${TMP_DIR:?}/__tmpFile #Get the data in a file /usr/sbin/lspath | /usr/bin/tr -s ' ' | /usr/bin/cut -d ' ' -f 2,3 > ${TMP_FILE} while read line do disk=`echo $line|/usr/bin/tr -s ' ' | /usr/bin/cut -d ' ' -f 1` adapter=`echo $line|/usr/bin/tr -s ' '| /usr/bin/cut -d ' ' -f 2` echo $adapter | /usr/bin/grep fscsi >/dev/null 2>&1 if [[ $? -eq 0 ]] then isSAN["$disk"]="Y" else isSAN["$disk"]="N" fi done < ${TMP_FILE} /usr/bin/rm -rf ${TMP_DIR} # lspv output for each disk in lspv # STARTS here #Date:SAN: vg:disk_name:size(MB):available(MB) echo "#Date SAN vg disk_name size(MB) available(MB)" >>${statsfile} 2>&4 for vg in `/usr/sbin/lsvg` do for disk in `/usr/sbin/lsvg -p ${vg} | /usr/bin/tail +3|/usr/bin/awk '{print $1}' 2>&4` do size=`/usr/bin/getconf DISK_SIZE /dev/${disk}` available=`/usr/sbin/lspv ${disk} | /usr/bin/grep "USED PPs" | /usr/bin/awk '{print $4}'| /usr/bin/tr -d "("` echo "${date} ${isSAN[$disk]} ${vg} ${disk} ${size} ${available}" >> ${statsfile} 2>&4 done done # Disks which don't belong to any Volume Group vg=-1 for disk in `/usr/sbin/lspv | /usr/bin/awk '{ if( $3 == "None" ){ print $1}}'` do size=`/usr/bin/getconf DISK_SIZE /dev/${disk}` available=$size echo "${date} ${isSAN[$disk]} ${vg} ${disk} ${size} ${available}" >> ${statsfile} 2>&4 done echo "DONE_LSPV\n" >> ${statsfile} 2>&4 # lspv output ENDS here # File System Data Stats here #Filesys_Name Filesys_Size Filesys_Free Inodes NumInodes NA Directory echo "#Date Filesys_Name Filesys_Size Filesys_Free Inodes NumInodes NA Directory" >> ${statsfile} 2>&4 /usr/bin/df -m |/usr/bin/tail +2|/usr/bin/tr -d "%" | /usr/bin/awk 'BEGIN { OFS = " " } { if( $2 != "-") { numInodes=($5/$4)*100 print "'"${date}"'",$1,$2,$3, numInodes, $5, "-1", $7 } }' >> ${statsfile} 2>&4 echo "DONE_DU\n" >> ${statsfile} 2>&4 # FS data ENDS here #SAN Data format #Command to be used "datapath query esspath" TMP_DIR=`/usr/lib/instl/libinst_mkworkdir 2>/dev/null` TMP_FILE=${TMP_DIR:?}/__tmpFile if [[ -f /usr/sbin/datapath ]] then /usr/sbin/datapath query essmap > ${TMP_FILE} elif [[ -f /usr/bin/pcmpath ]] then /usr/bin/pcmpath query essmap > ${TMP_FILE} fi if [[ -s ${TMP_FILE} ]] then while read line do echo "${date} ${line}" >> ${statsfile} 2>&4 done < ${TMP_FILE} fi #Remove the TMP directory /usr/bin/rm -rf ${TMP_DIR} echo "DONE_SAN\n" >> ${statsfile} 2>&4 # Collect VG Data for vg in `/usr/sbin/lsvg` do /usr/sbin/lsvg ${vg} >/dev/null 2>&1 if [[ $? -eq 0 ]] then total_pp=`/usr/sbin/lsvg ${vg} | /usr/bin/grep "TOTAL PPs" | /usr/bin/awk '{print $7}'| /usr/bin/tr -d "("` used_pp=`/usr/sbin/lsvg ${vg} | /usr/bin/grep "USED PPs" | /usr/bin/awk '{print $6}' | /usr/bin/tr -d "("` echo "${date} ${vg} ${total_pp} ${used_pp}" >> ${statsfile} 2>&4 fi done echo "DONE_VG\n" >> ${statsfile} 2>&4 # Done with the data collection in tmp file # Add the ending tag echo "" >> ${statsfile:?} } #--------------------------------------------------- # This function collects the process related # metrics and stored in pm_process.YYYY.MM.DD.DAY file #---------------------------------------------------- ProcessStat() { # To get the date use the following command # date "+%Y-%m-%m %H:%M:%S" # And use this date for all the processes PsStatsFile="${DATADIR}/pm_process.${TODAY}" date=`/usr/bin/date "+%Y-%m-%d %H:%M:%S"` IntervalTime=0 CpuSeconds=0 /usr/bin/ps -eo "%x %C %t %g %u %P %p %n %z %c"| /usr/bin/tail +2| /usr/bin/grep -v defunct | /usr/bin/awk ' { if($2>0.0) print "'"$date"'" " " $7":"$4":"$5":"$10 " " $2 " " "'"$IntervalTime"'" " " $1 " " $3 " " $6 " " $8 " " $9 }' >> ${PsStatsFile} Grace_Exit 0 } # --------------------------------------- # This function reads the PMCONF file and copies # customer information # --------------------------------------- cinfo() { statsfile=`/usr/bin/ls ${DATADIR:?}/pm_stats.send` echo "" >> ${statsfile} val=`/usr/bin/grep Company_Name_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Company_Name: ${val}" >> ${statsfile} val=`/usr/bin/grep Address_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Address: ${val}" >> ${statsfile} val=`/usr/bin/grep Address1_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Address1: ${val}" >> ${statsfile} val=`/usr/bin/grep City_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "City: ${val}" >> ${statsfile} val=`/usr/bin/grep state_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "State: ${val}" >> ${statsfile} val=`/usr/bin/grep country_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Country: ${val}" >> ${statsfile} val=`/usr/bin/grep countrycode_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Country Code: ${val}" >> ${statsfile} val=`/usr/bin/grep contactperson_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Contact Person Name: ${val}" >> ${statsfile} val=`/usr/bin/grep phone_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Contact Phone Number: ${val}" >> ${statsfile} val=`/usr/bin/grep email_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` echo "Email Address: ${val}" >> ${statsfile} #val=`/usr/bin/grep nlv_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` #echo "National Language version(NLV): ${val}" >> ${statsfile} #val=`/usr/bin/grep codepage_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` #echo "Code Page: ${val}" >> ${statsfile} #val=`/usr/bin/grep calender_PM ${PMCONF} | /usr/bin/cut -d ":" -f 2 2>&4` #echo "calendar type (*GRG, *CHN, *JPN): ${val}" >> ${statsfile} # Get the shift information from PMCONF file and put it in pm_stats.send file # Call GetShiftInfo function GetShiftInfo echo "" >> ${statsfile} } GetShiftInfo() { statsfile=`/usr/bin/ls ${DATADIR:?}/pm_stats.send` echo "#Trending Days " >>${statsfile} TrendingDays=`/usr/bin/grep TrendingDays ${PMCONF}| /usr/bin/cut -d "=" -f2` echo "busdays ${TrendingDays} " >>${statsfile} echo "#Shift Information" >>${statsfile} Shift1Start=`/usr/bin/grep First_Shift_Start ${PMCONF}| /usr/bin/cut -d "=" -f2` Shift1End=`/usr/bin/grep First_Shift_End ${PMCONF}| /usr/bin/cut -d "=" -f2` Shift2Start=`/usr/bin/grep Sec_Shift_Start ${PMCONF}| /usr/bin/cut -d "=" -f2` Shift2End=`/usr/bin/grep Sec_Shift_End ${PMCONF}| /usr/bin/cut -d "=" -f2` echo "shift_1 ${Shift1Start} ${Shift1End}" >>${statsfile} echo "shift_2 ${Shift2Start} ${Shift2End}" >>${statsfile} } # --------------------------------------------- # Takes YYYY.MM.DD.DAY as an arguement # copy pm_stats.YYYY.MM.DD.DAY to pm_stats.send file # --------------------------------------------- copyPMData() { # set -x # Accepts the date as arguement if [ ${Enable_Data_Transmission} = "True" ] then DATE=$* if [[ -f ${DATADIR}/pm_stats.${DATE} ]] then /usr/bin/cp ${DATADIR}/pm_stats.${DATE} ${DATADIR}/pm_stats.send 2>&4 /usr/bin/chmod 644 ${DATADIR}/pm_stats.send else echo "${DATADIR}/pm_stats.${DATE} file not found" >&4 echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi # --------------------------------- # Collect Customer Information # --------------------------------- cinfo fi } # Clean_Data function reads the retention peroid from the PMCONF file # and deletes the old recording files in DATADIR directory Clean_Data() { echo "INSIDE Clean_Data function" >&4 #delete the pm_stats.send file (if exists) /usr/bin/rm ${DATADIR}/pm_stats.send 2>&4 #Reads the retention period from PMCONF file RETAIN=`/usr/bin/grep RETAIN ${PMCONF} | /usr/bin/cut -d ":" -f 2` echo "RETAIN: ${RETAIN}" >&4 /usr/bin/find ${DATADIR} -mtime +${RETAIN} | xargs /usr/bin/rm 2>&4 echo "Exiting Clean_Data function" >&4 } # If 'pmcfg -D 0' is specified, then it collates all the data and # copies it to pm_stats.send file CollectAllData() { #delete the pm_stats.send file (if exists) /usr/bin/rm ${DATADIR}/pm_stats.send 2>&4 statssendfile=${DATADIR}/pm_stats.send #Log the statssendfile echo "Inside CollectAllData" >&4 echo "StatsFile: $statssendfile " >&4 #set -x cd ${DATADIR} Nfiles=`/usr/bin/ls pm_stats.[0-9][0-9]* 2>&4 | /usr/bin/wc -l | /usr/bin/awk '{print $1}'` if [[ ${Nfiles} -eq 0 ]] then echo "There are no recording files." >&4 echo "Data directory is empty" >&4 echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi file=`/usr/bin/ls -rt pm_stats.[0-9][0-9]* 2>&4 | /usr/bin/head -1 ` #Check for the existence of the file if [[ -z $file || ! -f $file ]] then echo "File: $file is not a proper file" >&4 echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi echo "Number of files: ${Nfiles}" >&4 echo "Last file: $file" >&4 # Now Take the PM header and write it to pm_stats.send file startline=`/usr/bin/grep -n "" ${file} 2>&4 | /usr/bin/head -1 | /usr/bin/cut -d ":" -f1 2>&4 ` endline=`/usr/bin/grep -n "" ${file} 2>&4 | /usr/bin/head -1 | /usr/bin/cut -d ":" -f1 2>&4` #The recording file must have tags. If not, the the file is corrupted. if [[ -z $startline || -z $endline ]] then echo "Error: $file is corrupted" echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi ((LinesToRead=endline-startline-1)) ((startline=startline+1)) # Start populating the file echo "" >${DATADIR}/pm_stats.send /usr/bin/tail +$startline $file | /usr/bin/head -$LinesToRead >>${DATADIR}/pm_stats.send echo "" >>${DATADIR}/pm_stats.send #Store all the new sections to process Ext_sections="" if [[ ${HAS_EXT} -eq 0 ]] then Ext_sections=`${PMCFG_EXT} -g` fi for section in vmstat iostat netstat process envstat dustat ${Ext_sections} do echo "<${section}>" >>${DATADIR}/pm_stats.send for file in `/usr/bin/ls -rt pm_stats.[0-9][0-9]* 2>&4` do echo "Info: Reading $file" >&4 startline=`/usr/bin/grep -n "<${section}>" ${file} | /usr/bin/head -1 | /usr/bin/cut -d ":" -f1 2>&4 ` endline=`/usr/bin/grep -n "" ${file} | /usr/bin/head -1 | /usr/bin/cut -d ":" -f1 2>&4` if [[ -z $startline || -z $endline ]] then echo "Warning: <${section}> is missing in ${file}" echo "Warning: Please see the $LOGFILE for details" continue fi ((LinesToRead=endline-startline-1)) ((startline=startline+1)) /usr/bin/tail +$startline $file | /usr/bin/head -$LinesToRead >>${DATADIR}/pm_stats.send EndDate=`/usr/bin/grep "End Date:" ${file} | /usr/bin/cut -d ":" -f2` done echo "" >>${DATADIR}/pm_stats.send done # Modify the EndDate in pm_stats.send file /usr/bin/sed "s/End Date:.*/End Date:${EndDate}/" ${DATADIR}/pm_stats.send > ${DATADIR}/pm_stats.send.tmp /usr/bin/cp ${DATADIR}/pm_stats.send.tmp ${DATADIR}/pm_stats.send /usr/bin/rm ${DATADIR}/pm_stats.send.tmp #Make file permission to 644 /usr/bin/chmod 644 ${DATADIR}/pm_stats.send # Copy the customer's information to the file cinfo # Prints the steps to do a manual transmission of PM Data # Call the DoManualTransmission function DoManualTransmission Grace_Exit 0 } DoManualTransmission() { echo "User has to manually transmit the PM Data file =========================================================================== Steps to do a Manual transmission from Electronic Service Agent on the HMC =========================================================================== 1. Login to HMC 2. Select 'Service Management' 3. Select 'Transmit Service Information' 4. Click the 'Send' button labeled 'To transmit the performance management information immediately, click Send. (the second Send button on the page) 5. Check the Console Events log for results ======================================================================= Steps to do a Manual transmission from Electronic Service Agent for AIX ======================================================================= 1. Login to ESA using web interface (https://hostname:port/esa) 2. Go to 'Service information' 3. Select action 'Collect information' 4. Select the Performance Management checkbox 5. Click OK 6. Check the Activity Log for results" } main() { # ------------------------------------------------- # pmcfg script should not run inside WPAR # ------------------------------------------------- Is_WPAR=`/usr/bin/uname -W` if [[ ${Is_WPAR} -ne 0 ]] then echo "PM Service is not supported inside WPAR" exit 0 fi # ------------------------------------------------- # Configure the envronment # ------------------------------------------------- Configure_Environment # ------------------------------------------------- # Check the data directory. If it is not there, # then create it. This case is seen in machines # which are installed with new build #-------------------------------------------------- if [[ ! -d ${DATADIR} ]] then /usr/bin/mkdir ${DATADIR} /usr/bin/chmod 755 ${DATADIR} fi # --------------------------------------------------------- # Check if Data Transmission is enabled and set the flag. # ---------------------------------------------------------- /usr/bin/grep "# Enabled" ${PMCONF} 2>&1 >/dev/null if [ $? -eq 0 ] then Enable_Data_Transmission=True fi # --------------------------------------------------------- # Do not check authorization if options are -A, -s and -v # To allow any users to execute pmcfg with these options # Else Allow only authorized users to proceed execution # --------------------------------------------------------- if [[ "$*" != "-A" && "$*" != "-s" && "$*" != "-v" ]] then ## Check for RBAC authorization if [[ -f /usr/ios/cli/ioscli ]] then # If its vios, check for vios authorization /usr/bin/ckauth vios.system.perfmgr.config rc=$? if [[ $rc -ne 0 ]]; then Grace_Exit 1 fi else # If its aix, check for aix authorization /usr/bin/ckauth aix.system.perfmgr.config rc=$? if [[ $rc -ne 0 ]]; then Grace_Exit 1 fi fi fi # ------------------------------------------------- # Parse the input and set the appropriate variables # ------------------------------------------------- Parse_Inputs $* # -------------------------------------------------------------- # Open the File Descriptor for log file # Error messages (if any) will be logged to log file. # Important Debug information will also be printed to this file # For Example: # #exec 4>log # #lspv hdisk1 2>&4 - It dumps the error message to log file # -------------------------------------------------------------- exec 4>${LOGFILE} # ------------------------------------------------- # Check if topas recording is running # ------------------------------------------------- /usr/bin/listtrec -P -l local_bin 2>&1 >/dev/null if [[ $? -ne 0 ]] then echo "Topas Recording is not running." >&4 echo "Please start topas recording going to smit topas." >&4 Grace_Exit 0 fi # ---------------------------------------------- # Clean the Data directory based on RETAIN Value # ---------------------------------------------- Clean_Data # ------------------------------------------------------- # Based on the input paramters, call appropriate functions # -------------------------------------------------------- if [[ ${Is_Regeneration_Required} = "False" ]] then host=`/usr/bin/hostname -s` year=`echo ${TODAY}| /usr/bin/cut -c 3,4` month=`echo ${TODAY}| /usr/bin/cut -c 6,7` day=`echo ${TODAY}| /usr/bin/cut -c 9,10` rec_file=${host}_${year}${month}${day}.topas # --------------------------------------------------------- # Get the recording file location using listtrec command # --------------------------------------------------------- #Binary_Rec_Location=`/usr/bin/ps -eaf|/usr/bin/grep "topasrec -L" |/usr/bin/grep "ypersistent=1" | /usr/bin/awk 'BEGIN { FS="-o" } { print $2}' | /usr/bin/awk '{print $1}' 2>&4` #Binary_Rec_Location=`/usr/bin/listtrec -l local_bin -P | /usr/bin/tail +2 | /usr/bin/awk '{ print $5 }' | /usr/bin/head -1 | /usr/bin/tr -d \*#` procid=`/usr/bin/listtrec -P -l local_bin | /usr/bin/grep perf | /usr/bin/cut -f1 -d" "` Binary_Rec_Location=$(echo `/usr/bin/listtrec -l local_bin | /usr/bin/grep $procid` | /usr/bin/cut -f5 -d" " | /usr/bin/cut -c2-) Binary_Rec_Location=${Binary_Rec_Location:-"/var/perf/daily/"} #Check if the location has a Slash('/') at the end echo ${Binary_Rec_Location} | /usr/bin/grep ".*/$" >&4 2>&4 if [[ $? -ne 0 ]] then host=`/usr/bin/basename ${Binary_Rec_Location} 2>&4` rec_file=${host}_${year}${month}${day}.topas Binary_Rec_Location=`/usr/bin/dirname ${Binary_Rec_Location} 2>&4` fi echo "${Binary_Rec_Location}/${rec_file}" >&4 /usr/bin/topasout -P ${Binary_Rec_Location}/${rec_file} 2>&4 if [[ $? -ne 0 ]] then echo "Error: /usr/bin/topasout failed to generate the recording file." >&4 echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi # --------------------------------- # Change the filename stats. to pmstats. file # --------------------------------- /usr/bin/mv "${DATADIR:?}/stats.${TODAY}" "${DATADIR:?}/pm_stats.${TODAY}" # --------------------------------- # Append Process Data to Statsfile # --------------------------------- PsStatsFile="${DATADIR:?}/pm_process.${TODAY}" statsfile="${DATADIR:?}/pm_stats.${TODAY}" echo "" >> ${statsfile} echo "#DATE TIME, PID:RGROUP:RUSER:COMMAND, %CPU, INTERVALTIME, CPUSECONDS, TOTALELAPSEDTIME, PPID, NI, VSZ " >> ${statsfile} /usr/bin/cat ${PsStatsFile} >> ${statsfile} 2>&4 echo "" >> ${statsfile} # --------------------------------- # Collect envstat data # --------------------------------- envstat # --------------------------------- # Collect dustat data # --------------------------------- dustat if [[ ${HAS_EXT} -eq 0 ]] then ${PMCFG_EXT} fi copyPMData ${TODAY} fi # The following code is used only when the customer wants to send data for previous date/day if [[ ${Is_Regeneration_Required} = "True" ]] then if [[ ${Enable_Data_Transmission} = "False" ]] then echo "PM data transmission is not enabled." Grace_Exit 1 fi #set -x # Check the length of the Date entered if [[ ${date} -ne 0 && ${#date} -ne 8 ]] then echo "Error: Wrong Date entered" Usage Grace_Exit 1 fi if [[ ${date} -eq 0 ]] then CollectAllData else #Convert the YYYYMMDD to YYYY.MM.DD year=`echo ${date} | /usr/bin/cut -c 1-4` month=`echo ${date} | /usr/bin/cut -c 5,6` day=`echo ${date} | /usr/bin/cut -c 7,8` date=${year}.${month}.${day} # Now search for the pm_stats file /usr/bin/ls ${DATADIR}/pm_stats.${date}* > /dev/null 2>&1 if [[ $? -ne 0 ]] then echo "Error: Wrong Date entered" >&4 echo "Error: ${DATADIR}/pm_stats.${date}* file not found" >&4 Usage echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi statsfile=`/usr/bin/ls ${DATADIR}/pm_stats.${date}*` # Copy the pm_stats file to pm_stats.send /usr/bin/cp ${statsfile} ${DATADIR}/pm_stats.send 2>&4 if [[ $? -ne 0 ]] then echo "Error: Copy Failed" >&4 echo "Error: Please see the ${LOGFILE} for details" Grace_Exit 1 fi # Make file permission to 644 /usr/bin/chmod 644 ${DATADIR}/pm_stats.send # --------------------------------- # Collect Customer Information # --------------------------------- cinfo #Call DoManualTransmission function # It lists the steps to do a manual transmission of PM Data if [[ ${Print_Manual} = "True" ]] then DoManualTransmission fi Grace_Exit 0 fi fi } main $INPUT_ARG Grace_Exit 0