#!/bin/bash red='\E[31;47m' green='\E[32;47m' # Remove "print stack trace" information from the log. remove_debug_information() { logfile=$1 templogfile1="$TMPDIR/webstatussemdebug1.log" templogfile="$TMPDIR/webstatussemdebug.log" cat $logfile | grep -v DEBUG | grep -v "java.lang.Thread.run(Thread.java:534)" > $templogfile1 cat $templogfile1 | awk -F' INFO org.ourgrid.webstatus.WebStatusLogger ===> ' '{print $1" "$2}' # while read line; do # date=$(echo "$line" | awk -F'===>' '{print $1}' | awk '{print $1" "$2}') # info=$(echo "$line" | awk -F'===>' '{print $2}') # echo "$date $info" # done < $templogfile } # Processing the log file looking for information about the # entities: 'Online peers', 'Peer', 'Local GuMs', 'Community # GuMs' and 'Accounting information' process_log_file() { file=$1 entities=("Online peers" "Peer" "Local GuMs" "Community GuMs" "Accounting information") prefix="$TMPDIR/instant-" snapshot=0 while read line do entity=$(echo $line | awk -F '] ' '{print $2}' | awk -F':' '{print $1}') entity_info=$(echo $line | awk -F '] ' '{print $2}' | awk -F': ' '{print $2}') date=$(echo $line | awk '{print $1}') date=${date//\//-} timestamp=$(echo $line | awk '{print $2}') if [ -n "${entity}" ] then case "$entity" in "${entities[0]}") filename="$prefix$date-$timestamp.txt" snapshot=$(($snapshot + 1)) ;; "${entities[1]}") peername=$entity_info echo "[$peername]" >> $filename echo -n "$snapshot--$date--$timestamp--$peername" ;; "${entities[2]}") gums=$entity_info echo "GUMS=$gums" >> $filename numgums=$(echo $gums | awk -F',' '{print NF}') echo -n "--$numgums" ;; "${entities[3]}") communitygums=$entity_info echo "COMMUNITYGUMS=$communitygums" >> $filename #numcommunitygums=$(echo $communitygums | awk -F',' '{print NF}') numcommunitygums=$(echo $communitygums | cut -d"[" -f2 | cut -d"]" -f1 | awk -F',' '{print NF}') echo "--$numcommunitygums" ;; "${entities[4]}") accounting=$entity_info echo "ACCOUNTING=$accounting" >> $filename ;; esac fi done <$file } generate_gnuplot_data_file() { filetobeprocessed=$1 totgums=0 totcommunitygums=0 npeers=0 utilization=0 percentualutilizacao=0 snapshot_base=$(head -n 1 $filetobeprocessed | awk -F'--' '{print $1}') echo "#Date Time TotGuMs TotCommGuMs NumPeers Utilization" while read line do snapshot=$(echo $line | awk -F '--' '{print $1}') date=$(echo $line | awk -F '--' '{print $2}') timestamp=$(echo $line | awk -F '--' '{print $3}') date=`echo $date | awk -F '[' '{print $2}'` timestamp=${timestamp%%]} peername=$(echo $line | awk -F '--' '{print $4}') gums=$(echo $line | awk -F '--' '{print $5}') communitygums=$(echo $line | awk -F '--' '{print $6}') if [ "$snapshot" = "$snapshot_base" ] then totgums=$((totgums + gums)) totcommunitygums=$((totcommunitygums + communitygums)) npeers=$((npeers + 1)) if [ $communitygums -gt 0 ] then utilization=$((utilization + gums)) fi else percentualutilizacao=`expr $utilization \* 100 / $totgums` #percentualutilizacao=$(($temp / $totgums)) echo "$date $timestamp $totgums $totcommunitygums $npeers $utilization $percentualutilizacao" snapshot_base=$((snapshot_base + 1)) totgums=$gums totcommunitygums=$communitygums npeers=0 utilization=0 fi done <$filetobeprocessed # Imprime a ultima linha echo "$date $timestamp $totgums $totcommunitygums $npeers $utilization $percentualutilizacao" } #Main nargs=$# # Se o número de argumentos for diferente de 1, sai. if [ ${nargs} -ne 1 ]; then usage exit 1 fi webstatuslogfile=$1 # Se o arquivo passado não existe if [ ! -e "$webstatuslogfile" ]; then echo "`basename $0`: '$webstatuslogfile' does not exists" exit 1 fi TMPDIR="/tmp/peer-$$/" OUTPUT_STEP1="$TMPDIR/output1.log" OUTPUT_STEP2="$TMPDIR/output2.log" datafile="webstatus.dat" mkdir -p $TMPDIR # remove informação de debug do arquivo de log, gerando o arquivo # $OUTPUT-STEP1 echo "[`date +%T`] Step 1 -> Removing debug information from log $webstatuslogfile..." remove_debug_information $webstatuslogfile >> $OUTPUT_STEP1 # processa o $OUTPUT_STEP1 e gera o output final que será usado # para calcular os gráficos. Gera $OUTPUT_STEP2 echo "[`date +%T`] Step 2 -> Extracting information about 'Online Peers'..." process_log_file $OUTPUT_STEP1 >> $OUTPUT_STEP2 #rm -f $OUTPUT_STEP1 echo "[`date +%T`] Step 3 -> Generating gnuplot data file ($datafile)..." generate_gnuplot_data_file $OUTPUT_STEP2 >> $datafile #rm -f $OUTPUT_STEP2 echo "[`date +%T`] Finished" # Remove the temp directory #rm -rf $TMPDIR