James Carlson wrote: > Darren Reed writes: >> When I've had an Internet connection via an ISP that >> meters traffic (you have a 'quota' of x gb/month), >> I've run a cron job on the end-of-month day to dump >> out the output from ipfstat and clear the counters >> back to 0. Thus at any time during the month, using >> ipfstat gives me a reasonable approximation of the >> current quota use. > > I think it'd be nice if that cron job didn't have to run with > privileges sufficient to write to the kernel. > > I agree that the delta tool doesn't necessarily have to be part of > dlstat itself. Perhaps if it were made a common library (along with > the rest of the column-formatting stuff that Brussels cleaned up), > that would address most of the concerns.
A C library? To me that seems like making a mountain out of a mole hill... 15 minutes and I came up with a perl script to print out what has changed between two dumps of netstat output - and that's just a very basic script. How long would it take to write in C? Substantially longer because you've got to go through all sorts of hoops to handle text input safely. For those that don't like perl, well, use python or your other favourite scripting langauge. Darren ./statdiff netstat st.1 st.2 tcpInAckBytes 308 ipInReceives 6 ipOutRequests 5 tcpOutDataSegs 5 tcpOutDataBytes 308 tcpOutSegs 5 tcpRttUpdate 4 tcpInInorderSegs 4 ipInDelivers 6 tcpInAckSegs 4 tcpInSegs 6 tcpInInorderBytes 208 #!/bin/perl if ($#ARGV ne 2) { print STDERR "Usaage: <format> <file1> <file2>\n"; exit(1); } if ($ARGV[0] == "netstat") { %fdata1 = (); open(F, "<$ARGV[1]"); &netstatfile(\%fdata1); close(F); %fdata2 = (); open(F, "<$ARGV[2]"); &netstatfile(\%fdata2); close(F); } foreach $k (keys %fdata1) { if ($fdata1{$k} ne $fdata2{$k}) { print "$k\t".int($fdata2{$k} - $fdata1{$k})."\n"; } } exit(0); sub netstatfile { while (<F>) { chop; if (/^(\S+)/i) { s/^$1//; } if (/=/) { while (/\s+/) { s/\s+//; } if (/^([a-z]+)=(\d+)/i) { $_[0]{$1} = $2; s/$1=$2//; } if (/^([a-z]+)=(\d+)/i) { $_[0]{$1} = $2; s/$1=$2//; } } } }