X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=bwmon.py;h=91a79f382af7ab6d74e97c1ef12aed7a0e6bff10;hb=refs%2Fheads%2F1.8;hp=d980abc859e8d8fe2e40d7fa6b8d26e23ff4a6de;hpb=2e44e004acaec94b64794a59baa6e92ad626a8a7;p=nodemanager.git diff --git a/bwmon.py b/bwmon.py index d980abc..91a79f3 100644 --- a/bwmon.py +++ b/bwmon.py @@ -52,14 +52,30 @@ except: seconds_per_day = 24 * 60 * 60 bits_per_byte = 8 +dev_default = tools.get_default_if() # Burst to line rate (or node cap). Set by NM. in KBit/s -default_MaxRate = int(bwlimit.get_bwcap() / 1000) +default_MaxRate = int(bwlimit.get_bwcap(dev_default) / 1000) default_Maxi2Rate = int(bwlimit.bwmax / 1000) # 5.4 Gbyte per day. 5.4 * 1024 k * 1024M * 1024G # 5.4 Gbyte per day max allowed transfered per recording period -default_MaxKByte = 5662310 +# 5.4 Gbytes per day is aprox 512k/s for 24hrs (approx because original math was wrong +# but its better to keep a higher byte total and keep people happy than correct +# the problem and piss people off. +# default_MaxKByte = 5662310 + +# -- 6/1/09 +# llp wants to double these, so we use the following +# 1mbit * 24hrs * 60mins * 60secs = bits/day +# 1000000 * 24 * 60 * 60 / (1024 * 8) +default_MaxKByte = 10546875 + # 16.4 Gbyte per day max allowed transfered per recording period to I2 -default_Maxi2KByte = 17196646 +# default_Maxi2KByte = 17196646 + +# -- 6/1/09 +# 3Mb/s for 24hrs a day (30.17 gigs) +default_Maxi2KByte = 31640625 + # Default share quanta default_Share = 1 @@ -199,7 +215,7 @@ class Slice: self.emailed = False self.capped = False - self.updateSliceAttributes(rspec) + self.updateSliceTags(rspec) bwlimit.set(xid = self.xid, minrate = self.MinRate * 1000, maxrate = self.MaxRate * 1000, @@ -210,7 +226,7 @@ class Slice: def __repr__(self): return self.name - def updateSliceAttributes(self, rspec): + def updateSliceTags(self, rspec): ''' Use respects from GetSlivers to PLC to populate slice object. Also do some sanity checking. @@ -277,10 +293,10 @@ class Slice: to their default values. """ # Cache share for later comparison - runningrates.get('share', 1) = self.Share + self.Share = runningrates.get('share', 1) # Query Node Manager for max rate overrides - self.updateSliceAttributes(rspec) + self.updateSliceTags(rspec) # Reset baseline time self.time = time.time() @@ -308,7 +324,7 @@ class Slice: (self.name, bwlimit.format_tc_rate(maxrate), bwlimit.format_tc_rate(maxi2rate)), 1) - bwlimit.set(xid = self.xid, + bwlimit.set(xid = self.xid, dev = dev_default, minrate = self.MinRate * 1000, maxrate = self.MaxRate * 1000, maxexemptrate = self.Maxi2Rate * 1000, @@ -370,7 +386,7 @@ class Slice: runningrates['share'] = self.Share # Query Node Manager for max rate overrides - self.updateSliceAttributes(rspec) + self.updateSliceTags(rspec) usedbytes = runningrates['usedbytes'] usedi2bytes = runningrates['usedi2bytes'] @@ -646,9 +662,41 @@ def sync(nmdbcopy): pickle.dump((version, slices, deaddb), f) f.close() +# doesnt use generic default interface because this runs as its own thread. +# changing the config variable will not have an effect since GetSlivers: pass +def getDefaults(nmdbcopy): + ''' + Get defaults from default slice's slice attributes. + ''' + status = True + # default slice + dfltslice = nmdbcopy.get(PLC_SLICE_PREFIX+"_default") + if dfltslice: + if dfltslice['rspec']['net_max_rate'] == -1: + allOff() + status = False + return status + + +def allOff(): + """ + Turn off all slice HTBs + """ + # Get/set special slice IDs + root_xid = bwlimit.get_xid("root") + default_xid = bwlimit.get_xid("default") + kernelhtbs = gethtbs(root_xid, default_xid) + if len(kernelhtbs): + logger.log("bwlimit: Disabling all running HTBs.") + for htb in kernelhtbs.keys(): bwlimit.off(htb) + + lock = threading.Event() def run(): - """When run as a thread, wait for event, lock db, deep copy it, release it, run bwmon.GetSlivers(), then go back to waiting.""" + """ + When run as a thread, wait for event, lock db, deep copy it, release it, + run bwmon.GetSlivers(), then go back to waiting. + """ logger.log("bwmon: Thread started", 2) while True: lock.wait() @@ -656,7 +704,11 @@ def run(): database.db_lock.acquire() nmdbcopy = copy.deepcopy(database.db) database.db_lock.release() - try: sync(nmdbcopy) + try: + if getDefaults(nmdbcopy) and len(bwlimit.tc("class show dev %s" % dev_default)) > 0: + # class show to check if net:InitNodeLimit:bwlimit.init has run. + sync(nmdbcopy) + else: logger.log("bwmon: BW limits DISABLED.") except: logger.log_exc() lock.clear()