-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParser.py
More file actions
31 lines (27 loc) · 1.16 KB
/
Parser.py
File metadata and controls
31 lines (27 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Assumes the output file is already in the folder
from math import floor
import json
import sys
class Parser:
""" A class to extract any useful information from the iperf3
json output. Then users can access whatever fields they
are interested in. """
def __init__(self):
self.bps = 0
self.bytes = 0
self.runLength = 0
self.intervalBPS = []
self.intervalLength = 0
self.hostUtilization = 0
self.remoteUtilization = 0
def extract(self, file):
with open(file) as dataFile:
data = json.load(dataFile)
self.bps = data['end']['sum_received']['bits_per_second']
self.bytes = data['end']['sum_received']['bytes']
self.runLength = data['end']['sum_received']['seconds']
self.hostUtilization = data['end']['cpu_utilization_percent']['host_total'] / 100.0
self.remoteUtilization = data['end']['cpu_utilization_percent']['remote_total'] / 100.0
self.intervalLength = floor(data['intervals'][0]['sum']['seconds'])
for i in xrange(len(data['intervals'])):
self.intervalBPS.append(data['intervals'][i]['sum']['bits_per_second'])