32 lines
		
	
	
		
			708 B
		
	
	
	
		
			Python
		
	
	
	
	
	
		
		
			
		
	
	
			32 lines
		
	
	
		
			708 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| 
								 | 
							
								def get_iperf3_stats(s):
							 | 
						||
| 
								 | 
							
								    pool = s.split("\n")
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    stats = []
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    interpret_stats = False
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    for i in pool:
							 | 
						||
| 
								 | 
							
								        c = i.split()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if 'ID]' in c:
							 | 
						||
| 
								 | 
							
								            interpret_stats = True
							 | 
						||
| 
								 | 
							
								            continue
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if '-' in c:
							 | 
						||
| 
								 | 
							
								            interpret_stats = False
							 | 
						||
| 
								 | 
							
								            break
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        if interpret_stats:
							 | 
						||
| 
								 | 
							
								            if len(c) < 8:
							 | 
						||
| 
								 | 
							
								                continue
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            stat = {}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            stat['int_start'], stat['int_end'] = list(map(float, c[2].split('-')))
							 | 
						||
| 
								 | 
							
								            stat['transfer'] = float(c[4]) * 1024 ** ['B', 'K', 'M', 'G'].index(c[5][0])
							 | 
						||
| 
								 | 
							
								            stat['bitrate'] = float(c[6]) * 1024 ** ['b', 'K', 'M', 'G'].index(c[7][0])
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            stats.append(stat)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return stats
							 |