Obciazenie sieci co 5 sekund... Jak to zrobic ??

Arkadiusz Chomicki duch w wla.pl
Sob, 3 Lip 2004, 19:00:55 CEST


On Sat, 3 Jul 2004, Pawel Koska wrote:

> Witam
> 
> Chcialbym zrobic kilka testow.
> Chodzi mi o to by zrobic jakis skrypt, czy cos takiego co wpisywalo by
> do pliku co 5 sekund jakie jest aktualne obciazenie sieci
> Moglo by zapisywac w kbps. Aha i dobrze by bylo gdyby jakas data sie
> dorzucala :)
> 
proponuje uzyc iftop
ale ten pokazuje na beirzaco

ja popelnilem w perlu malutki skrypt pokazujacy aktualny transfer na 
interfejscach
pokazuje na ekranie ale nic nie stoi na przeszkodzie zeby zapoisywal 
do pliku

skrypt jest w zalaczniku


Pozdrawiam
ChomAr
-- 
+-=========================| Arkadiusz Chomicki |=====================-+
  84-120 Władysławowo         GG#: 420515
  woj. pomorskie              e-mail:chomar(at)wla(dot)pl
  Registered User: 82605      http://www.chomar.wla.pl
  http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=82605
+-========================| Powered by PLD Linux |====================-+
-------------- następna część ---------
#!/usr/bin/perl -w
#
# ======================================================
#   Aktualna transmisja na interfejsach version 0.1
#   http://www.chomar.wla.pl/
#
#   by Arkadiusz Chomicki chomar (at) wla (dot) pl
#
# ======================================================
#
#Use Socket;

$sleep=2;

#my @TX_NAME;
#my @TX_VAR;
open DEVBUFF1, "/proc/net/dev";
while (<DEVBUFF1>) 
{
	$j++;
	push @dev_buff_prev, $_ if $j > 2;
#	push @dev_buff_prev, "$j\n" if $j > 2;
#	print $_ if $j > 2;
}
close DEVBUFF1;
#print "===============\n";

#exit;
open DEVBUFF, "/proc/net/dev";
while (1) {
	sleep $sleep;
	system("clear");
	seek (DEVBUFF,0,0);
	@dev_buff = <DEVBUFF>;

	$j=0;
	my $time_string = localtime;
	print "$time_string\n";
	print " dev  |RX bits      pkts     errs |";
	print       "|TX bits      pkts     errs\n";
	foreach (@dev_buff)
	{
	  if (/\s*(\w*):\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*/) {
	    $buf = $_;
	    
	    $dev = $1;

	    $RXbytes = $2;
	    $RXpackets = $3;
	    $RXerrs = $4;
#	    $RXdrop = $5;
#	    $RXfifo = $6;
#	    $RXframe = $7;
#	    $RXcommpresed = $8;
#	    $RXmulticast = $9;

	    $TXbytes = $10;
	    $TXpackets = $11;
	    $TXerrs = $12;
#	    $TXdrop = $13;
#	    $TXfifo = $14;
#	    $TXcolls = $15;
#	    $TXcarrier = $16;
#	    $TXcommpresed = $17;
	    
 	    $_=shift @dev_buff_prev;
            /\s*(.*):\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*(\d*)\s*/;
	    exit if ($dev ne $1);
	    printf "%6s|\t%6.2f Mb/s %4.0f 1/s %4d ||", $dev, ($RXbytes- $2)*8/1024/1024/$sleep, ($RXpackets -  $3)/$sleep, $RXerrs;
	    printf      " %6.2f Mb/s %4.0f 1/s %4d \n",       ($TXbytes-$10)*8/1024/1024/$sleep, ($TXpackets - $11)/$sleep, $TXerrs;
	    
#	    print "\$_=$_";
	    push @dev_buff_prev, $buf;
	  }
	}
	print "======|===========================|";
	print       "|===========================\n";
#	foreach (@dev_buff_prev) {
#	  print $_;
#	}
#exit
#	@dev_buff_prev = @dev_buff;
}
close DEVBUFF;



Więcej informacji o liście dyskusyjnej pld-users-pl