-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
57 lines (38 loc) · 1.16 KB
/
test.py
File metadata and controls
57 lines (38 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import pprint
os.system("vnstat -d --dumpdb -i eth0 > /tmp/data.txt")
file = open('data.txt','r')
day = []
month = []
top = []
for line in file:
explode = line.split('\n')[0]
vstatdata = explode.strip().split(';')
if(vstatdata[0] == 'd'):
template = {}
template['time'] = vstatdata[2]
template['rx'] = int(vstatdata[3]) * 1024 + int(vstatdata[5])
template['tx'] = int(vstatdata[4]) * 1024 + int(vstatdata[6])
template['act'] = vstatdata[7]
day.append(template)
elif(vstatdata[0] == 'm'):
template = {}
template['time'] = vstatdata[2]
template['rx'] = int(vstatdata[3]) * 1024 + int(vstatdata[5])
template['tx'] = int(vstatdata[4]) * 1024 + int(vstatdata[6])
template['act'] = vstatdata[7]
month.append(template)
elif(vstatdata[0] == 't'):
template = {}
template['time'] = vstatdata[2]
template['rx'] = int(vstatdata[3]) * 1024 + int(vstatdata[5])
template['tx'] = int(vstatdata[4]) * 1024 + int(vstatdata[6])
template['act'] = vstatdata[7]
top.append(template)
print "\nmonth:\n"
pprint.pprint(month)
print "\ndays:\n"
pprint.pprint(day)
print "\ntop:\n"
pprint.pprint(top)
os.remove('/tmp/data.txt')