3 $firewallip="192.168.1.1"; # please change me?
8 #Inter-| Receive | Transmit
9 # face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
10 # lo:22905347 39915 0 0 0 0 0 0 22905347 39915 0 0 0 0 0 0
11 # eth0: 923454 7885 0 0 0 0 0 347 1987558 6791 0 0 0 0 0 0
12 # ppp0: 7080806 7876 2 0 0 2 0 0 314121 5267 0 0 0 0 0 0
13 # ppp1: 331265 7810 0 0 0 0 0 0 233915 8563 0 0 0 0 0 0
14 #########################
20 $staname="$ENV{HOME}/.wmjiface.stat.$ppid";
22 @statusFiles=`ls $ENV{HOME}/.wmjiface.stat.* 2>/dev/null`;
24 foreach (@statusFiles) {
25 s/^.*[.]wmjiface[.]stat[.]//;
27 system("rm $ENV{HOME}/.wmjiface.stat.$_") if not ( -d
"/proc/$_" );
32 $then; # aquired during read_stat;
34 %statso; # aquired during read_stat;
35 %statsc; # aquired during read_proc;
40 $tdiff = $now - $then;
42 foreach (keys %statsc) {
44 $bytesin = $statsc{$_}{bytesi
} - $statso{$_}{bytesi
};
45 $bytesout = $statsc{$_}{byteso
} - $statso{$_}{byteso
};
47 #$packetsin = $statsc{$_}{packetsi} - $statso{$_}{packetsi};
48 #$packetsout = $statsc{$_}{packetso} - $statso{$_}{packetso};
50 $bytesin_ps = $bytesin/$tdiff if $tdiff > 0;
51 $bytesout_ps = $bytesout/$tdiff if $tdiff > 0;
53 #$packetsin_ps = $packetsin/$tdiff if $tdiff > 0;
54 #$packetsout_ps = $packetsout/$tdiff if $tdiff > 0;
56 printf "%s %i %i\n", $_, $bytesin_ps, $bytesout_ps;
66 ##################################################################3
69 open sta
, ">$staname" or die;
71 printf sta
"%i\n", $now;
73 foreach (keys %statsc) {
74 printf sta
"%s:%i:%i:%i:%i:%i\n",
78 $statsc{$_}{packetsi
},
79 $statsc{$_}{packetso
};
86 open sta
, "$staname" or return ();
94 ($face, $bytesi, $byteso, $packetsi, $packetso) = split ":";
96 $statso{$face} = { bytesi
=> $bytesi,
99 packetso
=> $byteso };
107 $dev = $dev = new IO
::Socket
::INET
(
108 PeerAddr
=> "$firewallip",
112 ) or die "Could not create socket: $!\n";
114 $waste = $sock; # title
115 $waste = $sock; # title
118 $devfilesexist = `ls /var/run/ppp*.dev 2>/dev/null`; chomp $devfilesexist;
121 close $dev if /\x04/;
123 chomp; s/[ ]+/:/g; s/^://; s/:$//; s/[:]+/:/g;
125 s/([0-9]+)([0-9]{9})/$2/g;
128 $bytesi, $packetsi, $errsi, $dropi, $fifoi, $frame, $compressedi, $multicast,
129 $byteso, $packetso, $errso, $dropo, $fifoo, $colls, $carrier, $compressedo
132 if($devfilesexist !~ /^$/ and $face =~ /ppp/) {
133 $tosser = `grep $face /var/run/*.dev /dev/null | head -1`;
135 $tosser =~ s/^[^-]*-//;
136 $tosser =~ s/.dev:.*//;
137 if($tosser !~ /^$/) {
138 $statsc{$tosser} = { bytesi
=> $bytesi,
141 packetso
=> $byteso };
144 $statsc{$face} = { bytesi
=> $bytesi,
147 packetso
=> $byteso };