Bandwidth limiting added
authorAndy Bavier <acb@cs.princeton.edu>
Thu, 6 Jan 2005 21:55:56 +0000 (21:55 +0000)
committerAndy Bavier <acb@cs.princeton.edu>
Thu, 6 Jan 2005 21:55:56 +0000 (21:55 +0000)
pl_mom.pl
pl_mom.spec

index 55f8c9e..75440e3 100755 (executable)
--- 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/<id> 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.  ".
index 127fdc0..2b35512 100644 (file)
@@ -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}