Implemented export of statistic files and first version of statistics file

This commit is contained in:
Simon Wüllhorst 2015-12-23 17:35:55 +01:00
parent 52efe6a7f0
commit 48d4fca08b
3 changed files with 108 additions and 4 deletions

View file

@ -14,11 +14,13 @@ class DomainSelector:
self.graph = Graph(self.nodesData, self.graphData) self.graph = Graph(self.nodesData, self.graphData)
if self.targets == None: if self.targets == None:
self.writeConfigFiles(self.graph.nodes_list,"all") self.writeConfigFiles(self.graph.nodes_list,"all")
self.writeDumpFile(self.graph.nodes_list,"all")
else: else:
nodes = {} nodes = {}
for k,v in self.targets.iteritems(): for k,v in self.targets.iteritems():
nodes = self.graph.getNodeCloudsIn(v) nodes = self.graph.getNodeCloudsIn(v)
self.writeConfigFiles(nodes,k) self.writeConfigFiles(nodes,k)
self.writeDumpFile(nodes,k)
nodes = {} nodes = {}
def __getFile__(self, nodesFile): def __getFile__(self, nodesFile):
@ -34,12 +36,12 @@ class DomainSelector:
resource.close() resource.close()
return data return data
def writeConfigFiles(self,nodes_level, name): def writeConfigFiles(self, nodes, name):
maxDepth = self.maxDepth(nodes_level) maxDepth = self.maxDepth(nodes)
for i in range(0,maxDepth): for i in range(0,maxDepth):
content = 'geo $switch {\n\tdefault\t0;' content = 'geo $switch {\n\tdefault\t0;'
f = open(self.dataPath+'/'+name+'_node_level'+str(i),'w') f = open(self.dataPath+'/'+name+'_node_level'+str(i),'w')
for node in nodes_level.itervalues(): for node in nodes.itervalues():
if node.stepsToVpn == i: if node.stepsToVpn == i:
if node.ipv6 and node.hostname: if node.ipv6 and node.hostname:
content += '\n\t'+node.ipv6+'\t1;\t #'+node.hostname content += '\n\t'+node.ipv6+'\t1;\t #'+node.hostname
@ -49,6 +51,19 @@ class DomainSelector:
f.write(content.encode('utf8')) f.write(content.encode('utf8'))
f.close() f.close()
def writeDumpFile(self, nodes, name):
content = {}
for node in nodes.itervalues():
if node.ipv6 and node.hostname:
content[node.nodeid] = {
'nodeid' : node.nodeid,
'ipv6' : node.ipv6,
'hostname' : node.hostname,
'level' : node.stepsToVpn,
}
with open(self.dataPath+'/'+name+'_node_statistics.json', 'w') as outfile:
json.dump(content, outfile)
def maxDepth(self, nodes): def maxDepth(self, nodes):
maxDepth = 0 maxDepth = 0
for v in nodes.itervalues(): for v in nodes.itervalues():

View file

@ -1,7 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 - # -*- coding: utf-8 -
#Imports: #Imports:
import json
from domain_selector import DomainSelector from domain_selector import DomainSelector
targets = { targets = {

90
track_statistics.py Executable file
View file

@ -0,0 +1,90 @@
#!/usr/bin/python
# -*- coding: utf-8 -
#Imports:
import json
import operator
class TrackStatistics:
def __init__(self,nodesFile,statisticsFiles, printStatus = False):
self.printStatus = printStatus
self.nodesData = self.__getFile__(nodesFile)
self.statisticsData = []
for entry in statisticsFiles:
self.statisticsData.append({'data' : self.__getFile__(entry['data']), 'name' : entry['name']})
#print self.statisticsData
for domain in self.statisticsData:
self.printDomainStatisticsPerLevel(domain['data'], domain['name'])
def printDomainStatisticsPerLevel(self,data, name = "not set"):
#firmwareVersion = {}
print '-'*50
print 'Printing statistics for domain:', name
for level in range(0,self.maxDepth(data)):
firmwareVersion = {}
for nodeid, node in data.iteritems():
if level == node['level']:
fwver = self.nodesData['nodes'][nodeid]['nodeinfo']['software']['firmware']['release']
if fwver in firmwareVersion:
firmwareVersion[fwver] += 1
else:
firmwareVersion[fwver] = 1
print '\tLevel:',level
for k,v in sorted(firmwareVersion.items(), key=operator.itemgetter(1), reverse = True):
print '\t\t '+k+':\t'+str(v)
print '-'*50
def maxDepth(self, nodes):
maxDepth = 0
for v in nodes.itervalues():
if v['level'] > maxDepth:
maxDepth = v['level']
return maxDepth+1
def __getFile__(self, nodesFile):
if nodesFile.startswith('https://') or nodesFile.startswith('http://'):
if self.printStatus:
print "Download node.json from URL: " + nodesFile
resource = urllib.urlopen(nodesFile)
else:
if self.printStatus:
print "Open node.json file: " + nodesFile
resource = open(nodesFile)
data = json.loads(resource.read())
resource.close()
return data
data = [
{
'data' : '../domaenensplit_webserver_config/muenster_sued_node_statistics.json',
'name' : 'Münster Süd'
},
{
'data' : '../domaenensplit_webserver_config/muenster_stadt_node_statistics.json',
'name' : 'Münster Stadt'
},
{
'data' : '../domaenensplit_webserver_config/kreis_coesfeld_node_statistics.json',
'name' : 'Kreis Coesfeld'
},
{
'data' : '../domaenensplit_webserver_config/kreis_warendorf_node_statistics.json',
'name' : 'Kreis Warendorf'
},
{
'data' : '../domaenensplit_webserver_config/kreis_steinfurt_ost_node_statistics.json',
'name' : 'Kreis Steinfurt Ost'
},
{
'data' : '../domaenensplit_webserver_config/kreis_steinfurt_west_node_statistics.json',
'name' : 'Kreis Steinfurt West'
},
{
'data' : '../domaenensplit_webserver_config/kreis_borken_node_statistics.json',
'name' : 'Kreis Borken'
},
]
stat = TrackStatistics('nodes.json', data, printStatus = True)