From: Andy Bavier Date: Tue, 22 Feb 2005 18:06:47 +0000 (+0000) Subject: Remove bandwidth caps when pl_mom restarts X-Git-Tag: planetlab-3_0-branch~2 X-Git-Url: http://git.onelab.eu/?p=mom.git;a=commitdiff_plain;h=56223fd521ba496f961baf743698ef2cfaebf76e Remove bandwidth caps when pl_mom restarts --- diff --git a/pl_mom.pl b/pl_mom.pl index 6f286e6..ecab7bf 100755 --- a/pl_mom.pl +++ b/pl_mom.pl @@ -5,7 +5,7 @@ use Sys::Syslog; use Sys::Hostname; #use LWP::Simple; -$debug = 0; +$debug = 1; $proc = "pl_mom"; $alias_addr = "pl-mom\@planet-lab.org"; $from_addr = "support\@planet-lab.org"; @@ -27,6 +27,7 @@ if (! $debug) { $daily_log = "/var/lib/misc/pl_mom.daily"; $daily_stamp = "/var/lib/misc/pl_mom.stamp"; $configfile = "/etc/planetlab/pl_mom.conf"; + $capfile = "/var/lib/misc/pl_mom.oldcaps"; } else { $kill_thresh = 2; $reboot_thresh = 20; @@ -42,6 +43,7 @@ if (! $debug) { $daily_log = "./pl_mom.daily"; $daily_stamp = "./pl_mom.stamp"; $configfile = "./pl_mom.conf"; + $capfile = "./pl_mom.oldcaps"; } $sleep = 30; @@ -74,6 +76,7 @@ if (! $pid) { if ($bwcap =~ /off/) { syslog("info", "pl_mom: Bandwidth capping is off"); } + reset_bandwidth_caps(); bandwidth_monitor(); die (0); } @@ -130,7 +133,8 @@ sub reboot_kicker { system("touch $rebootfile"); if (! $debug) { - system("shutdown -r now"); + #system("shutdown -r now"); + system("/bin/sync; /sbin/reboot -f"); } die (0); } @@ -158,17 +162,9 @@ sub bandwidth_monitor { # Also may want a list of slices that are exempt from capping. if (defined(%Start)) { undef %Start; } if (defined(%Now)) { undef %Now; } + if (defined(%Cap)) { undef %Cap; } - if (defined(%Cap)) { - # Reset bandwidth limits here - chomp($cap = `cat /etc/planetlab/bwcap`); - foreach $sliceid ( sort ( keys %Cap ) ) { - $slice = get_slice_name($sliceid); - syslog("info", "pl_mom: Uncapping bandwidth of $slice"); - cap_bandwidth ($slice, $cap); - } - undef %Cap; - } + reset_bandwidth_caps(); syslog("info", "pl_mom: Beginning bandwidth monitoring for $now"); } @@ -216,7 +212,7 @@ sub bandwidth_monitor { $slicename = get_slice_name($slice); if ($slicename) { bw_cap_mail($slicename); - # Cap bandwidth here + log_bandwidth_cap($slicename, $bwcap); cap_bandwidth($slicename, $bwcap); } else { syslog("warning", "pl_mom: Could not find slice ". @@ -249,6 +245,29 @@ sub read_config_file { } } +sub reset_bandwidth_caps { + if (-e $capfile) { + open(CAP, "<$capfile") or die "Cannot open $capfile: $!"; + while () { + chomp(); + ($slicename, $oldcap) = split(/ /); + syslog("info", "pl_mom: Restoring bandwidth cap of $oldcap ". + "to $slicename"); + cap_bandwidth ($slicename, $oldcap); + } + close CAP; + unlink($capfile); + } +} + +sub log_bandwidth_cap { + ($slicename, $cap) = @_; + syslog("warning", "pl_mom: Capping bandwidth of slice ". + "$slicename at $cap until midnight GMT."); + # Save current cap to $capfile + system("echo $slicename `bwlimit getcap $slicename` >> $capfile"); +} + sub send_mail { # Arg 0: recipient addresses, comma-separated string # Arg 1: subject line @@ -268,10 +287,9 @@ sub send_mail { } sub cap_bandwidth { - # Arg 0: slice name - # Arg 1: bandwidth cap for 'tc' - `bwlimit setcap $_[0] $_[1]`; - `bwlimit on $_[0]`; + ($slicename, $cap) = @_; + system("bwlimit setcap $slicename $cap"); + system("bwlimit on $slicename"); } sub get_date { @@ -305,10 +323,6 @@ sub bw_cap_mail { my $date = get_date(); my $sent = int($byte_cutoff/1000000000); - # Put this here because this is where we have the - syslog("warning", "pl_mom: Capping bandwidth of slice ". - "$slicename at $bwcap until midnight GMT."); - send_mail("$alias_addr, $slicename\@slices.planet-lab.org", "$proc capped bandwidth of slice $slicename on $hostname", "Slice $slicename has transmitted more than ${sent}GB today". diff --git a/pl_mom.spec b/pl_mom.spec index c0ae78f..8d42a06 100644 --- a/pl_mom.spec +++ b/pl_mom.spec @@ -1,6 +1,6 @@ %define name pl_mom %define version 0.3 -%define release 5.planetlab%{?date:.%{date}} +%define release 6.planetlab%{?date:.%{date}} Summary: PlanetLab mom -- Cleans up your mess Name: %{name}