wmclockmon: update change-log
[dockapps.git] / wmjiface / src / svr.client / ifacechk.client
blob1e55281c9c4aa041158260c90eb7ad6a84468ff1
1 #!/usr/bin/perl
3 $firewallip="192.168.1.1"; # please change me?
6 ################
7 # cat /proc/net/dev
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 #########################
16 $ppid=getppid();
18 use IO::Socket;
20 $staname="$ENV{HOME}/.wmjiface.stat.$ppid";
22 @statusFiles=`ls $ENV{HOME}/.wmjiface.stat.* 2>/dev/null`;
24 foreach (@statusFiles) {
25 s/^.*[.]wmjiface[.]stat[.]//;
26 chomp;
27 system("rm $ENV{HOME}/.wmjiface.stat.$_") if not ( -d "/proc/$_" );
30 $now=time();
32 $then; # aquired during read_stat;
34 %statso; # aquired during read_stat;
35 %statsc; # aquired during read_proc;
37 &read_proc();
39 if(&read_stat()) {
40 $tdiff = $now - $then;
42 foreach (keys %statsc) {
43 if($statso{$_}) {
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;
62 &write_stat();
63 exit;
66 ##################################################################3
68 sub write_stat() {
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",
75 $_,
76 $statsc{$_}{bytesi},
77 $statsc{$_}{byteso},
78 $statsc{$_}{packetsi},
79 $statsc{$_}{packetso};
82 close sta;
85 sub read_stat() {
86 open sta, "$staname" or return ();
88 $then = <sta>;
89 chomp $then;
91 while(<sta>) {
92 chomp;
94 ($face, $bytesi, $byteso, $packetsi, $packetso) = split ":";
96 $statso{$face} = { bytesi => $bytesi,
97 byteso => $byteso,
98 packetsi => $byteso,
99 packetso => $byteso };
102 close sta;
103 return 1;
106 sub read_proc() {
107 $dev = $dev = new IO::Socket::INET (
108 PeerAddr => "$firewallip",
109 PeerPort => "7654",
110 Proto => tcp,
111 Reuse => 1
112 ) or die "Could not create socket: $!\n";
114 $waste = $sock; # title
115 $waste = $sock; # title
116 $waste = $sock; # lo
118 $devfilesexist = `ls /var/run/ppp*.dev 2>/dev/null`; chomp $devfilesexist;
120 while(<$dev>) {
121 close $dev if /\x04/;
122 last if /\x04/;
123 chomp; s/[ ]+/:/g; s/^://; s/:$//; s/[:]+/:/g;
125 s/([0-9]+)([0-9]{9})/$2/g;
127 ($face,
128 $bytesi, $packetsi, $errsi, $dropi, $fifoi, $frame, $compressedi, $multicast,
129 $byteso, $packetso, $errso, $dropo, $fifoo, $colls, $carrier, $compressedo
130 ) = split ":";
132 if($devfilesexist !~ /^$/ and $face =~ /ppp/) {
133 $tosser = `grep $face /var/run/*.dev /dev/null | head -1`;
134 chomp $tosser;
135 $tosser =~ s/^[^-]*-//;
136 $tosser =~ s/.dev:.*//;
137 if($tosser !~ /^$/) {
138 $statsc{$tosser} = { bytesi => $bytesi,
139 byteso => $byteso,
140 packetsi => $byteso,
141 packetso => $byteso };
143 } else {
144 $statsc{$face} = { bytesi => $bytesi,
145 byteso => $byteso,
146 packetsi => $byteso,
147 packetso => $byteso };
151 close dev;