/[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.1 - (show annotations)
Mon May 20 16:00:03 2002 UTC (21 years, 11 months ago) by dpavlin
Branch: MAIN
File MIME type: text/plain
parse iptraf log file (be sure to set interval to 5 minute and DON'T resolve
service names!

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 use Time::Local;
10
11 my @PORTS = qw (
12 TCP/22 TCP/25 TCP/20 TCP/21 UDP/53
13 TCP/80 TCP/110 TCP/113 TCP/119 UDP/137 UDP/138
14 TCP/210 TCP/443 UDP/514 );
15
16 #my $log = '/var/log/iptraf/tcp_udp_services-eth1.log';
17 my $log = '/home/dpavlin/iptraf/tcp_udp_services-eth1.log';
18
19 open(LOG,$log) || die "Can't open logfile '$log': $!";
20
21 my %hash;
22
23 while (<LOG>) {
24 chomp;
25 last if ( m/^Running/ );
26 next if ( m/^\s*$/ );
27
28 ## read data for tcp packets
29 if (my ($port) = $_ =~ m/^(\w+\/\d+)/) {
30 my ($packs, $bytes, $pack_in, $byte_in, $pack_out, $byte_out) =
31 $_ =~ m/\s(\d+)\s/g;
32
33 $hash{$port} = [$byte_in, $byte_out];
34 }
35 }
36
37 close(LOG);
38
39 foreach my $port (@PORTS) {
40 print @{$hash{$port}}[0] || 0,"\n",@{$hash{$port}}[1] || 0,"\n";
41 }

  ViewVC Help
Powered by ViewVC 1.1.26