#!/usr/bin/perl ################################################## # BiffSocko biff@biffsocko.com # murexparser.pl # # parses murex session logs ################################################## use Time::Local; use Time::localtime; use Sys::Hostname; $USAGE="$0 "; $host = hostname(); ################################# # DEBUG provides additional output # for debugging errors # # DEBUG = 0 : DEBUG OFF # DEBUG = 1 : DEBUG ON ################################# $DEBUG=0; ##################################### # Check command line args ##################################### if($#ARGV ne 0){ print "$USAGE\n"; exit(1); } $FILE=$ARGV[0]; if(! -f $FILE){ print "$FILE does not exist .. exiting\n"; exit(1); } ##################################### # open log file ##################################### if(!(open(Fp, $FILE))){ print "cant open $FILE .. exiting\n"; exit(1); } ##################################### # parse log file ##################################### $counter=0; ################################ #print header ################################ #print "hostname,Process,Status,ElpsedTime,CPU_Time,IO_Time,Start_Time,Finish_Time,CPU_Percent,Rdbcom1,Rdbcom2\n"; $tmp=; # get rid of headers $tmp=; # get rid of headers while(){ if($_ =~m/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/ig){ @line = split(/\|/, $_); $counter++; $date = @line[0]; $date =~ s/^\s+//; # strip off leading whitespace $date =~ s/\s+$//; # strip off trailing whitespace ############################################## # get date into EPOCH time ############################################## $year = substr($date,0,4); $month = substr($date,4,2); $day = substr($date,6,2); $date = "$month/$day/$year"; $month--; print "$counter + 2\n"; print "$_\n"; $date = timelocal(0, 0, 0, $day, $month, $year); $finish_time = @line[1]; $finish_time =~ s/^\s+//; # strip off leading whitespace $finish_time =~ s/\s+$//; # strip off trailing whitespace $user = @line[2]; $user =~ s/^\s+//; # strip off leading whitespace $user =~ s/\s+$//; # strip off trailing whitespace $id = @line[3]; $id =~ s/^\s+//; # strip off leading whitespace $id =~ s/\s+$//; # strip off trailing whitespace $context = @line[4]; $context =~ s/^\s+//; # strip off leading whitespace $context =~ s/\s+$//; # strip off trailing whitespace $command = @line[5]; $command =~ s/^\s+//; # strip off leading whitespace $command =~ s/\s+$//; # strip off trailing whitespace $information = @line[6]; $information =~ s/^\s+//; # strip off leading whitespace $information =~ s/\s+$//; # strip off trailing whitespace $elapsed_1 = @line[7]; $elapsed_1 =~ s/^\s+//; # strip off leading whitespace $elapsed_1 =~ s/\s+$//; # strip off trailing whitespace $cpu_1 = @line[8]; $cpu_1 =~ s/^\s+//; # strip off leading whitespace $cpu_1 =~ s/\s+$//; # strip off trailing whitespace $cpu_per_1 = @line[9]; $cpu_per_1 =~ s/^\s+//; # strip off leading whitespace $cpu_per_1 =~ s/\s+$//; # strip off trailing whitespace $rdbcom_1 = @line[10]; $rdbcom_1 =~ s/^\s+//; # strip off leading whitespac $rdbcom_1 =~ s/\s+$//; # strip off trailing whitespace $rdbc_per_1 = @line[11]; $rdbc_per_1 =~ s/^\s+//; # strip off leading whitespace $rdbc_per_1 =~ s/\s+$//; # strip off trailing whitespace $elapsed_2 = @line[12]; $elapsed_2 =~ s/^\s+//; # strip off leading whitespace $elapsed_2 =~ s/\s+$//; # strip off trailing whitespace $cpu_2 = @line[13]; $cpu_2 =~ s/^\s+//; # strip off leading whitespace $cpu_2 =~ s/\s+$//; # strip off trailing whitespace $cpu_per_2 = @line[14]; $cpu_per_2 =~ s/^\s+//; # strip off leading whitespace $cpu_per_2 =~ s/\s+$//; # strip off trailing whitespace $rdbcom_2 = @line[15]; $rdbcom_2 =~ s/^\s+//; # strip off leading whitespace $rdbcom_2 =~ s/\s+$//; # strip off trailing whitespace $rdbc_per_2 = @line[16]; $rdbc_per_2 =~ s/^\s+//; # strip off leading whitespace $rdbc_per_2 =~ s/\s+$//; # strip off trailing whitespace ############################################## # get rid of the 's' at the end of the elapsed # times ############################################## chop($elapsed_1); chop($elapsed_2); $total_time = $elapsed_1 + $elapsed_2; $finish_time =~m/(.*)(:)(.*)(:)(.*)/ig; $finish_time_hour=$1; $finish_time_minute=$3; $finish_time_seconds=$5; ############################################## # calculate the start and finish times of this # process. ############################################## $finish_time = $date + $finish_time_hour * 60 *60 + $finish_time_minute * 60 + $finish_time_seconds; $finish_time_str = ctime($finish_time); $start_time = $date + $finish_time_hour * 60 *60 + $finish_time_minute * 60 + $finish_time_seconds - $total_time; $start_time_str = ctime($start_time); ############################################## # additional debug statements ############################################## if($DEBUG eq 1){ print " $finish_time|$finish_time_hour|$finish_time_minute|$finish_time_seconds| date - $date year - $year month - $month day - $day start_time - $start_time finish_time - $finish_time user - $user id - $id command - $command cpu - $cpu_1 cpu per - $cpu_per_1 elapssed_1 - $elapsed_1 elapssed_2 - $elapsed_2 total_time = $total_time rdbcom_1 = $rdbcom_1 rdbcom_2 = $rdbcom_2 finish_time_str = $finish_time_str start_time_str = $start_time_str =================================================================\n"; } print "$host,$command,$context,$information,,$elapsed_1,,,$start_time_str,$start_time,$finish_time_str,$finish_time,$cpu_per_1,$rdbcom_1,$rdbcom_2\n"; $host = hostname(); } } exit(0);