/[cricket]/parse_iptraf.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /parse_iptraf.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Mon May 20 17:25:52 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.3: +24 -4 lines
File MIME type: text/plain
added remember offset

1 #!/usr/bin/perl
2
3 # based on work of Eric Wong <eric@taedium.net>
4 # available at http://www.taedium.net/rrd-iptraf/ [iptraf.txt]
5
6 use strict;
7 use warnings;
8
9 my @PORTS = qw (
10 TCP/22 TCP/25 TCP/20 TCP/21 UDP/53
11 TCP/80 TCP/110 TCP/113 TCP/119 UDP/137 UDP/138
12 TCP/210 TCP/443 UDP/514 );
13
14 my $log = '/var/log/iptraf/tcp_udp_services-eth1.log';
15 #my $log = '/home/dpavlin/iptraf/tcp_udp_services-eth1.log';
16
17 $log = $ARGV[0] if ($ARGV[0] && -r $ARGV[0]);
18
19 open(LOG,$log) || die "Can't open logfile '$log': $!";
20
21 my $delta="/var/tmp/";
22 my $tmp_log=$log;
23 $tmp_log=~s/\W/_/g;
24 $delta.=$tmp_log.".offset";
25
26 if (-e $delta) {
27 open(D,$delta) || die "can't open delta file '$delta' for log '$log': $!";
28 my $offset=<D>;
29 chomp $offset;
30 close(D);
31 my $log_size = -s $log;
32 if ($offset <= $log_size) {
33 seek(LOG,$offset,0);
34 }
35 }
36
37 my %hash;
38
39 while (<LOG>) {
40 chomp;
41 last if ( m/^Running/ );
42 next if ( m/^\s*$/ );
43
44 ## read data for tcp packets
45 if (my ($port) = $_ =~ m/^(\w+\/\d+)/) {
46 my ($packs, $bytes, $pack_in, $byte_in, $pack_out, $byte_out) =
47 $_ =~ m/\s(\d+)\s/g;
48
49 $hash{$port} = [$byte_in, $byte_out];
50 }
51 }
52
53 open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
54 print D tell(LOG);
55 close(D);
56
57 close(LOG);
58
59 foreach my $port (@PORTS) {
60 print @{$hash{$port}}[0] || 0,"\n",@{$hash{$port}}[1] || 0,"\n";
61 delete $hash{$port};
62 }
63
64 my ($sum_in,$sum_out) = (0,0);
65
66 foreach my $port (keys %hash) {
67 $sum_in+=@{$hash{$port}}[0];
68 $sum_out+=@{$hash{$port}}[1];
69 }
70 print "$sum_in\n$sum_out\n";

  ViewVC Help
Powered by ViewVC 1.1.26