#!/bin/bash # Variáveis Globais ERR_LOGFILE_NOT_FOUND=128 # Funções # # filter -> recebe como argumento # filter() { LOGTOBEFILTERED=$1 LOGALL="$TMPDIR/logall.log" NUMBEREDLOG="$TMPDIR/peerlogfullnumbered.log" RESULTNOT="$TMPDIR/resultnot.log" RESULTUP="$TMPDIR/resultup.log" RESULTDOWN="$TMPDIR/resultdown.log" RESULTNEED="$TMPDIR/resultneed.log" RESULTPEERUP="$TMPDIR/resultpeerup.log" RESULTPEERDOWN="$TMPDIR/resultpeerdown.log" RESULTCOMMGUMIN="$TMPDIR/resultcommunitygum_in.log" RESULTCOMMGUMOUT="$TMPDIR/resultcommunitygum_out.log" RESULT="$TMPDIR/result.log" FILTEREDLOG="$TMPDIR/filtered.log" # Adicionando número de linhas ao arquivo cat -n $LOGTOBEFILTERED > $NUMBEREDLOG # Extraindo eventos relevantes do arquivo cat $NUMBEREDLOG | grep not\ connect | grep UAServerConnector.getUserAgentServer | awk '{print $1" "$2" "$3" "$13" not connected" }' > $RESULTNOT cat $NUMBEREDLOG | grep set\ up | awk '{print $1" "$2" "$3" "$8" up"}' > $RESULTUP cat $NUMBEREDLOG | grep set\ down | awk '{print $1" "$2" "$3" "$8" down"}' > $RESULTDOWN cat $NUMBEREDLOG | grep CommunityObtainer.wannaGuMs | grep Local\ Peer\ needs | awk '{print $1" "$2" "$3" Peer needs "$10}' > $RESULTNEED cat $NUMBEREDLOG | grep ourgrid.peer.main.Main.main | grep Starting\ doctor\ engine | awk '{print $1" "$2" "$3" Peer started!"}' >> $RESULTPEERUP cat $NUMBEREDLOG | grep ourgrid.peer.main.Main.main | grep Starting\ doctor\ engine | awk '{print $1}' >> $RESULTPEERDOWN cat $NUMBEREDLOG | grep org.ourgrid.peer.communityobtainer.CommunityObtainer.hereIsOurGuM | awk '{print $1" "$2" "$3" "$11" Community GuM IN"}' >> $RESULTCOMMGUMIN cat $NUMBEREDLOG | grep org.ourgrid.peer.communityobtainer.CommunityObtainerFacade.disposeOf | awk '{print $1" "$2" "$3" "$9" Community GuM OUT"}' >> $RESULTCOMMGUMOUT for i in $( cat $RESULTPEERDOWN ); do POS=`expr $i - 1` if [ "$POS" != "0" ]; then cat $NUMBEREDLOG | sed -n ''$POS'p' | awk '{print $1" "$2" "$3" Peer down!"}' >> $LOGALL fi done sort -m $RESULTDOWN $RESULTUP $RESULTNOT $RESULTNEED $RESULTPEERUP $RESULTCOMMGUMIN $RESULTCOMMGUMOUT >> $LOGALL sort -n $LOGALL > $RESULT cat $RESULT | awk '{print $2" "$3" "$4" "$5" "$6" "$7}' > $FILTEREDLOG tail -n 1 $NUMBEREDLOG | awk '{print $2" "$3" Peer Down!"}' >> $FILTEREDLOG } find_log_files() { SRCDIR=$1 PEERFILENAME="Peer*.log" LOGFILES="$TMPDIR/peerlogs.log" # Localiza todos os arquivos - a partir de SRCDIR - cujo nome # começa com "Peer" e terminam com ".log" find $SRCDIR -name $PEERFILENAME > $LOGFILES # testa se o arquivo existe e é vazio if [ ! -s $LOGFILES ]; then echo "$(basename $0): Peer log files don't exist in '$SRCDIR' directory" exit $ERR_LOGFILES_NOT_FOUND else echo "Using the following files..." cat $LOGFILES fi } create_full_log() { LOGFILES=$1 FULLLOG="$TMPDIR/peerfulllog.log" for i in $( cat $LOGFILES ); do cat $i >> $FULLLOG done } generate_events_by_entities() { FILTEREDLOG=$1 WORKLOADDIR="$TMPDIR/workload" mkdir -p $WORKLOADDIR while read line do id=$(echo $line | awk '{print $3}') echo $line >> $WORKLOADDIR/$id.log done < $FILTEREDLOG } workload() { STATISTICSFILE="$TMPDIR/peerstatistics.log" PEERLOGFILE=Peer.log WORKLOADDIR="$TMPDIR/workload" mkdir -p $WORKLOADDIR echo "Starting workload" echo -n "Generating Peer statistics..." cat $WORKLOADDIR/$PEERLOGFILE > $STATISTICSFILE echo "done" echo "Generating GuMs statistics..." for i in $(ls $WORKLOADDIR | grep -v $PEERLOGFILE) do echo -n "Using $i..." cat $WORKLOADDIR/$i >> $STATISTICSFILE echo "done" done echo echo "done" } remove_not_connected_events() { tmpfile=$1 cat $1 | grep -v "not connected" } create_event_files() { FILE=$1 INSTANTDIR="$TMPDIR/instant" mkdir -p $INSTANTDIR while read line do id=$(echo $line | awk -F '[' '{print $2}' | awk -F':' '{print $1}') id=${id//\//-} echo $line >> "$INSTANTDIR/$id.log" done < $FILE } # Main # # Este script é invocado com 1 argumento opcional # clear red='\E[31;47m' green='\E[32;47m' nargs=$# TMPDIR="/tmp/peer-$$" # Cria um diretório temporário onde os logs serão armazenados mkdir -p $TMPDIR # Testa o número de argumentos e descobre a partir de onde vai # procurar os arquivos de log. if [ ${nargs} -eq 0 ] then SRCDIR=. else if [ ${nargs} -eq 1 ] then SRCDIR=$1 else usage fi fi FINALFILE="finalstatistics.log" THISLOGFILE="workload.log" echo "[`date +%x" "%T`] Step 1 -> Initializing Workload... $SRCDIR" echo "[`date +%x" "%T`] Step 1 -> Initializing Workload... $SRCDIR" >> $THISLOGFILE # Seta o valor da variavel $LOGFILES find_log_files $SRCDIR echo "[`date +%x" "%T`] Step 2 -> Creating a single log file to be processed... $SRCDIR" echo "[`date +%x" "%T`] Step 2 -> Creating a single log file to be processed... $SRCDIR" >> $THISLOGFILE # Cria um unico arquivo de log concatenado todos os logs listados # em LOGFILES create_full_log $LOGFILES echo "[`date +%x" "%T`] Step 3 -> Filtering the log file... $SRCDIR" echo "[`date +%x" "%T`] Step 3 -> Filtering the log file... $SRCDIR" >> $THISLOGFILE # Filtra o arquivo gerado acima ($FULLLOG), gerando um arquivo # menor ($FILTEREDLOG) filter $FULLLOG # Gera um arquivo por maquina em '$WORKLOAD' dir contendo todos os eventos de cada # uma. echo "[`date +%x" "%T`] Step 4 -> Generating Events by Entities... $SRCDIR" echo "[`date +%x" "%T`] Step 4 -> Generating Events by Entities... $SRCDIR" >> $THISLOGFILE generate_events_by_entities $FILTEREDLOG # Gera o workload do peer e mostra na tela echo "[`date +%x" "%T`] Step 5 -> Generating peer workload... $SRCDIR" echo "[`date +%x" "%T`] Step 5 -> Generating peer workload... $SRCDIR" >> $THISLOGFILE workload echo "[`date +%x" "%T`] Step 6 -> Removing not connected events $SRCDIR" echo "[`date +%x" "%T`] Step 6 -> Removing not connected events $SRCDIR" >> $THISLOGFILE remove_not_connected_events $STATISTICSFILE > $FINALFILE echo "[`date +%x" "%T`] Step 7 -> Create snapshot files $SRCDIR" echo "[`date +%x" "%T`] Step 7 -> Create snapshot files $SRCDIR" >> $THISLOGFILE create_event_files $FINALFILE # remove todos os arquivos temporários gerados para o # processamento dos logs. #rm -rf $TMPDIR echo "[`date +%x" "%T`] Finished $SRCDIR" echo "[`date +%x" "%T`] Finished $SRCDIR" >> $THISLOGFILE