From 35c9a0df67a03fff79cf05159a637ca003fe048b Mon Sep 17 00:00:00 2001 From: EUcancER Date: Tue, 8 Nov 2011 12:37:32 +0100 Subject: add script to find legacy hosts --- retiolum/scripts/adv_graphgen/find_legacy_hosts.py | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 retiolum/scripts/adv_graphgen/find_legacy_hosts.py (limited to 'retiolum/scripts/adv_graphgen/find_legacy_hosts.py') diff --git a/retiolum/scripts/adv_graphgen/find_legacy_hosts.py b/retiolum/scripts/adv_graphgen/find_legacy_hosts.py new file mode 100755 index 00000000..52388b6d --- /dev/null +++ b/retiolum/scripts/adv_graphgen/find_legacy_hosts.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- + +import sys,json +""" TODO: Refactoring needed to pull the edges out of the node structures again, +it should be easier to handle both structures""" +DUMP_FILE = "/krebs/db/availability" + +def get_all_nodes(): + import os + return os.listdir("/etc/tinc/retiolum/hosts") +def generate_stats(): + """ Generates some statistics of the network and nodes + """ + import json + jlines = [] + try: + f = open(DUMP_FILE,'r') + for line in f: + jlines.append(json.loads(line)) + f.close() + except Exception,e: + pass + all_nodes = {} + for k in get_all_nodes(): + all_nodes[k] = get_node_availability(k,jlines) + print ( json.dumps(all_nodes)) + +def get_node_availability(name,jlines): + """ calculates the node availability by reading the generated dump file + adding together the uptime of the node and returning the time + parms: + name - node name + jlines - list of already parsed dictionaries node archive + """ + begin = last = current = 0 + uptime = 0 + #sys.stderr.write ( "Getting Node availability of %s\n" % name) + for stat in jlines: + if not stat['nodes']: + continue + ts = stat['timestamp'] + if not begin: + begin = last = ts + current = ts + if stat['nodes'].get(name,{}).get('to',[]): + uptime += current - last + else: + pass + #sys.stderr.write("%s offline at timestamp %f\n" %(name,current)) + last = ts + all_the_time = last - begin + try: + return uptime/ all_the_time + except: + return 1 + + +generate_stats() -- cgit v1.2.3