def main(): """ Initialize monitoring """ print 'TrafficMon started.\nPress <Ctrl>-C to shut down.' # initialize interface indices for monitored nodes # These are router nodes which we have explicitly pointed out to be polled for node in config.Nodes: logging.debug('Initializing node ' + `node`) if nodes.find(node): continue n = nodes.create(node) n.type = nodes.ROUTER nodes.add(n) # finish initialization, start monitoring threads for router nodes logging.debug('Starting AODV thread for ' + `node.address`) threads.add(gatherers.rrdtool.AodvThread(node)) # TODO: modularize backends for node in nodes.collection: if (node.type == nodes.ROUTER): if (config.Simulate): logging.debug('Starting SNMP poll thread for ' + `node.address`) threads.add(gatherers.rrdtool.SnmpPollThread(node)) else: logging.debug('Starting simulated SNMP thread for ' + `node.address`) threads.add(gatherers.rrdtool.SimulationPollThread(node)) logging.debug('Starting graphing thread for ' + `node.address`) threads.add(rendering.rrdtool.GraphingThread(node))
logging.error('Error loading plugin:') traceback.print_exc() sys.exit() print 'Loaded plugin', plugin.PLUGIN_INFO['NAME'] try: # set up topology logging.debug('Initializing topology') topology.initialize() # initialize interface indices for monitored nodes # These are router nodes which we have explicitly pointed out to be polled for node in config.Nodes: logging.debug('Initializing node ' + `node`) if nodes.find(node): continue n = nodes.create(node) n.type = nodes.ROUTER nodes.add(n) # do any processing defined by plugin logging.debug('Initializing plugin') plugin.initialize() # start web server logging.debug('Starting web server') threads.add(webserver.WebThread()) # print thread pool status num_threads = threads.size()
def loop_aodv(self): for target in nodes.collection: # BUG: (maybe?) if a node does not have SNMP there's no way # to fetch its SNMP status if target.type != nodes.ROUTER: continue # first, reset neighbours list so we can redetect links target.neighbours = {} ############ text = None global execResults logging.debug('loop_aodv for %s' % target.address) try: execResults[target.address] = \ snmp.walk(target.address, (1,3,6,1,4,1,2021,8)) # try and increase interval if self.interval > 10: self.interval -= 1 except Exception, e: logging.error('Unable to get AODV output for ' + `target.address` + ': ' + `e`) # try and reduce traffic interval if self.interval < 30: self.interval += 1 continue target.aodv_data = \ aodv.parse(str(execResults[target.address][8][0][1])) target.wifi_data = \ wifi.parse(str(execResults[target.address][9][0][1])) for interface in target.aodv_data: # fetch entry for this link entry = target.aodv_data[interface] destaddress = entry['destination'] # check if it already exists dest = nodes.find(destaddress) if dest == None: # add newly discovered nodes to collection dest = nodes.create(destaddress) nodes.add(dest) try: logging.debug(snmp.walk(dest.address, snmp.load_symbol('SNMPv2-MIB', 'sysDescr'))[0][0][1]) # no problems here. this destination supports SNMP dest.type = nodes.ROUTER logging.debug('Starting SNMP poll thread for ' + `dest.address`) threads.add(GathererThread(dest)) logging.debug('Starting graphing thread for ' + `dest.address`) threads.add(rendering.rrd.GraphingThread(dest)) except Exception, e: if e.message == 'requestTimedOut': # assume machine does not have SNM # assume machine does not have SNMP? logging.debug('PROBING %s has timed out!' % dest.address) dest.type = nodes.GENERIC else: # we have a real error! logging.error(e) # also check for AODV gateway nodes gateway = nodes.find(entry['gateway']) if gateway == None: gateway = nodes.create(entry['gateway']) nodes.add(gateway) try: logging.debug(snmp.walk(gateway.address, snmp.load_symbol('SNMPv2-MIB', 'sysDescr'))[0][0][1]) # no problems here. this gateway supports SNMP gateway.type = nodes.ROUTER logging.debug('Starting SNMP poll thread for ' + `gateway.address`) threads.add(GathererThread(gateway)) logging.debug('Starting graphing thread for ' + `gateway.address`) threads.add(rendering.rrd.GraphingThread(gateway)) except Exception, e: if e.message == 'requestTimedOut': # assume machine does not have SNMP? logging.debug('PROBING %s has timed out!' % gateway.address) gateway.type = nodes.GENERIC else: # we have a real error! logging.error(e)
def populate(): for address, details in NODES.items(): # add node to nodes list node = nodes.find(address) if node == None: node = nodes.create(address) nodes.add(node) node.type = nodes.ROUTER # temporary neighbours store node._neighbours = [] # actual store for current neighbours node.neighbours = {} # number of rrdtool databases used node.rrd_files = {} # keep track of incoming/outgoing traffic node.in_octets = {} node.out_octets = {} # set wireless statistics node.linklevel = 50 + random.randint(-25,25) node.signallevel = 50 + random.randint(-25,25) node.noiselevel = 10 # assign node positions # topology.assign(node, details['positions']) # initialize interfaces and neighbouring links for interface, neighbour in details['neighbours'].items(): if neighbour not in NODES.keys(): continue nnode = nodes.find(neighbour) if nnode == None: nnode = nodes.create(neighbour) nodes.add(nnode) # update node's neighbours and initial connections node.neighbours[nnode] = [interface] node._neighbours.append(nnode) if interface not in node.interfaces: node.interfaces.append(interface) # check path to rrdtool database rrd_file = config.RrdTemplate.substitute({ 'dir': config.RrdPath, 'host': node.address, 'if': interface }) if rrd_file in node.rrd_files.values(): continue if not os.path.exists(rrd_file): print 'Creating RRDtool database at ' + `rrd_file` try: rrdtool.create(rrd_file, #'-b now -60s', # Start time now -1 min '-s ' + `config.TrafficInterval`, # interval 'DS:traffic_in:COUNTER:' + `config.TrafficInterval * 2` + ':0:3500000', 'DS:traffic_out:COUNTER:' + `config.TrafficInterval * 2` + ':0:3500000', # wireless 'DS:link:GAUGE:120:U:U', 'DS:signal:GAUGE:120:U:U', 'DS:noise:GAUGE:120:U:U', 'RRA:LAST:0.1:1:720', # 720 samples of 1 minute (12 hours) #'RRA:LAST:0.1:5:576', # 576 samples of 5 minutes (48 hours) 'RRA:AVERAGE:0.1:1:720', # 720 samples of 1 minute (12 hours) #'RRA:AVERAGE:0.1:5:576', # 576 samples of 5 minutes (48 hours) 'RRA:MAX:0.1:1:720' # 720 samples of 1 minute (12 hours) #'RRA:MAX:0.1:5:576' # 576 samples of 5 minutes (48 hours) ) except rrdtool.error, e: # this should be quite serious. Handle immediately! logging.error(e) raise Exception, 'Unable to create RRDtool database!' else: print node.address, 'using RRDtool database at ', rrd_file node.rrd_files[interface] = rrd_file node.interfaces.sort() node._neighbours.sort(lambda nodex, nodey: nodex.address < nodey.address and -1 or 1)