Changeset 9989 in genesis


Ignore:
Timestamp:
Feb 18, 2012, 9:38:29 PM (13 years ago)
Author:
rick
Message:

Hack the data visualisation in here as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/make-network-graph.py

    r9809 r9989  
    1111import sys
    1212import tempfile
     13import yaml
    1314
    1415OUTFILE = os.path.join(os.getcwd(),'network.png')
     16
     17store = yaml.load(open('store.yaml','r'))
    1518
    1619def make_graph():
    1720  poel = {}
    1821  link_type = {}
     22  link_data = {}
    1923  try:
    2024    for host in gformat.get_hostlist():
     
    3741        else:
    3842          poel[addr] = [host]
    39           # Assume all eth2wifibridge to be 11a for a moment
    40           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'):
    4145            link_type[addr] = '11a'
    4246          else:
    4347            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
    4463          print "### %s [%s] is of type %s" % (gformat.showaddr(addr), iface_key, link_type[addr])
    4564  except (KeyError, ValueError), e:
     
    4867    sys.exit(1)
    4968
    50   f = tempfile.NamedTemporaryFile(bufsize=0)
     69  #f = tempfile.NamedTemporaryFile(bufsize=0)
     70  f = open('/tmp/test.dot','w')
    5171  sys.stderr.write("# Building temponary graph file\n")
    5272  print >> f, "Graph WirelessLeidenNetwork {"
     
    5979  for addr,leden in poel.iteritems():
    6080    if link_type[addr] == '11a':
    61       color = 'red'
     81      color = 'green'
    6282      weight = 4
    6383    elif link_type[addr] == 'eth':
     
    6787      color = 'black'
    6888      weight = 1
     89    width = max(1,link_data[addr])
    6990    leden = sorted(set(leden))
    7091    for index,lid in enumerate(leden[:-1]):
    7192      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)
    7394  print >> f, "}"
     95  f.flush()
    7496  sys.stderr.write("# Plotting temponary graph file using graphviz\n")
    7597  retval = subprocess.call(["neato","-Tpng",f.name, "-o", OUTFILE])
Note: See TracChangeset for help on using the changeset viewer.