- Timestamp:
- Feb 18, 2012, 9:38:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/make-network-graph.py
r9809 r9989 11 11 import sys 12 12 import tempfile 13 import yaml 13 14 14 15 OUTFILE = os.path.join(os.getcwd(),'network.png') 16 17 store = yaml.load(open('store.yaml','r')) 15 18 16 19 def make_graph(): 17 20 poel = {} 18 21 link_type = {} 22 link_data = {} 19 23 try: 20 24 for host in gformat.get_hostlist(): … … 37 41 else: 38 42 poel[addr] = [host] 39 # Assume all eth2wifibridgeto be 11a for a moment40 if datadump[iface_key].has_key(' eth2wifibridge'):43 # Assume all ns_ip to be 11a for a moment 44 if datadump[iface_key].has_key('ns_ip'): 41 45 link_type[addr] = '11a' 42 46 else: 43 47 link_type[addr] = datadump[iface_key]['type'] 48 49 link_data[addr] = 1 50 iface = datadump[iface_key]['interface'] 51 nodename = datadump['nodename'] 52 print nodename, iface 53 INTERVAL = 60 * 10 54 if store['uptime'].has_key(nodename) and store['snmp'].has_key(nodename) and store['traffic'].has_key(nodename): 55 if store['traffic'][nodename].has_key(iface): 56 (b_in, b_out) = store['traffic'][nodename][iface] 57 uptime = store['uptime'][nodename] 58 t_kb = float(b_in + b_out) / 1024 59 print "# INFO: Found %s kB in %s seconds" % (t_kb, INTERVAL) 60 retval = ((t_kb) / uptime) * INTERVAL 61 link_data[addr] = retval 62 44 63 print "### %s [%s] is of type %s" % (gformat.showaddr(addr), iface_key, link_type[addr]) 45 64 except (KeyError, ValueError), e: … … 48 67 sys.exit(1) 49 68 50 f = tempfile.NamedTemporaryFile(bufsize=0) 69 #f = tempfile.NamedTemporaryFile(bufsize=0) 70 f = open('/tmp/test.dot','w') 51 71 sys.stderr.write("# Building temponary graph file\n") 52 72 print >> f, "Graph WirelessLeidenNetwork {" … … 59 79 for addr,leden in poel.iteritems(): 60 80 if link_type[addr] == '11a': 61 color = ' red'81 color = 'green' 62 82 weight = 4 63 83 elif link_type[addr] == 'eth': … … 67 87 color = 'black' 68 88 weight = 1 89 width = max(1,link_data[addr]) 69 90 leden = sorted(set(leden)) 70 91 for index,lid in enumerate(leden[:-1]): 71 92 for buur in leden[index + 1:]: 72 print >> f,' %s -- %s [label="%s", color="%s", weight="%s" ]' % (lid, buur, gformat.showaddr(addr), color, weight)93 print >> f,' %s -- %s [label="%s", color="%s", weight="%s", style="setlinewidth(%s)"]' % (lid, buur, gformat.showaddr(addr), color, weight, width) 73 94 print >> f, "}" 95 f.flush() 74 96 sys.stderr.write("# Plotting temponary graph file using graphviz\n") 75 97 retval = subprocess.call(["neato","-Tpng",f.name, "-o", OUTFILE])
Note:
See TracChangeset
for help on using the changeset viewer.