forked from freifunk-mwu/backend-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_traffic_all.py
executable file
·74 lines (64 loc) · 2.28 KB
/
draw_traffic_all.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
IMAGE = '''
<img src="${image}" alt="${interface} - ${itype}" /><br />
'''
IFBLOCK = '''
\t<div class="ifblock" onclick="toggle('${interface}')">
\t\t<h2>${interface}</h2>
\t\t<div class="ifimg" id="${interface}">
\t\t\t${images}
\t\t</div>
\t</div>
'''
def draw_traffic():
from os import path
from photon.util.locations import search_location
from common import pinit
from common.html import page
photon, settings = pinit('draw_traffic', verbose=True)
traffic = '<small>click to show or hide</small><br />'
avail_if = photon.m(
'checking for available interfaces',
cmdd=dict(
cmd='sudo vnstat --iflist'
)
).get('out', '')
interfaces = settings['web']['traffic']['interfaces'] + [settings['fastd'][community]['interface'] for community in settings['fastd'].keys()]
for interface in interfaces:
if interface in avail_if:
if not search_location(path.join(settings['web']['traffic']['dbdir'], interface)):
photon.m(
'creating vnstat db for %s' %(interface),
cmdd=dict(
cmd='sudo vnstat -u -i %s' %(interface)
),
verbose=True
)
images = ''
for flag, itype in settings['web']['traffic']['types']:
image = '%s-%s.png' %(interface, itype)
photon.m(
'drawing %s graph for %s' %(itype, interface),
cmdd=dict(
cmd='vnstati -i %s -%s -o %s' %(interface, flag, path.join(settings['web']['output'], 'traffic', image))
),
critical=False
)
images += photon.template_handler(
IMAGE,
fields=dict(
interface=interface,
itype=itype,
image=image
)
).sub
traffic += photon.template_handler(
IFBLOCK,
fields=dict(
interface=interface,
images=images
)
).sub
page(photon, traffic, sub='traffic')
if __name__ == '__main__':
draw_traffic()