#!/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,
# Faiyaz Ahmed <faiyaza@cs.princeton.edu>
# 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
from sets import Set
+priority = 20
+
# Defaults
# Set DEBUG to True if you don't want to send emails
DEBUG = False
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
(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,
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'])
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)
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