4 #Inter-| Receive | Transmit
5 # face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
6 # lo:22905347 39915 0 0 0 0 0 0 22905347 39915 0 0 0 0 0 0
7 # eth0: 923454 7885 0 0 0 0 0 347 1987558 6791 0 0 0 0 0 0
8 # ppp0: 7080806 7876 2 0 0 2 0 0 314121 5267 0 0 0 0 0 0
9 # ppp1: 331265 7810 0 0 0 0 0 0 233915 8563 0 0 0 0 0 0
10 #########################
14 $iface="/proc/net/dev";
15 $staname="$ENV{HOME}/.wmjiface.stat.$ppid";
17 @statusFiles=`ls $ENV{HOME}/.wmjiface.stat.* 2>/dev/null`;
19 foreach (@statusFiles) {
20 s/^.*[.]wmjiface[.]stat[.]//;
22 system("rm $ENV{HOME}/.wmjiface.stat.$_") if not ( -d
"/proc/$_" );
27 $then; # aquired during read_stat;
29 %statso; # aquired during read_stat;
30 %statsc; # aquired during read_proc;
35 $tdiff = $now - $then;
37 foreach (keys %statsc) {
39 $bytesin = $statsc{$_}{bytesi
} - $statso{$_}{bytesi
};
40 $bytesout = $statsc{$_}{byteso
} - $statso{$_}{byteso
};
42 #$packetsin = $statsc{$_}{packetsi} - $statso{$_}{packetsi};
43 #$packetsout = $statsc{$_}{packetso} - $statso{$_}{packetso};
45 $bytesin_ps = $bytesin/$tdiff if $tdiff > 0;
46 $bytesout_ps = $bytesout/$tdiff if $tdiff > 0;
48 #$packetsin_ps = $packetsin/$tdiff if $tdiff > 0;
49 #$packetsout_ps = $packetsout/$tdiff if $tdiff > 0;
51 printf "%s %i %i\n", $_, $bytesin_ps, $bytesout_ps;
61 ##################################################################3
64 open sta
, ">$staname" or die;
66 printf sta
"%i\n", $now;
68 foreach (keys %statsc) {
69 printf sta
"%s:%i:%i:%i:%i:%i\n",
73 $statsc{$_}{packetsi
},
74 $statsc{$_}{packetso
};
81 open sta
, "$staname" or return ();
89 ($face, $bytesi, $byteso, $packetsi, $packetso) = split ":";
91 $statso{$face} = { bytesi
=> $bytesi,
94 packetso
=> $byteso };
102 open dev
, "$iface" or die;
104 $waste = <dev
>; # title
105 $waste = <dev
>; # title
108 $devfilesexist = `ls /var/run/ppp*.dev 2>/dev/null`; chomp $devfilesexist;
111 chomp; s/[ ]+/:/g; s/^://; s/:$//; s/[:]+/:/g;
113 s/([0-9]+)([0-9]{9})/$2/g;
116 $bytesi, $packetsi, $errsi, $dropi, $fifoi, $frame, $compressedi, $multicast,
117 $byteso, $packetso, $errso, $dropo, $fifoo, $colls, $carrier, $compressedo
120 if($devfilesexist !~ /^$/ and $face =~ /ppp/) {
121 $tosser = `grep $face /var/run/*.dev /dev/null | head -1`;
123 $tosser =~ s/^[^-]*-//;
124 $tosser =~ s/.dev:.*//;
125 if($tosser !~ /^$/) {
126 $statsc{$tosser} = { bytesi
=> $bytesi,
129 packetso
=> $byteso };
132 $statsc{$face} = { bytesi
=> $bytesi,
135 packetso
=> $byteso };