/[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.5 - (show annotations)
Wed May 22 07:11:08 2002 UTC (17 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.4: +6 -1 lines
File MIME type: text/plain
return undef on faulty values (this makes graph without spikes)

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 # Dobrica Pavlinusic <dpavlin@rot13.org>
7
8 use strict;
9 use warnings;
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 $log = $ARGV[0] if ($ARGV[0] && -r $ARGV[0]);
20
21 open(LOG,$log) || die "Can't open logfile '$log': $!";
22
23 my $delta="/var/tmp/";
24 my $tmp_log=$log;
25 $tmp_log=~s/\W/_/g;
26 $delta.=$tmp_log.".offset";
27
28 if (-e $delta) {
29 open(D,$delta) || die "can't open delta file '$delta' for log '$log': $!";
30 my $offset=<D>;
31 chomp $offset;
32 close(D);
33 my $log_size = -s $log;
34 if ($offset <= $log_size) {
35 seek(LOG,$offset,0);
36 }
37 }
38
39 my %hash;
40
41 while (<LOG>) {
42 chomp;
43 last if ( m/^Running/ );
44 next if ( m/^\s*$/ );
45
46 ## read data for tcp packets
47 if (my ($port) = $_ =~ m/^(\w+\/\d+)/) {
48 my ($packs, $bytes, $pack_in, $byte_in, $pack_out, $byte_out) =
49 $_ =~ m/\s(\d+)\s/g;
50
51 $hash{$port} = [$byte_in, $byte_out];
52 }
53 }
54
55 open(D,"> $delta") || die "can't open delta file '$delta' for log '$log': $!";
56 print D tell(LOG);
57 close(D);
58
59 close(LOG);
60
61 foreach my $port (@PORTS) {
62 print @{$hash{$port}}[0] || "U","\n",@{$hash{$port}}[1] || "U","\n";
63 delete $hash{$port};
64 }
65
66 my ($sum_in,$sum_out) = (0,0);
67
68 foreach my $port (keys %hash) {
69 $sum_in+=@{$hash{$port}}[0];
70 $sum_out+=@{$hash{$port}}[1];
71 }
72
73 $sum_in = "U" if ($sum_in == 0);
74 $sum_out = "U" if ($sum_out == 0);
75 print "$sum_in\n$sum_out\n";

  ViewVC Help
Powered by ViewVC 1.1.26