#!/usr/bin/perl # # Program: POP3 Statistics # # Author: Matty < matty91 at gmail dot com > # # Current Version: 1.0 # # Revision History: # # Version 1.0 # Original release # # Last Updated: 12-14-1998 # # Tested with: Qpopper 2.53 logfiles # # Usage: popstats.pl [ LOGFILE ] # LOGFILE can be specified on the command line such as # popstats.pl some_log or you can modify the DEFAULT_POPPER_LOGFILE # variable to specify it. # # Purpose: # This program processes the popper logfiles. It generates the following # Stats based on information extracted from the logs: # Connections # Messages Read # Bytes Read # Timeouts # Lockfiles # Bytes Per Connection # Messages Per Connection # Average Message Size # # popstats also produces a count of X users with bad passwords, lockfile busy messages, # messages read, bytes read, and top ppl to connect and successfully # login to our pop3 server. # # Example: # $ postats.pl # Report for Sun Jul 25 02:02:39 EDT 1999 # # ============ HOSTNAME POP3 Stat's ============ # Overall: # Connections: 12427 # Messages Read: 6345 # Bytes Read: 89841731 # Timeouts: 27 # Lockfiles: 24 # # Averages: # Bytes Per Connection: 7229.6 # Messages Per Connection: 0.5 # Average Message Size: 14159.5 # # ====== Users Receiving Lockfile Busy Errors ====== # =============================== # Username Lockfiles Encountered # =============================== # tom 16 # # ====== Users with Bad Passwords ===== # ============================================ # Username Failures # ============================================ # tom 409 # betty 13 # herman 13 # # ====== Top 30 users to Connect ========= # ======================== # Username Connections # ======================== # herman 2091 # betty 1091 # tom 381 # # ====== Top 30 users in terms of Bytes Trasmitted ====== # ==================== # Username Bytes # ==================== # betty 7982630 # tom 5715565 # herman 636378 # # ====== Top 30 users in terms of Messages Read ====== # ==================== # Username Messages # ==================== # tom 297 # betty 271 # herman 193 ################## # GLOBAL DEFINES # ################## $DEFAULT_POPPER_LOGFILE = '/var/log/popper'; # Default logfile to use $COUNT = 30; # Number of reports we want printed $SERVERNAME = 'myserver'; # Name of the server to be processed ##################################### # NO NEED TO MODIFY BELOW THIS LINE # ##################################### if ( @ARGV == 0 ) { $POPFILE = $DEFAULT_POPPER_LOGFILE; } elsif ( @ARGV == 1 ) { $POPFILE = @ARGV[0]; } else { print "Useage: $0 [LOGFILE]\n"; die 0; } ################## # OPEN THE FILES # ################## open(INPUT,"<$POPFILE") || die "Cannot open $POPFILE\n"; while ( $line = ) { chop($line); if ( $line =~ /-ERR/g ) { # # Logfile Format For Stats line: # arr[6] -- USERNAME # arr[7] -- MESSAGES DELETED # arr[8] -- BYTES DELETED # arr[9] -- MESSAGES LEFT ON SERVER # arr[10]-- BYTES LEFT ON SERVER # @arr = split(/\s+/,$line); if ( $line =~ /timeout/g ) { $timeouts++; } elsif ( $line =~ /Password/g && $line =~ /incorrect/g) { $arr[10] =~ s/"/ /g; $bad_pass{@arr[10]}++; } elsif ( $line =~ /lock/g && $line =~ /busy/g) { $lockfile++; $arr[5] =~ m/(.*)\@/; $lock_busy{$1}++; } } elsif ( $line =~ /Stats:/g ) { @arr = split(/\s+/,$line); $connections++; $total_messages_read += @arr[7]; $total_bytes_read += @arr[8]; ########################### # GET PER USER STATISTICS # ########################### $user_arr{@arr[6]}++; $user_bytes{@arr[6]} += @arr[8]; $user_messages{@arr[6]} += @arr[7]; if ( @arr[11] > 0 ) { $user_los_messg{@arr[6]} += @arr[9]; $user_los_bytes{@arr[6]} += @arr[10]; } } } ############################################################## # CALCULATE SOME AVERAGES AND MAKE SURE THE DIVIDEND IS NOT 0# ############################################################## if ( $connections == 0 ) { $bytes_per_connection = 0; $messages_per_connection = 0; } else { $bytes_per_connection = $total_bytes_read / $connections; $messages_per_connection = $total_messages_read / $connections; } if ( $total_messages_read == 0 ) { $average_message_size = 0; } else { $average_message_size = $total_bytes_read / $total_messages_read; } print "============ $SERVERNAME POP3 Stat's ============\n"; print "Overall:\n"; print " Connections: $connections\n"; print " Messages Read: $total_messages_read\n"; print " Bytes Read: $total_bytes_read\n"; print " Timeouts: $timeouts\n"; print " Lockfiles: $lockfile\n\n"; print "Averages:\n"; printf " Bytes Per Connection: %8.1f\n", $bytes_per_connection; printf " Messages Per Connection: %8.1f\n", $messages_per_connection; printf " Average Message Size: %8.1f\n\n", $average_message_size; ############################################## # PRINT THE USERS WITH LOCK BUSY LOG ENTRIES # ############################################## @array = sort { $lock_busy{$a} < $lock_busy{$b} } keys %lock_busy; print (" ====== Users Receiving Lockfile Busy Errors ======\n"); print (" ===============================\n"); print (" Username Lockfiles Encountered\n"); print (" ===============================\n"); for ( $i = 0; ( $i < $COUNT) && ( $i < @array); $i++ ) { printf(" %-10s",$array[$i]); printf(" %4d\n",$lock_busy{$array[$i]}); } ########################### # DEAL WITH BAD PASSWORDS # ########################### @array = sort { $bad_pass{$a} < $bad_pass{$b} } keys %bad_pass; print ("\n ====== Users with Bad Passwords =====\n"); print (" ============================================\n"); print (" Username Failures \n"); print (" ============================================\n"); for ( $i = 0;( $i < $COUNT) && ( $i < @array); $i++) { printf(" %-30s",$array[$i]); printf(" %4d\n",$bad_pass{$array[$i]}); # printf("$array[$i] $bad_pass{$array[$i]}\n"); } ################################################### # USERS THAT CONNECT AND LOGIN TO THE POP3 SERVER # ################################################### @array = sort { $user_arr{$a} < $user_arr{$b} } keys %user_arr; print ("\n ====== Top $COUNT users to Connect =========\n"); print (" ========================\n"); print (" Username Connections \n"); print (" ========================\n"); for ( $i = 0 ;($i < $COUNT) && ( $i < @array); $i++) { printf(" %-10s",$array[$i]); printf(" %4d\n",$user_arr{$array[$i]}); # printf("$array[$i] $user_arr{$array[$i]}\n"); } ################################################# # PRINT THE USERS BY NUMBER OF BYTES TRASMITTED # ################################################# @array = sort { $user_bytes{$a} < $user_bytes{$b} } keys %user_bytes; print ("\n ====== Top $COUNT users in terms of Bytes Transmitted ======\n"); print (" ====================\n"); print (" Username Bytes \n"); print (" ====================\n"); for ( $i = 0; ($i < $COUNT) && ( $i < @array); $i++ ) { printf(" %-10s",$array[$i]); printf(" %8d\n",$user_bytes{$array[$i]}); # printf("$array[$i] $user_bytes{$array[$i]}\n"); } ############################################## # PRINT THE USERS BY NUMBER OF MESSAGES READ # ############################################## @array = sort { $user_messages{$a} < $user_messages{$b} } keys %user_messages; print ("\n ====== Top $COUNT users in terms of Messages Read ======\n"); print (" ====================\n"); print (" Username Messages\n"); print (" ====================\n"); for ( $i = 0; ($i < $COUNT) && ( $i < @array); $i++ ) { printf(" %-10s",$array[$i]); printf(" %4d\n",$user_messages{$array[$i]}); # printf("$array[$i] $user_messages{$array[$i]}\n"); }