Add files via upload

This commit is contained in:
Robert Chacón 2022-02-06 20:11:22 -07:00 committed by GitHub
parent 8cf90c29a9
commit 989133fe99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ from operator import itemgetter
from prettytable import PrettyTable from prettytable import PrettyTable
from ispConfig import fqOrCAKE, interfaceA, interfaceB from ispConfig import fqOrCAKE, interfaceA, interfaceB
import decimal import decimal
from itertools import groupby
def getStatistics(): def getStatistics():
with open('qdiscs.json', 'r') as infile: with open('qdiscs.json', 'r') as infile:
@ -25,13 +26,17 @@ def getStatistics():
packets = int(jsonVersion[0]['packets']) packets = int(jsonVersion[0]['packets'])
bytesSent = int(jsonVersion[0]['bytes']) bytesSent = int(jsonVersion[0]['bytes'])
packetLoss = round((drops/packets),6) packetLoss = round((drops/packets),6)
if interface == interfaceB: if interface == interfaceA:
device['packetLossDownload'] = packetLoss device['packetLossDownload'] = packetLoss
device['bytesSentDownload'] = bytesSent device['bytesSentDownload'] = bytesSent
device['packetsDownload'] = packets
device['dropsDownload'] = drops
device['foundStats'] = True device['foundStats'] = True
else: else:
device['packetLossUpload'] = packetLoss device['packetLossUpload'] = packetLoss
device['bytesSentUpload'] = bytesSent device['bytesSentUpload'] = bytesSent
device['packetsUpload'] = packets
device['dropsUpload'] = drops
device['foundStats'] = True device['foundStats'] = True
except: except:
print("Failed to retrieve stats for device " + device['hostname']) print("Failed to retrieve stats for device " + device['hostname'])
@ -46,28 +51,79 @@ if __name__ == '__main__':
devices = getStatistics() devices = getStatistics()
# Display table of Customer CPEs with most packets dropped # Display table of Customer CPEs with most packets dropped
x = PrettyTable() x = PrettyTable()
x.field_names = ["Hostname", "ParentNode", "IPv4", "IPv6", "DL Dropped", "UL Dropped", "GB Down/Up"] x.field_names = ["Hostname", "ParentNode", "IPv4", "IPv6", "DL Dropped", "UL Dropped", "Avg Dropped", "GB Down", "GB Up"]
sortableList = [] sortableList = []
pickTop = 30 pickTopCPEs = 5
pickTopAPs = 10
for device in devices: for device in devices:
name = device['hostname'] name = device['hostname']
AP = device['ParentNode'] ParentNode = device['ParentNode']
ipv4 = device['ipv4'] ipv4 = device['ipv4']
ipv6 = device['ipv6'] ipv6 = device['ipv6']
packetLossDownload = device['packetLossDownload'] packetLossDownload = device['packetLossDownload']
packetLossUpload = device['packetLossUpload'] packetLossUpload = device['packetLossUpload']
GBdownloadedString = str(round((device['bytesSentDownload']/1000000000),3)) GBdownloadedString = str(round((device['bytesSentDownload']/1000000000),3))
GBuploadedString = str(round((device['bytesSentUpload']/1000000000),3)) GBuploadedString = str(round((device['bytesSentUpload']/1000000000),3))
GBstring = GBuploadedString + '/' + GBdownloadedString GBstring = GBdownloadedString + '/' + GBuploadedString
avgDropped = (packetLossDownload + packetLossUpload)/2 avgDropped = round((packetLossDownload + packetLossUpload)/2,3)
sortableList.append((name, AP, ipv4, ipv6, packetLossDownload, packetLossUpload, avgDropped, GBstring)) sortableList.append((name, ParentNode, ipv4, ipv6, packetLossDownload, packetLossUpload, avgDropped, GBdownloadedString, GBuploadedString))
res = sorted(sortableList, key = itemgetter(4), reverse = True)[:pickTop] res = sorted(sortableList, key = itemgetter(4), reverse = True)[:pickTopCPEs]
for stat in res: for stat in res:
name, AP, ipv4, ipv6, packetLossDownload, packetLossUpload, avgDropped, GBstring = stat name, AP, ipv4, ipv6, packetLossDownload, packetLossUpload, avgDropped, GBdownloadedString, GBuploadedString = stat
if not name: if not name:
name = ipv4 name = ipv4
downloadDroppedString = "{0:.3%}".format(packetLossDownload) downloadDroppedString = "{0:.3%}".format(packetLossDownload)
uploadDroppedString = "{0:.3%}".format(packetLossUpload) uploadDroppedString = "{0:.3%}".format(packetLossUpload)
x.add_row([name, AP, ipv4, ipv6, downloadDroppedString, uploadDroppedString, GBstring]) avgDroppedString = "{0:.3%}".format(avgDropped)
x.add_row([name, AP, ipv4, ipv6, downloadDroppedString, uploadDroppedString, avgDroppedString, GBdownloadedString, GBuploadedString])
print(x)
listOfParentNodes = []
listOfParentNodesWithStats = []
for device in devices:
if device['ParentNode'] not in listOfParentNodes:
listOfParentNodes.append(device['ParentNode'])
for parentNode in listOfParentNodes:
bytesSentDownloadDropped = 0
bytesSentUploadDropped = 0
bytesSentDownload = 0
bytesSentUpload = 0
packetsDownload = 0
packetsUpload = 0
packetsDownloadDropped = 0
packetsUploadDropped = 0
counter = 0
for device in devices:
if device['ParentNode'] == parentNode:
bytesSentDownload += device['bytesSentDownload']
bytesSentUpload += device['bytesSentUpload']
packetsDownload += device['packetsDownload']
packetsUpload += device['packetsUpload']
packetsDownloadDropped += device['dropsDownload']
packetsUploadDropped += device['dropsUpload']
counter += 1
if bytesSentDownload > 0:
packetLossDownload = round(packetsDownloadDropped/packetsDownload,5)
else:
packetLossDownload = 0
if bytesSentUpload > 0:
packetLossUpload = round(packetsUploadDropped/packetsUpload,5)
else:
packetLossUpload = 0
GBdownload = round((bytesSentDownload/1000000000),3)
GBupload = round((bytesSentUpload/1000000000),3)
packetLossAvg = (packetLossDownload+packetLossUpload)/2
listOfParentNodesWithStats.append((parentNode,packetLossDownload,packetLossUpload,packetLossAvg, GBdownload,GBupload))
res = sorted(listOfParentNodesWithStats, key = itemgetter(3), reverse = True)[:pickTopAPs]
x = PrettyTable()
x.field_names = ["ParentNode", "Download Dropped", "Upload Dropped", "Avg Dropped", "GB Down", "GB Up"]
for stat in res:
parentNode,packetLossDownload,packetLossUpload,packetLossAvg, GBdownload,GBupload = stat
packetLossDownloadString = "{0:.3%}".format(packetLossDownload)
packetLossUploadString = "{0:.3%}".format(packetLossUpload)
avgLossString = "{0:.3%}".format(packetLossAvg)
x.add_row([parentNode,packetLossDownloadString,packetLossUploadString,avgLossString, GBdownload,GBupload])
print(x) print(x)