X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=bwmon.py;h=2b13d6f20828406877fd795cab5e7e677665cac1;hb=74a8cfb9d2eac39ae02e5323e1fb5b1d33297981;hp=69325c9faabd89e2c945e91ef3760ef6f63e2ecc;hpb=658683174ea538f4cacdab54302882005e148b8f;p=nodemanager.git diff --git a/bwmon.py b/bwmon.py index 69325c9..2b13d6f 100644 --- a/bwmon.py +++ b/bwmon.py @@ -1,5 +1,8 @@ #!/usr/bin/python # +# $Id$ +# $URL$ +# # Average bandwidth monitoring script. Run periodically via NM db.sync to # enforce a soft limit on daily bandwidth usage for each slice. If a # slice is found to have transmitted 80% of its daily byte limit usage, @@ -14,19 +17,17 @@ # Faiyaz Ahmed # Copyright (C) 2004-2008 The Trustees of Princeton University # -# $Id$ -# import os import sys import time import pickle import socket -import logger import copy import threading -import tools +import logger +import tools import bwlimit import database @@ -52,8 +53,9 @@ 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 @@ -323,7 +325,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, @@ -578,7 +580,7 @@ def sync(nmdbcopy): if newslice != None and live[newslice].has_key('_rspec') == True: # Check to see if we recently deleted this slice. if live[newslice]['name'] not in deaddb.keys(): - logger.log( "bwmon: New Slice %s" % live[newslice]['name'] ) + logger.log( "bwmon: new slice %s" % live[newslice]['name'] ) # _rspec is the computed rspec: NM retrieved data from PLC, computed loans # and made a dict of computed values. slices[newslice] = Slice(newslice, live[newslice]['name'], live[newslice]['_rspec']) @@ -686,7 +688,7 @@ def allOff(): default_xid = bwlimit.get_xid("default") kernelhtbs = gethtbs(root_xid, default_xid) if len(kernelhtbs): - logger.log("bwlimit: Disabling all running HTBs.") + logger.log("bwmon: Disabling all running HTBs.") for htb in kernelhtbs.keys(): bwlimit.off(htb) @@ -704,15 +706,16 @@ def run(): nmdbcopy = copy.deepcopy(database.db) database.db_lock.release() try: - if getDefaults(nmdbcopy) and len(bwlimit.tc("class show dev eth0")) > 0: + 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() + except: logger.log_exc("bwmon failed") lock.clear() def start(*args): tools.as_daemon_thread(run) def GetSlivers(*args): + logger.verbose ("bwmon: triggering dummy GetSlivers") pass