#!/bin/bash ################################################## # Author: QAD Inc. (eos@qad.com) # Date: July-08-2010 # # Version: 2 # Version Date: 10-July-2012 # Version Info: Improved Efficiency # # Script to analyse an the Table ReadVST information generated by the tableReadVST monitor # - Created in response to an escalation - # # Please use at own risk. # # Usage # ----- # For usage message run the script without any arguments # ################################################## #useage message if [[ $# -lt 1 ]]; then echo -e " DESCRIPTION This command analyses the output of the tableReadVST monitor It requires one comulsory argument USAGE $0 where: - Compulsory Is the name of the tableReadVST monitor file OUTPUTS: -Processed.csv TABLENAME -Reads to that table between samples -Processed-MostReads.csv Total Reads to each table and % of database reads for that table -Processed-MainTargets.tx List of tables with > 100 million reads " exit fi ############################################### ################## # Set up variables ################## fName=$1 outFile=$fName-Processed.csv mostReadsFile=$fName-Processed-MostReads.csv mainTargets=$fName-Processed-MainTargets.txt ################## # Error checks ... ################## if [ ! -e $fName ]; then echo -e " NOTE - Input file $fName does not exist, exiting " exit fi echo "Step1 - Restructing File" awk 'function getNumReads(oldReads,newReads,tName){if(oldReads>newReads){if(tName=="TotalReads"){readDiff=0;}else{readDiff=newReads}}else{readDiff=(newReads - oldReads)}return readDiff;}{if(($1!="ScriptDuration")&&($1!="SampleTime")&&($1!="SampleComplete")&&($1!="")){tMatchNumber[$1]+=1;if(tMatchNumber[$1]==1){totalReads[$1]=0;oldReads[$1]=$2;}else{newReads[$1]=getNumReads(oldReads[$1],$2,$1);totalReads[$1]+=newReads[$1];oldReads[$1]=$2;tableDetails[$1]=newReads[$1]","tableDetails[$1];}}}END{for(tableNameTotal in totalReads){print tableNameTotal " " totalReads[tableNameTotal];print tableNameTotal " " tableDetails[tableNameTotal] >> "./tableReadDetails_temp";}}' $fName | sort -k2 -nr > ./mostread_temp tableNames=$(more ./mostread_temp | awk 'BEGIN{matchNum=1;}{if($2>50000){if(matchNum==1){a=$1;matchNum+=1;}else{a=a","$1;}}}END{print a;}') echo "Step2 - Extract Table Read Statistics" awk -v myvar=$tableNames 'BEGIN{split(myvar,tName,",");}{tableDetails[$1]=$2;}END{rowNum=1;for (i=1; i0; n--){for (i=1; i ${outFile}_temp # Add TimeStamp more $fName | grep "SampleTime" | awk 'BEGIN{print "Time,";}{split($2,sTime,"-");print sTime[4]":"sTime[5]":"sTime[6]","}' > ./ST_temp sed -ie '$d' ./ST_temp paste ./ST_temp ./${outFile}_temp > ./$outFile sed -i 's/[\t ]//g;/^$/d' ./$outFile sed -i 's/=/ /g' ./$outFile echo "Step3 - Summary of Tables with Most Read" more ./mostread_temp | awk '{if(NR==1){print $1","$2 ",%";}else{print $1","$2 ",=(B"NR"*100)/$B$1";}}' > $mostReadsFile echo "Step4 - Main Targets for Tables with > 100 Million Reads" echo "This File Contains Tables That have > 100 Million Reads" > $mainTargets more $mostReadsFile | awk 'BEGIN{FS=",";}NR>1{if($2>100000000){print $1 " " $2;}else{exit;}}' >> $mainTargets echo -e "-----------------------------------------\n File Created: $outFile\n Import to Excel as a Comma Delimted File\n -----------------------------------------" echo -e "-----------------------------------------\n File Created: $mostReadsFile\n Import to Excel as a Comma Delimted File\n -----------------------------------------" echo -e "-----------------------------------------\n File Created: $mainTargets\n Text File Containing Tables > 100 Million Reads \n -----------------------------------------" # Clean_Up rm ./mostread_temp rm ./tableReadDetails_temp -f rm ./ST_temp -f rm ./${outFile}_temp -f