From: Faiyaz Ahmed Date: Fri, 1 Dec 2006 22:02:01 +0000 (+0000) Subject: * Fixed floating point arith error. tc likes whole numbers. X-Git-Tag: planetlab-4_0-rc1~18 X-Git-Url: http://git.onelab.eu/?p=mom.git;a=commitdiff_plain;h=803f99c0c1963672af3f9c8ee7186b9924b35efd * Fixed floating point arith error. tc likes whole numbers. * Added extra debug statements. --- diff --git a/bwmon.py b/bwmon.py index b31e893..09bea99 100755 --- a/bwmon.py +++ b/bwmon.py @@ -100,12 +100,6 @@ class Slice: ByteThresh - After thresh, cap node to (maxbyte - bytes)/(time left in period) ExemptByteMax - Same as above, but for i2. ExemptByteThresh - i2 ByteThresh - #last_maxexemptrate - last recorded maxexemptrate from NM. Slice attribute. - #last_maxrate - last recorded maxrate from NM. Slice attribute. - #last_ByteMax - Last recorded from NM. total volume of data allowed. - #last_ByteThresh - Last recorded from NM. After thresh, cap node to (maxbyte - bytes)/(period - t) - #last_ExemptByteMax - Last recorded from NM. Same as above, but for i2. - #last_ExemptByteThresh - Last recorded from NM. i2 ByteThresh """ @@ -121,12 +115,6 @@ class Slice: self.ExemptByteThresh = default_ExemptByteThresh self.maxrate = default_maxrate self.maxexemptrate = default_maxexemptrate - #self.last_maxrate = default_maxrate - #self.last_maxexemptrate = default_maxexemptrate - #self.last_ByteMax = default_ByteMax - #self.last_ByteThresh = default_ByteThresh - #self.last_ExemptByteMax = default_ExemptByteMax - #self.last_ExemptByteThresh = default_ExemptByteThresh # Get real values where applicable self.reset(maxrate, maxexemptrate, bytes, exemptbytes) @@ -170,13 +158,8 @@ class Slice: def update(self, maxrate, maxexemptrate, bytes, exemptbytes): """ - Update byte counts and check if average rates have been - exceeded. In the worst case (instantaneous usage of the entire - average daily byte limit at the beginning of the recording - period), the slice will be immediately capped and will get to - send twice the average daily byte limit. In the common case, - it will get to send slightly more than the average daily byte - limit. + Update byte counts and check if byte limits have been + exceeded. """ # Query Node Manager for max rate overrides @@ -190,8 +173,9 @@ class Slice: 'date': time.asctime(time.gmtime()) + " GMT", 'period': format_period(period)} + print("byts %s self.bytes %s ByteThresh %s" %(bytes, self.bytes, self.ByteThresh)) if bytes >= (self.bytes + self.ByteThresh): - new_maxrate = (self.ByteMax - self.ByteThresh)/(period - (time.time() - self.time)) + new_maxrate = int(self.ByteMax - self.ByteThresh)/(period - (time.time() - self.time)) else: new_maxrate = maxrate @@ -204,7 +188,7 @@ class Slice: if verbose: print "%(slice)s %(class)s " \ - "%(bytes)s, %(limit)s (%(new_maxrate)s avg)" % \ + "%(bytes)s, %(limit)s (%(new_maxrate)s maxrate)" % \ params # Cap low bandwidth burst rate @@ -214,7 +198,7 @@ class Slice: if exemptbytes >= (self.exemptbytes + self.ExemptByteThresh): new_maxexemptrate = \ - (self.ExemptByteMax - self.ExemptByteThresh)/(period - (time.time() - self.time)) + int((self.ExemptByteMax - self.ExemptByteThresh)/(period - (time.time() - self.time))) else: new_maxexemptrate = maxexemptrate @@ -247,6 +231,8 @@ class Slice: else: slicemail(self.name, subject, message + (footer % params)) + + def usage(): print """ Usage: %s [OPTIONS]... @@ -328,8 +314,16 @@ def main(): bytes, exemptbytes) = params live.append(xid) - # Delete Me - print("name %s , minrate %s, maxrate %s, minexemptrate %s, maxexemptrate %s, bytes %s, exemptbytes %s" % (bwlimit.get_slice(xid), minrate, maxrate, minexemptrate, maxexemptrate, bytes, exemptbytes)) + if verbose: + print("\n%s, minrate %s, maxrate %s, minexemptrate %s,"\ + " maxexemptrate %s, bytes %s, exemptbytes %s" % \ + (bwlimit.get_slice(xid), + bwlimit.format_tc_rate(minrate), + bwlimit.format_tc_rate(maxrate), + bwlimit.format_tc_rate(minexemptrate), + bwlimit.format_tc_rate(maxexemptrate), + bytes, + exemptbytes)) # Ignore root and default buckets if xid == root_xid or xid == default_xid: