From bb39e347c9556097fb1f20fe3061242a202dc394 Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Thu, 6 Jan 2005 21:55:56 +0000 Subject: [PATCH] Bandwidth limiting added --- pl_mom.pl | 30 ++++++++++++++++++++++-------- pl_mom.spec | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pl_mom.pl b/pl_mom.pl index 55f8c9e..75440e3 100755 --- a/pl_mom.pl +++ b/pl_mom.pl @@ -17,8 +17,8 @@ if (! $debug) { $log_thresh = 85; $change_thresh = 5; $min_thresh = 10; - #$byte_cutoff = 16000000000; # 16GB - $byte_cutoff = 5000000000; # 5GB + $byte_cutoff = 16000000000; # 16GB + #$byte_cutoff = 5000000000; # 5GB $bwmon_sleep = 900; $sendmail = "/usr/sbin/sendmail -t -f$from_addr"; @@ -149,12 +149,18 @@ sub bandwidth_monitor { # Could save the list of capped slices in a file in order to # avoid re-sending mails if the daemon restarts. # Also may want a list of slices that are exempt from capping. - if (defined(%Cap)) { - undef %Cap; + if (defined(%Start)) { undef %Start; } + if (defined(%Now)) { undef %Now; } + + if (defined(%Cap)) { + # Reset bandwidth limits here + chomp($cap = `cat /etc/planetlab/bwcap`); + foreach $slice ( sort ( keys %Cap ) ) { + cap_bandwidth ($slice, $cap); + } + undef %Cap; } - # Need to reset bandwidth limits here - syslog("info", "pl_mom: Beginning bandwidth monitoring for $now"); } @@ -200,11 +206,12 @@ sub bandwidth_monitor { $slicename = get_slice_name($slice); if ($slicename) { bw_cap_mail($slicename); + # Cap bandwidth here + cap_bandwidth($slicename, $bwcap); } else { syslog("warning", "pl_mom: Could not find slice name". " for slice ID $slice"); } - # Add bandwidth cap here } } else { # The /proc/virtual/ directory is gone... @@ -233,6 +240,13 @@ sub send_mail { close(SENDMAIL); } +sub cap_bandwidth { + # Arg 0: slice name + # Arg 1: bandwidth cap for 'tc' + `bwlimit setcap $_[0] $_[1]`; + `bwlimit on $_[0]`; +} + sub get_date { my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdat) = localtime(time); @@ -268,7 +282,7 @@ sub bw_cap_mail { syslog("warning", "pl_mom: Capping bandwidth of slice ". "$slicename at $bwcap until midnight GMT."); - send_mail("acb\@planet-lab.org", + send_mail($alias_addr, "$proc capped bandwidth of slice $slicename on $hostname", "Slice $slicename has transmitted more than ${sent}GB today". " on $hostname. ". diff --git a/pl_mom.spec b/pl_mom.spec index 127fdc0..2b35512 100644 --- a/pl_mom.spec +++ b/pl_mom.spec @@ -1,6 +1,6 @@ %define name pl_mom %define version 0.3 -%define release 1.planetlab%{?date:.%{date}} +%define release 3.planetlab%{?date:.%{date}} Summary: PlanetLab mom -- Cleans up your mess Name: %{name} -- 2.43.0