annotate speedcheck.py @ 36:5dbc310f1eca

Fix uptime parser broken by previous commit. Add comment about it while I'm here.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 17 Nov 2020 15:47:56 +1030
parents 815e6b61d76e
children 1a87c79cf103
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
815e6b61d76e Decode to string to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
1 #!/usr/bin/env python3
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
3 import configparser
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 import optparse
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 import os
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 import re
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 import rrdtool
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 import subprocess
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 import time
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 def main():
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
12 conf = configparser.ConfigParser()
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 conflist = []
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 if ('HOME' in os.environ):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 conflist.append(os.path.expanduser('~/.speedcheck.ini'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 conf.read(conflist)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 usage = '''%prog [options]'''
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 parser = optparse.OptionParser(usage)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 parser.add_option('-v', '--verbose', action="store_true", default=False,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 help="Enable debug output")
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 parser.add_option('-r', '--rrd', action="store", help="Path to RRD")
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 parser.add_option('-g', '--graphdir', action="store", help="Directory for graphs")
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 (opts, args) = parser.parse_args()
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 if opts.rrd == None:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 if conf.has_option('global', 'rrd'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 opts.rrd = conf.get('global', 'rrd')
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 else:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 parser.error('Path to RRD must be specified in either the ini or on the command line')
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 if opts.graphdir == None:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 if conf.has_option('global', 'graphdir'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 opts.graphdir = conf.get('global', 'graphdir')
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 else:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 parser.error('Graph directory must be specified in either the ini or on the command line')
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 if opts.verbose:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
40 print('Fetching stats...')
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 stats = fetchstats(conf)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 if opts.verbose:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
43 print(stats)
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 if opts.verbose:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
45 print('Updating RRD')
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 updaterrd(opts.rrd, stats)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 if opts.verbose:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
48 print('Updating graph')
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 graphrrd(opts.rrd, opts.graphdir)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 def fetchstats(conf):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 stats = {}
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 if conf.has_option('global', 'neardl'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 stats['neardl'] = testdl(conf.get('global', 'neardl'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 if conf.has_option('global', 'nearul'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 stats['nearul'] = testul(conf.get('global', 'nearul'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 if conf.has_option('global', 'nearping'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 stats['nearpl'], stats['nearlat'] = testping(conf.get('global', 'nearping'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 if conf.has_option('global', 'fardl'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 stats['fardl'] = testdl(conf.get('global', 'fardl'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 if conf.has_option('global', 'farul'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 stats['farul'] = testul(conf.get('global', 'farul'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 if conf.has_option('global', 'farping'):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 stats['farpl'], stats['farlat'] = testping(conf.get('global', 'farping'))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 return stats
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 def testdl(url):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 p = subprocess.Popen(['curl', '-w', '%{speed_download}', '-so', '/dev/null', url], stdout = subprocess.PIPE)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 speed, xxx = p.communicate()
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 if p.returncode != 0:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
72 print('Error %d fetching \'%s\'' % (p.returncode, url))
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 return None
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 return float(speed) * 8.0 / 1024.0 # convert to kbit/sec
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 def testping(host):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 p = subprocess.Popen(['ping', '-c', '5', '-t', '8', '-q', host], stdout = subprocess.PIPE)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 stdout, stderr = p.communicate()
35
815e6b61d76e Decode to string to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
79 l = stdout.decode('ascii', 'ignore').split('\n')
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 if len(l) != 6:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
81 print('Unable to parse ping line:', l)
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 xx, xx, xx, plossline, latline, xx = l
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 ploss = float(re.match('.* received, ([0-9.]+)% packet loss', plossline).groups()[0])
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 latency = float(re.match('.*stddev = [0-9.]+/([0-9.]+)/.* ms', latline).groups()[0])
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 return ploss, latency
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 def createrrd(rrdname):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88 # Create RRD for upstream/downstream speed, packet loss and
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 # latency for near and far site
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 # Do a test every half and hour
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 # Average 2 for hourly stats (keep 168 - a weeks worth)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92 # Average 48 for hourly stats (keep 1825 - 5 years worth)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 # Detemine minimum & maximum for an hour and keep a weeks worth.
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 rrdtool.create(rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 '--step', '300',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 'DS:neardl:GAUGE:3600:0:U',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 'DS:nearul:GAUGE:3600:0:U',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 'DS:nearpl:GAUGE:3600:0:100',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 'DS:nearlat:GAUGE:3600:0:U',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 'DS:fardl:GAUGE:3600:0:U',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 'DS:farul:GAUGE:3600:0:U',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 'DS:farpl:GAUGE:3600:0:100',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 'DS:farlat:GAUGE:3600:0:U',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 'RRA:AVERAGE:0.1:2:168',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 'RRA:AVERAGE:0.1:48:1825',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 'RRA:MIN:0.1:2:168',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 'RRA:MAX:0.1:2:168',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 )
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 def updaterrd(rrdname, stats):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 try:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 os.stat(rrdname)
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
113 except OSError as e:
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 if e.errno == 2:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 29
diff changeset
115 print('Creating RRD...')
28
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 createrrd(rrdname)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
117 s = '%d:' % (int(time.time()))
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 for a in ['neardl', 'nearul', 'nearpl', 'nearlat', 'fardl', 'farul', 'farpl', 'farlat']:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 if a in stats:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 s += '%f:' % (stats[a])
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 else:
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 s += 'U:'
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 s = s[0:-1]
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 rrdtool.update(rrdname, s)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 def graphrrd(rrdname, graphdir):
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 latencyargs = (
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 '-a', 'SVG',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 '--vertical-label', 'milliseconds',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 'DEF:nearlat=%s:nearlat:AVERAGE' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 'DEF:nearlatmin=%s:nearlat:MIN' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 'DEF:nearlatmax=%s:nearlat:MAX' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134 'CDEF:nearlatdif=nearlatmax,nearlatmin,-',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 'LINE0.001:nearlatmin#000000:',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137 'AREA:nearlatdif#00dc76::STACK',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 'LINE1:nearlatmax#00ff00:Near latency',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
140 'DEF:farlat=%s:farlat:AVERAGE' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
141 'DEF:farlatmin=%s:farlat:MIN' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
142 'DEF:farlatmax=%s:farlat:MAX' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
143 'CDEF:farlatdif=farlatmax,farlatmin,-',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 'LINE0.001:farlatmin#000000:',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 'AREA:farlatdif#dc0076::STACK',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 'LINE1:farlatmax#ff0000:Far packetloss',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 'DEF:nearpl=%s:nearpl:AVERAGE' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 'LINE1:nearpl#0000ff:Near packet loss (%)',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
151
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 'DEF:farpl=%s:farpl:AVERAGE' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 'LINE1:nearpl#ffff00:Far packet loss (%)',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 )
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155 rrdtool.graph('%s/latency-hour-link.svg' % (graphdir),
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 '--width', '768',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 '--height', '256',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 '--start', 'end - 7d',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159 '--end', 'now',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 *latencyargs)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 rrdtool.graph('%s/latency-daily-link.svg' % (graphdir),
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 '--width', '768',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163 '--height', '256',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 '--start', 'end - 365d',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165 '--end', 'now',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 *latencyargs)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
168 bwargs = (
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
169 '-a', 'SVG',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
170 '-X', '0',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
171 '--vertical-label', 'kbit/sec',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
172
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
173 'DEF:neardl=%s:neardl:AVERAGE' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
174 'DEF:neardlmin=%s:neardl:MIN' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
175 'DEF:neardlmax=%s:neardl:MAX' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
176 'CDEF:neardldif=neardlmax,neardlmin,-',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
177
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
178 'LINE0.001:neardlmin#000000:',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
179 'AREA:neardldif#00dc76::STACK',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
180 'LINE1:neardlmax#00ff00:Near download',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
181
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 'DEF:fardl=%s:fardl:AVERAGE' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
183 'DEF:fardlmin=%s:fardl:MIN' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
184 'DEF:fardlmax=%s:fardl:MAX' % rrdname,
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
185 'CDEF:fardldif=fardlmax,fardlmin,-',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
186
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
187 'LINE0.001:fardlmin#000000:',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
188 'AREA:fardldif#dc0076::STACK',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 'LINE1:fardlmax#ff0000:Far download',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190 )
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191 rrdtool.graph('%s/bw-hour-link.svg' % (graphdir),
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 '--width', '768',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
193 '--height', '256',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
194 '--start', 'end - 1d',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
195 '--end', 'now',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
196 *bwargs)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
197 rrdtool.graph('%s/bw-daily-link.svg' % (graphdir),
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
198 '--width', '768',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
199 '--height', '256',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
200 '--start', 'end - 7d',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
201 '--end', 'now',
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
202 *bwargs)
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
203
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
204 if __name__ == '__main__':
b474c873357d add speed check script
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
205 main()