Mercurial > ~darius > hgwebdir.cgi > adslstats
annotate adslstats.py @ 17:43f54da8baf9
Add max sync speeds to munin (untested)
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 20 May 2016 15:18:59 +0930 |
parents | 425d02592dce |
children | ec994073f70a |
rev | line source |
---|---|
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
1 #!/usr/bin/env python2 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
2 ############################################################################ |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
3 # |
16 | 4 # Parse DSL link stats for TP-Link W9970 & generate RRD archives & graphs |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
5 # |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
6 ############################################################################ |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
7 # |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
8 # Copyright (C) 2015 Daniel O'Connor. All rights reserved. |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
9 # |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
10 # Redistribution and use in source and binary forms, with or without |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
11 # modification, are permitted provided that the following conditions |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
12 # are met: |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
13 # 1. Redistributions of source code must retain the above copyright |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
14 # notice, this list of conditions and the following disclaimer. |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
15 # 2. Redistributions in binary form must reproduce the above copyright |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
16 # notice, this list of conditions and the following disclaimer in the |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
17 # documentation and/or other materials provided with the distribution. |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
18 # |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
19 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
22 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
29 # SUCH DAMAGE. |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
30 # |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
31 ############################################################################ |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
32 |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
33 import base64 |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
34 import ConfigParser |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
35 import optparse |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
36 import os |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
37 import re |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
38 import requests |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
39 import rrdtool |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
40 import sys |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
41 import time |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
42 import urllib |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
43 from bs4 import BeautifulSoup |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
44 |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
45 conf = ConfigParser.ConfigParser() |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
46 conf.add_section('global') |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
47 conf.set('global', 'username', 'admin') |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
48 conf.set('global', 'password', 'admin') |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
49 conf.set('global', 'name', '10.0.2.13') |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
50 |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
51 conflist = ['adslstats.ini'] |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
52 if ('HOME' in os.environ): |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
53 conflist.append(os.path.expanduser('~/.adslstats.ini')) |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
54 conf.read(conflist) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
55 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
56 usage = '''%prog [options]''' |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
57 opts = optparse.OptionParser(usage) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
58 opts.add_option('-v', '--verbose', action="store_true", default=False, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
59 help="Enable debug output") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
60 opts.add_option('-g', '--graph', action="store_true", default=False, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
61 help="Generate a graph") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
62 opts.add_option('-u', '--update', action="store_true", default=False, |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
63 help="Update RRD (implies -d)") |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
64 opts.add_option('-m', '--munin', action="store", default=None, |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
65 help="Output munin data for ARG") |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
66 opts.add_option('-a', '--authname', action="store", default=conf.get('global', 'username'), |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
67 help="Username to login to modem") |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
68 opts.add_option('-p', '--password', action="store", default=conf.get('global', 'password'), |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
69 help="Password to login to modem") |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
70 opts.add_option('-n', '--name', action="store", default=conf.get('global', 'name'), |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
71 help="Hostname of modem") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
72 opts.add_option('-b', '--base', action="store", default="/home/darius/projects/adslstats/adslstats", |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
73 help="Base directory for RRD & PNGs") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
74 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
75 (options, args) = opts.parse_args() |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
76 |
4
f50214bca1ae
Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents:
1
diff
changeset
|
77 statsurl = "http://%s/statsadsl.html" % (options.name) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
78 rrdname = "%s.rrd" % (options.base) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
79 graphbasename = options.base |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
80 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
81 matchnum = re.compile('([0-9]+(\.[0-9]+)?)') |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
82 statsdict = { |
4
f50214bca1ae
Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents:
1
diff
changeset
|
83 3 : 'Status:', |
f50214bca1ae
Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents:
1
diff
changeset
|
84 8 : 'SNR Margin (0.1 dB):', |
f50214bca1ae
Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents:
1
diff
changeset
|
85 9 : 'Attenuation (0.1 dB):', |
f50214bca1ae
Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents:
1
diff
changeset
|
86 14 : 'Rate (Kbps):', |
f50214bca1ae
Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents:
1
diff
changeset
|
87 } |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
88 |
16 | 89 class DSLStats(object): |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
90 def __str__(self): |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
91 s = "Line Rate - Up: %d kbits, Down %d kbits\n" % (self.upstream, self.downstream) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
92 if hasattr(self, 'upstreammax'): |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
93 s += "Maximum Rate - Up: %d kbit, Down %s kbit\n" % (self.upstreammax, self.downstreammax) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
94 s += """Noise Margin - Up: %.1f dB, Down %.1f dB |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
95 Attenuation - Up: %.1f dB, Down %.1f dB""" % (self.nmup, self.nmdown, |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
96 self.attenup, self.attendown) |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
97 return s |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
98 |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
99 def getstats(): |
16 | 100 stats = DSLStats() |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
101 parser = ConfigParser.ConfigParser() |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
102 base = 'http://%s' % (conf.get('global', 'name')) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
103 # Gunk extracted from Chrome (what the page is requesting). Note it's sensitive to line ending type... |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
104 # We could get more data, eg error rates.. |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
105 data = '[WAN_DSL_INTF_CFG#1,0,0,0,0,0#0,0,0,0,0,0]0,12\r\nstatus\r\nmodulationType\r\nX_TP_AdslModulationCfg\r\nupstreamCurrRate\r\ndownstreamCurrRate\r\nX_TP_AnnexType\r\nupstreamMaxRate\r\ndownstreamMaxRate\r\nupstreamNoiseMargin\r\ndownstreamNoiseMargin\r\nupstreamAttenuation\r\ndownstreamAttenuation\r\n[WAN_DSL_INTF_STATS_TOTAL#1,0,0,0,0,0#0,0,0,0,0,0]1,8\r\nATUCCRCErrors\r\nCRCErrors\r\nATUCFECErrors\r\nFECErrors\r\nSeverelyErroredSecs\r\nX_TP_US_SeverelyErroredSecs\r\nerroredSecs\r\nX_TP_US_ErroredSecs\r\n' |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
106 cookies = {'Authorization' : 'Basic ' + base64.standard_b64encode(conf.get('global', 'username') + ':' + conf.get('global', 'password'))} |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
107 headers = {'Referer' : base} |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
108 r = requests.post(base + '/cgi?1&5' , data = data, headers = headers, cookies = cookies, stream = True) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
109 parser.readfp(r.raw) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
110 res = {} |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
111 tmp = '1,0,0,0,0,0' |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
112 if parser.get(tmp, 'status') == 'Up': |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
113 stats.linkup = True |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
114 else: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
115 stats.linkup = False |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
116 stats.upstream = float(parser.get(tmp, 'upstreamCurrRate')) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
117 stats.downstream = float(parser.get(tmp, 'downstreamCurrRate')) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
118 stats.upstreammax = float(parser.get(tmp, 'upstreamMaxRate')) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
119 stats.downstreammax = float(parser.get(tmp, 'downstreamMaxRate')) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
120 stats.nmup = float(parser.get(tmp, 'upstreamNoiseMargin')) / 10.0 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
121 stats.nmdown = float(parser.get(tmp, 'downstreamNoiseMargin')) / 10.0 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
122 stats.attenup = float(parser.get(tmp, 'upstreamAttenuation')) / 10.0 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
123 stats.attendown = float(parser.get(tmp, 'downstreamAttenuation')) / 10.0 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
124 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
125 return stats |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
126 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
127 # Setup RRD |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
128 # We expect data to be logged every 5 minutes |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
129 # Average 12 5 minute points -> hourly stats (keep 168 - a weeks worth) |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
130 # Average 288 5 minute points -> daily stats (keep 1825 - 5 years worth) |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
131 # Detemine minimum & maximum for an hour and keep a weeks worth. |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
132 def makerrd(filename): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
133 rrdtool.create(filename, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
134 '--step', '300', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
135 'DS:upstream:GAUGE:3600:32:150000', # Upstream (kbits) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
136 'DS:downstream:GAUGE:3600:32:150000', # Downstream (kbits) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
137 'DS:upstreammax:GAUGE:3600:32:150000', # Upstream maximum (kbits) |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
138 'DS:downstreammax:GAUGE:3600:32:150000', # Downstream maximum (kbits) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
139 'DS:nmup:GAUGE:3600:0:100', # Upstream Noise margin (dB) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
140 'DS:nmdown:GAUGE:3600:0:100', # Downstream Noise margin (dB) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
141 'DS:attenup:GAUGE:3600:0:100', # Upstream Attenuation (dB) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
142 'DS:attendown:GAUGE:3600:0:100', # Downstream Attenuation (dB) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
143 'RRA:AVERAGE:0.1:12:168', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
144 'RRA:AVERAGE:0.1:288:1825', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
145 'RRA:MIN:0.1:12:168', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
146 'RRA:MAX:0.1:12:168') |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
147 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
148 # Update the RRD (format stats as expected) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
149 def updaterrd(filename, tstamp, stats): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
150 rrdtool.update(filename, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
151 '%d:%d:%d:%d:%d:%f:%f:%f:%f' % (tstamp, |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
152 stats.upstream, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
153 stats.downstream, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
154 stats.upstreammax, |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
155 stats.downstreammax, |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
156 stats.nmup, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
157 stats.nmdown, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
158 stats.attenup, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
159 stats.attendown)) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
160 |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
161 # Open the URL and call the parser |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
162 def getdata(): |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
163 stats = getstats() |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
164 return stats |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
165 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
166 # Generate a graph |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
167 def gengraph(): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
168 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
169 linkargs = ( |
5 | 170 '-a', 'SVG', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
171 '-X', '0', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
172 '-l', '0', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
173 '--vertical-label', 'kbit/sec', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
174 '--slope-mode', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
175 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
176 'DEF:upstream=%s:upstream:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
177 'DEF:upstreammin=%s:upstream:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
178 'DEF:upstreammax=%s:upstream:MAX' % rrdname, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
179 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
180 'DEF:downstream=%s:downstream:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
181 'DEF:downstreammin=%s:downstream:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
182 'DEF:downstreammax=%s:downstream:MAX' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
183 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
184 'CDEF:upstreamdif=upstreammax,upstreammin,-', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
185 'CDEF:downstreamdif=downstreammax,downstreammin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
186 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
187 'DEF:maxupstream=%s:upstreammax:AVERAGE' % rrdname, |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
188 'DEF:maxdownstream=%s:downstreammax:AVERAGE' % rrdname, |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
189 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
190 'LINE0:upstreammin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
191 'AREA:upstreamdif#00dc76::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
192 'LINE1:upstream#00ff00:Upstream', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
193 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
194 'LINE0:downstreammin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
195 'AREA:downstreamdif#ff8686::STACK', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
196 'LINE1:downstream#ff0000:Downstream', |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
197 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
198 'LINE1:maxupstream#0000ff:Upstream (maximum)', |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
199 'LINE1:maxdownstream#000000:Downstream (maximum)' |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
200 ) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
201 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
202 signalargs = ( |
5 | 203 '-a', 'SVG', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
204 '--vertical-label', 'dB', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
205 '--slope-mode', |
15
7dbe86981f6b
Make minimum level of dB graph 0 to make reading lower values easier.
Daniel O'Connor <darius@dons.net.au>
parents:
14
diff
changeset
|
206 '-l', '0', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
207 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
208 'DEF:upstream=%s:upstream:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
209 'DEF:downstream=%s:downstream:AVERAGE' % rrdname, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
210 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
211 'DEF:nmup_=%s:nmup:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
212 'DEF:nmupmin_=%s:nmup:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
213 'DEF:nmupmax_=%s:nmup:MAX' % rrdname, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
214 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
215 'DEF:nmdown_=%s:nmdown:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
216 'DEF:nmdownmin_=%s:nmdown:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
217 'DEF:nmdownmax_=%s:nmdown:MAX' % rrdname, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
218 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
219 'DEF:attenup=%s:attenup:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
220 'DEF:attenupmin=%s:attenup:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
221 'DEF:attenupmax=%s:attenup:MAX' % rrdname, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
222 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
223 'DEF:attendown=%s:attendown:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
224 'DEF:attendownmin=%s:attendown:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
225 'DEF:attendownmax=%s:attendown:MAX' % rrdname, |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
226 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
227 'CDEF:nmup=nmup_,10,*', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
228 'CDEF:nmupmin=nmupmin_,10,*', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
229 'CDEF:nmupmax=nmupmax_,10,*', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
230 'CDEF:nmupdif=nmupmax,nmupmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
231 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
232 'CDEF:nmdown=nmdown_,10,*', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
233 'CDEF:nmdownmin=nmdownmin_,10,*', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
234 'CDEF:nmdownmax=nmdownmax_,10,*', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
235 'CDEF:nmdowndif=nmdownmax,nmdownmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
236 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
237 'CDEF:attenupdif=attenupmax,attenupmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
238 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
239 'CDEF:attendowndif=attendownmax,attendownmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
240 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
241 'LINE0:nmupmin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
242 'AREA:nmupdif#5c5cff::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
243 'LINE1:nmup#0000ff:Noise Margin - Up (1/10 dB)', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
244 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
245 'LINE0:nmdownmin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
246 'AREA:nmdowndif#009a00::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
247 'LINE1:nmdown#00ff00:Noise Margin - Down (1/10 dB)', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
248 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
249 'LINE0:attenupmin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
250 'AREA:attenupdif#f98100::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
251 'LINE1:attenup#ff0000:Attenuation - Up', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
252 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
253 'LINE0:attendownmin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
254 'AREA:attendowndif#aaaaaa::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
255 'LINE1:attendown#000000:Attenuation - Down') |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
256 |
5 | 257 rrdtool.graph("%s-hour-link.svg" % (graphbasename), |
258 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
259 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
260 '--start', 'end - 7d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
261 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
262 *linkargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
263 |
5 | 264 rrdtool.graph("%s-daily-link.svg" % (graphbasename), |
265 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
266 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
267 '--start', 'end - 365d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
268 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
269 *linkargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
270 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
271 |
5 | 272 rrdtool.graph("%s-hour-signal.svg" % (graphbasename), |
273 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
274 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
275 '--start', 'end - 7d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
276 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
277 *signalargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
278 |
5 | 279 rrdtool.graph("%s-daily-signal.svg" % (graphbasename), |
280 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
281 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
282 '--start', 'end - 365d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
283 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
284 *signalargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
285 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
286 if __name__ == "__main__": |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
287 names = ['Noise Margin (up)', 'Noise Margin (down)', 'Attenuation (up)', 'Attenuation (down)'] |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
288 if options.munin != None: |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
289 # Handle the wrapper passing us its $0 as our $1 |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
290 tmp = options.munin.split('_') |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
291 if len(tmp) > 1: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
292 options.munin = tmp[-1] |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
293 if options.munin not in ['signal', 'sync']: |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
294 print "Unknown data type ", options.munin |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
295 sys.exit(1) |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
296 if len(args) > 0: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
297 if args[0] == 'config': |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
298 if options.munin == 'signal': |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
299 print '''graph_category adsl |
16 | 300 graph_title DSL Signal Quality |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
301 graph_args --base 1000 -l 0 |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
302 graph_vlabel dB''' |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
303 for n in names: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
304 name = n.translate(None, ' ()').lower() |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
305 print '''%s.label %s |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
306 %s.type GAUGE |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
307 %s.max 100 |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
308 %s.min 0''' % (name, n, name, name, name) |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
309 elif options.munin == 'sync': |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
310 print '''graph_category adsl |
16 | 311 graph_title DSL Sync Speed |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
312 graph_args --base 1024 -l 0 |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
313 graph_vlabel kbit/sec |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
314 up.label Up |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
315 up.type GAUGE |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
316 up.max 150000 |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
317 up.min 0 |
10 | 318 down.label Down |
319 down.type GAUGE | |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
320 down.max 15000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
321 down.min 0 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
322 upmax.label Up |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
323 upmax.type GAUGE |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
324 upmax.max 150000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
325 upmax.min 0 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
326 downmax.label Down |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
327 downmax.type GAUGE |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
328 downmax.max 150000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
329 downmax.min 0''' |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
330 sys.exit(0) |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
331 if options.update or options.munin: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
332 stats = getdata() |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
333 if options.verbose: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
334 if stats == None: |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
335 print "Modem is offline" |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
336 else: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
337 print stats |
13
bf46efd061d7
Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
338 if (options.update or options.munin != None) and stats != None: |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
339 if options.update: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
340 try: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
341 os.stat(rrdname) |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
342 except OSError, e: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
343 if e.errno == 2: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
344 print "rrd not found, creating.." |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
345 makerrd(rrdname) |
13
bf46efd061d7
Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
346 updaterrd(rrdname, int(time.time()), stats) |
9
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
347 if options.munin != None: |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
348 if options.munin == 'signal': |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
349 print '''noisemarginup.value %.1f |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
350 noisemargindown.value %.1f |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
351 attenuationup.value %.1f |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
352 attenuationdown.value %.1f''' % (stats.nmup, stats.nmdown, stats.attenup, stats.attendown) |
8b5958404f81
Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
353 elif options.munin == 'sync': |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
354 s = '''up.value %.1f |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
355 down.value %.1f\n''' % (stats.upstream, stats.downstream) |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
356 if hasattr(stats, 'upstreammax'): |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
357 s += '''upmax.value %.1f |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
358 downmax.value %.1f''' % (stats.upstreammax, stats.downstreammax) |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
359 print s |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
360 if options.graph: |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
361 gengraph() |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
362 |