From 1beb79232d2015f6c4eb40c4fab2b1ccda9fc85a Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Fri, 21 Jan 2005 14:07:04 +0000 Subject: [PATCH] Turn on/off bandwidth caps --- pl_mom.pl | 65 +++++++++++++++++++++++++++++++++++++---------------- pl_mom.spec | 2 +- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/pl_mom.pl b/pl_mom.pl index 75440e3..1e16c3c 100755 --- a/pl_mom.pl +++ b/pl_mom.pl @@ -9,7 +9,8 @@ $debug = 0; $proc = "pl_mom"; $alias_addr = "pl-mom\@planet-lab.org"; $from_addr = "support\@planet-lab.org"; -$bwcap = "1.5Mbit"; +#$bwcap = "1.5Mbit"; +$bwcap = "off"; if (! $debug) { $kill_thresh = 90; @@ -18,7 +19,6 @@ if (! $debug) { $change_thresh = 5; $min_thresh = 10; $byte_cutoff = 16000000000; # 16GB - #$byte_cutoff = 5000000000; # 5GB $bwmon_sleep = 900; $sendmail = "/usr/sbin/sendmail -t -f$from_addr"; @@ -26,6 +26,7 @@ if (! $debug) { $rebootfile = "/var/lib/misc/pl_mom.reboot"; $daily_log = "/var/lib/misc/pl_mom.daily"; $daily_stamp = "/var/lib/misc/pl_mom.stamp"; + $configfile = "/etc/planetlab/pl_mom.conf"; } else { $kill_thresh = 2; $reboot_thresh = 20; @@ -40,6 +41,7 @@ if (! $debug) { $rebootfile = "./pl_mom.reboot"; $daily_log = "./pl_mom.daily"; $daily_stamp = "./pl_mom.stamp"; + $configfile = "./pl_mom.conf"; } $sleep = 30; @@ -51,6 +53,8 @@ if (! $debug) { system("echo $$ > $pidfile"); +read_config_file(); + # Check to see whether pl_mom rebooted the node if (-e $rebootfile) { unlink($rebootfile); @@ -67,6 +71,9 @@ if (! $pid) { $pid = fork(); if (! $pid) { syslog ("info", "pl_mom: Launching bandwidth monitor"); + if ($bwcap =~ /off/) { + syslog("info", "pl_mom: Bandwidth capping is off"); + } bandwidth_monitor(); die (0); } @@ -155,7 +162,9 @@ sub bandwidth_monitor { if (defined(%Cap)) { # Reset bandwidth limits here chomp($cap = `cat /etc/planetlab/bwcap`); - foreach $slice ( sort ( keys %Cap ) ) { + foreach $sliceid ( sort ( keys %Cap ) ) { + $slice = get_slice_name($sliceid); + syslog("info", "pl_mom: Uncapping bandwidth of $slice"); cap_bandwidth ($slice, $cap); } undef %Cap; @@ -197,24 +206,26 @@ sub bandwidth_monitor { } } close (BASE); - - foreach $slice ( sort (keys %Start) ) { - if (defined $Now{$slice}) { - $today = $Now{$slice} - $Start{$slice}; - if ($today >= $byte_cutoff && ! defined($Cap{$slice})) { - $Cap{$slice} = "sent"; - $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"); + + if (!($bwcap =~ /off/)) { + foreach $slice ( sort (keys %Start) ) { + if (defined $Now{$slice}) { + $today = $Now{$slice} - $Start{$slice}; + if ($today >= $byte_cutoff && ! defined($Cap{$slice})) { + $Cap{$slice} = "sent"; + $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"); + } } + } else { + # Token bucket for this slice is gone! } - } else { - # The /proc/virtual/ directory is gone... } } @@ -222,6 +233,22 @@ sub bandwidth_monitor { } } +sub read_config_file { + if (-e $configfile) { + open (CONFIG, "<$configfile") || + print "Cannot open $configfile; $!\n"; + while () { + if (m/^(.*)=(.*)$/) { + ${$1} = $2; + if ($debug) { + print "read_config_file: $1 = ${$1}\n"; + } + } + } + close CONFIG; + } +} + sub send_mail { # Arg 0: recipient addresses, comma-separated string # Arg 1: subject line diff --git a/pl_mom.spec b/pl_mom.spec index 2b35512..eaf3818 100644 --- a/pl_mom.spec +++ b/pl_mom.spec @@ -1,6 +1,6 @@ %define name pl_mom %define version 0.3 -%define release 3.planetlab%{?date:.%{date}} +%define release 4.planetlab%{?date:.%{date}} Summary: PlanetLab mom -- Cleans up your mess Name: %{name} -- 2.43.0