accesslog_parser.pl
资源名称:gateway-1.2.1 [点击查看]
上传用户:gzpyjq
上传日期:2013-01-31
资源大小:1852k
文件大小:3k
源码类别:
手机WAP编程
开发平台:
WINDOWS
- #!/usr/bin/perl
- #
- # accesslog_parser.pl
- #
- # Kalle Marjola for project Kannel, based on stat.pl by
- # 2000-05-12 jarkko@iki.fi
- use strict;
- my (%stat_in, %stat_out);
- my (%userstat_in, %userstat_out);
- my (%dailystat_in, %dailystat_out);
- my (%keywordstat_in);
- my $failed_send = 0;
- my $failed_rout = 0;
- my $rejected = 0;
- my $start = 0;
- my $ends = 0;
- my $line;
- while ($line = <STDIN>) {
- chomp($line);
- # does string begin with date
- if ($line =~ /^(dddd)-(dd)-(dd)s+(dd):dd:dds+(.*)$/) {
- my ($year, $month, $day, $hour, $msg) = ($1, $2, $3, $4, $5);
- my ($sender, $receiver, $keyword) =
- ($msg =~ /[SMSC:[^]]*] [[^:]*:([^]]*)] [[^:]*:([^]]*)] [[^:]*:(w*)/i);
- if ($msg =~ /receive sms/i) {
- $stat_in{$sender}{"$year-$month-$day $hour"}++;
- $userstat_in{$sender}++;
- $dailystat_in{"$year-$month-$day $hour"}++;
- $keywordstat_in{lc($keyword)}{"$year-$month-$day $hour"}++;
- } elsif ($msg =~ /sent sms/i) {
- $stat_out{$receiver}{"$year-$month-$day $hour"}++;
- $userstat_out{$receiver}++;
- $dailystat_out{"$year-$month-$day $hour"}++;
- } elsif ($msg =~ /failed send sms/i) {
- $failed_send++;
- } elsif ($msg =~ /failed routing sms/i) {
- $failed_rout++;
- } elsif ($msg =~ /rejected/i) {
- $rejected++;
- } elsif ($msg =~ /log begins/i) {
- $start++;
- } elsif ($msg =~ /log ends/i) {
- $ends++;
- }
- }
- }
- my $key;
- my $key2;
- # daily/hourly user (phone-number) specific statistics
- print "By phone numbern===============n";
- print "Mobile Originated (from user):n";
- foreach $key (sort keys %stat_in) {
- print "$key:n";
- foreach $key2 (sort keys %{ $stat_in{$key} } ) {
- print "t$key2 = $stat_in{$key}{$key2}n";
- }
- print "ttttTotal: $userstat_in{$key}nn";
- }
- print "Mobile Terminated (to user):n";
- foreach $key (sort keys %stat_out) {
- print "$key:n";
- foreach $key2 (sort keys %{ $stat_out{$key} } ) {
- print "t$key2 = $stat_out{$key}{$key2}n";
- }
- print "ttttTotal: $userstat_out{$key}nn";
- }
- # statistics by keyword
- my $total;
- print "By keywordn==========n";
- print "Mobile Originated (from user):n";
- foreach $key (sort keys %keywordstat_in) {
- print "$key:n";
- $total = 0;
- foreach $key2 (sort keys %{ $keywordstat_in{$key} } ) {
- print "t$key2 = $keywordstat_in{$key}{$key2}n";
- $total += $keywordstat_in{$key}{$key2};
- }
- print "ttttTotal: $totalnn";
- }
- # statistics by hour basic
- my ($total_in, $total_out);
- print "Total usagen===========n";
- print "Mobile Originated (from user):n";
- foreach $key (sort keys %dailystat_in) {
- $total_in += $dailystat_in{$key};
- print "$key = $dailystat_in{$key}n";
- }
- print "ttttTotal: $total_innn";
- print "Mobile Terminated (to user):n";
- foreach $key (sort keys %dailystat_out) {
- $total_out += $dailystat_out{$key};
- print "$key = $dailystat_out{$key}n";
- }
- print "ttttTotal: $total_outnn";
- print "$failed_send failed sendings, $failed_rout failed routing, $rejected rejected messagesn";
- my $ugly = $start - $ends;
- print "$start Kannel start-ups, $ugly crashes/ugly shutdownsn";