From 2bcc6c1930ea59077be2e7ef390093ccde82c5c9 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Mon, 27 Feb 2006 02:41:43 +0000 Subject: [PATCH] - bwlimit script now sets up capped and exempt subclasses; capped buckets all begin with 0x1000. Ignore the root (0x1000) and default (0x1fff) buckets, as well as exempt buckets. - don't send mail when debugging - log bandwidth caps and actually cap bandwidth when debugging --- pl_mom.pl | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/pl_mom.pl b/pl_mom.pl index 5b4e676..c6ac506 100755 --- a/pl_mom.pl +++ b/pl_mom.pl @@ -196,10 +196,8 @@ sub bandwidth_monitor { ! defined($Cap{$slice})) { $Cap{$slice} = "sent"; bw_cap_mail($slice); - if (! $debug) { - log_bandwidth_cap($slice, $Maxrate{$slice}); - cap_bandwidth($slice, $Maxrate{$slice}); - } + log_bandwidth_cap($slice, $Maxrate{$slice}); + cap_bandwidth($slice, $Maxrate{$slice}); } } else { # Token bucket for this slice is gone! @@ -253,6 +251,16 @@ sub get_baseline_counts { foreach $line ( @Lines ) { if ($line =~ /qdisc pfifo (.*): dev/) { $sliceid = hex($1); + # "Capped" buckets all begin with 0x1000. Ignore the root + # (0x1000) and default (0x1fff) buckets, as well as + # "exempt" buckets that begin with 0x2000 (or anything + # other than 0x1000). + if (($sliceid & 0xf000) == 0x1000 && + $sliceid != 0x1000 && $sliceid != 0x1fff) { + $sliceid = $sliceid & 0x0fff; + } else { + $sliceid = 0xffff; + } } else { if ($line =~ /Sent (.*) bytes/) { my $bytes = $1; @@ -296,10 +304,6 @@ sub get_slice_limits { } $Maxrate{$slice} = $limit; $Cutoff{$slice} = $cutoff; - if ($debug) { - print "Slice $slice, maxrate $Maxrate{$slice}, ". - "cutoff $Cutoff{$slice}\n"; - } } } } @@ -336,13 +340,18 @@ sub send_mail { my $subject = "Subject: $_[1]\n"; my $msg = $_[2]; - open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!"; - print SENDMAIL $to; - print SENDMAIL $from; - print SENDMAIL $subject; - print SENDMAIL "Content-type: text/plain\n\n"; - print SENDMAIL $msg; - close(SENDMAIL); + if ($debug) { + print $to; + print $subject; + } else { + open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!"; + print SENDMAIL $to; + print SENDMAIL $from; + print SENDMAIL $subject; + print SENDMAIL "Content-type: text/plain\n\n"; + print SENDMAIL $msg; + close(SENDMAIL); + } } sub cap_bandwidth { -- 2.43.0