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";
$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;
$daily_log = "./pl_mom.daily";
$daily_stamp = "./pl_mom.stamp";
$configfile = "./pl_mom.conf";
+ $capfile = "./pl_mom.oldcaps";
}
$sleep = 30;
if ($bwcap =~ /off/) {
syslog("info", "pl_mom: Bandwidth capping is off");
}
+ reset_bandwidth_caps();
bandwidth_monitor();
die (0);
}
system("touch $rebootfile");
if (! $debug) {
- system("shutdown -r now");
+ #system("shutdown -r now");
+ system("/bin/sync; /sbin/reboot -f");
}
die (0);
}
# 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");
}
$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 ".
}
}
+sub reset_bandwidth_caps {
+ if (-e $capfile) {
+ open(CAP, "<$capfile") or die "Cannot open $capfile: $!";
+ while (<CAP>) {
+ 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
}
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 {
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".