332362a429169495c0b267b56c0929a3addc08de
[mx01] / klin / from-by-time.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6 my $stat;
7 my $l = 0;
8
9 while(<>) {
10         chomp;
11         my ( $mon, $dd, $time, $host, $daemon, $msg ) = split(/\s+/,$_,6);
12
13         next unless $msg =~ m/from=<([^>]+)>/;
14         my $from = $1;
15
16         my $t = $time;
17         $t =~ s/\d:\d\d$/_/; # group by 10 min
18
19         $stat->{$mon}->{$dd}->{$t}->{$from}++;
20
21         $l++;
22         print STDERR "$l " if $l % 10000 == 0;
23 }
24
25 #warn "# stat = ", dump( $stat );
26
27 foreach my $mon ( sort keys %$stat ) {
28         foreach my $dd ( sort keys %{$stat->{$mon}} ) {
29                 foreach my $t ( sort keys %{ $stat->{$mon}->{$dd} } ) {
30                         my $n = 0;
31                         my $e = $stat->{$mon}->{$dd}->{$t};
32                         foreach my $email ( sort { $e->{$b} <=> $e->{$a} } keys %$e ) {
33                                 if ( $n == 0 ) {
34                                         printf "%3s %2s %5s %d %s\n", $mon, $dd, $t, $e->{$email}, $email;
35                                 } elsif ( $n == 5 ) { # XXX top
36                                         last;
37                                 } else {
38                                         printf "%3s %2s %5s %d %s\n", '', '', '', $e->{$email}, $email;
39                                 }
40                                 $stat->{_from}->{$email} += $e->{$email};
41                                 $n++;
42                         }
43                 }
44         }
45 }
46 #print "_from = ",dump( $stat->{_from} );
47 foreach my $email ( sort { $stat->{_from}->{$b} <=> $stat->{_from}->{$a} } keys %{ $stat->{_from} } ) {
48         printf "%4d %s\n", $stat->{_from}->{$email}, $email;
49 }