Mercurial > ~darius > hgwebdir.cgi > adslstats
annotate adslstats.py @ 19:5bec78c876db
Properly re-arrange signal graph entries, show power.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 23 May 2016 11:52:50 +0930 |
parents | ec994073f70a |
children | 38e3804d4f80 |
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 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
77 rrdname = "%s.rrd" % (options.base) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
78 graphbasename = options.base |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
79 |
16 | 80 class DSLStats(object): |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
81 def __str__(self): |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
82 s = '''Line Rate - Up: %d kbits, Down %d kbits |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
83 Maximum Rate - Up: %d kbit, Down %s kbit |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
84 Noise Margin - Up: %.1f dB, Down %.1f dB |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
85 Attenuation - Up: %.1f dB, Down %.1f dB |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
86 Errors - Up: %d, Down %d |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
87 Power - Up: %.1f dBm, Down %.1f dBm |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
88 Uptime - %d sec''' % (self.upstream, self.downstream, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
89 self.upstreammax, self.downstreammax, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
90 self.nmup, self.nmdown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
91 self.attenup, self.attendown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
92 self.fecATUC, self.fecATUR, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
93 self.uppower, self.downpower, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
94 self.uptime) |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
95 return s |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
96 |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
97 def getstats(): |
16 | 98 stats = DSLStats() |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
99 parser = ConfigParser.ConfigParser() |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
100 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
|
101 # Gunk extracted from Chrome (what the page is requesting). Note it's sensitive to line ending type... |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
102 # Plus information from http://forum.kitz.co.uk/index.php?topic=15738.0 |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
103 # ATUR = ADSL Termination Unit Remote |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
104 # ATUC = ADSL Termination Unit Central office |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
105 query = '[WAN_DSL_INTF_CFG#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n[WAN_DSL_INTF_STATS_TOTAL#0,0,0,0,0,0#0,0,0,0,0,0]1,0\r\n' |
14
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} |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
108 r = requests.post(base + '/cgi?5&5' , data = query, headers = headers, cookies = cookies, stream = True) |
14
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 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
124 stats.fecATUR = int(parser.get(tmp, 'FECErrors')) |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
125 stats.fecATUC = int(parser.get(tmp, 'ATUCFECErrors')) |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
126 stats.uppower = float(parser.get(tmp, 'upstreamPower')) / 10.0 # I think it's tenths of a dBm but who knows |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
127 stats.downpower = float(parser.get(tmp, 'downstreamPower')) / 10.0 |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
128 stats.uptime = int(parser.get(tmp, 'showtimeStart')) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
129 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
130 return stats |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
131 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
132 # Setup RRD |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
133 # We expect data to be logged every 5 minutes |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
134 # 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
|
135 # 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
|
136 # 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
|
137 def makerrd(filename): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
138 rrdtool.create(filename, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
139 '--step', '300', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
140 '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
|
141 '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
|
142 '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
|
143 '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
|
144 '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
|
145 '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
|
146 'DS:attenup:GAUGE:3600:0:100', # Upstream Attenuation (dB) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
147 'DS:attendown:GAUGE:3600:0:100', # Downstream Attenuation (dB) |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
148 'DS:fecATUC:DERIVE:3600:0:U', # Upstream FEC error count |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
149 'DS:fecATUR:DERIVE:3600:0:U', # Downstream FEC error count |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
150 'DS:powerup:GAUGE:3600:-100:100', # Upstream Power (dBm) |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
151 'DS:powerdown:GAUGE:3600:-100:100', # Downstream Power (dBm) |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
152 'DS:uptime:DERIVE:3600:0:U', # Uptime (seconds) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
153 '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
|
154 'RRA:AVERAGE:0.1:288:1825', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
155 'RRA:MIN:0.1:12:168', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
156 'RRA:MAX:0.1:12:168') |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
157 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
158 # Update the RRD (format stats as expected) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
159 def updaterrd(filename, tstamp, stats): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
160 rrdtool.update(filename, |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
161 '%d:%d:%d:%d:%d:%f:%f:%f:%f:%d:%d:%f:%f:%d' % ( |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
162 tstamp, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
163 stats.upstream, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
164 stats.downstream, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
165 stats.upstreammax, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
166 stats.downstreammax, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
167 stats.nmup, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
168 stats.nmdown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
169 stats.attenup, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
170 stats.attendown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
171 stats.fecATUC, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
172 stats.fecATUR, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
173 stats.uppower, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
174 stats.downpower, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
175 stats.uptime)) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
176 |
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
|
177 # 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
|
178 def getdata(): |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
179 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
|
180 return stats |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
181 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
182 # Generate a graph |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
183 def gengraph(): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
184 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
185 linkargs = ( |
5 | 186 '-a', 'SVG', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
187 '-X', '0', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
188 '-l', '0', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
189 '--vertical-label', 'kbit/sec', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
190 '--slope-mode', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
191 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
192 'DEF:upstream=%s:upstream:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
193 'DEF:upstreammin=%s:upstream:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
194 'DEF:upstreammax=%s:upstream:MAX' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
195 'CDEF:upstreamdif=upstreammax,upstreammin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
196 '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
|
197 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
198 'LINE0:upstreammin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
199 'AREA:upstreamdif#00dc76::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
200 'LINE1:upstream#00ff00:Upstream', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
201 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
202 'LINE1:maxupstream#0000ff:Upstream (maximum)', |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
203 |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
204 'DEF:downstream=%s:downstream:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
205 'DEF:downstreammin=%s:downstream:MIN' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
206 'DEF:downstreammax=%s:downstream:MAX' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
207 'CDEF:downstreamdif=downstreammax,downstreammin,-', |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
208 'DEF:maxdownstream=%s:downstreammax:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
209 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
210 'LINE0:downstreammin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
211 'AREA:downstreamdif#ff8686::STACK', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
212 'LINE1:downstream#ff0000:Downstream', |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
213 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
214 'LINE1:maxdownstream#000000:Downstream (maximum)' |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
215 ) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
216 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
217 signalargs = ( |
5 | 218 '-a', 'SVG', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
219 '--vertical-label', 'dB', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
220 '--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
|
221 '-l', '0', |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
222 '--font', 'LEGEND:7', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
223 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
224 'DEF:nmup=%s:nmup:AVERAGE' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
225 'DEF:nmupmin=%s:nmup:MIN' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
226 '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
|
227 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
228 'CDEF:nmupdif=nmupmax,nmupmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
229 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
230 'LINE0:nmupmin#000000:', |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
231 'AREA:nmupdif#5c5cff::STACK', |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
232 'LINE1:nmup#0000ff:Noise Margin - Up', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
233 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
234 'DEF:nmdown=%s:nmdown:AVERAGE' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
235 'DEF:nmdownmin=%s:nmdown:MIN' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
236 'DEF:nmdownmax=%s:nmdown:MAX' % rrdname, |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
237 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
238 'CDEF:nmdowndif=nmdownmax,nmdownmin,-', |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
239 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
240 'LINE0:nmdownmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
241 'AREA:nmdowndif#009a00::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
242 'LINE1:nmdown#00ff00:Noise Margin - Down', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
243 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
244 'DEF:attenup=%s:attenup:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
245 'DEF:attenupmin=%s:attenup:MIN' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
246 'DEF:attenupmax=%s:attenup:MAX' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
247 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
248 'CDEF:attenupdif=attenupmax,attenupmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
249 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
250 'LINE0:attenupmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
251 'AREA:attenupdif#f98100::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
252 'LINE1:attenup#ff0000:Attenuation - Up', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
253 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
254 'DEF:attendown=%s:attendown:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
255 'DEF:attendownmin=%s:attendown:MIN' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
256 'DEF:attendownmax=%s:attendown:MAX' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
257 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
258 'CDEF:attendowndif=attendownmax,attendownmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
259 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
260 'LINE0:attendownmin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
261 'AREA:attendowndif#aaaaaa::STACK', |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
262 'LINE1:attendown#000000:Attenuation - Down', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
263 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
264 'DEF:powerup=%s:powerup:AVERAGE' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
265 'DEF:powerupmin=%s:powerup:MIN' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
266 'DEF:powerupmax=%s:powerup:MAX' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
267 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
268 'CDEF:powerupdif=powerupmax,powerupmin,-', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
269 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
270 'LINE0:powerupmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
271 'AREA:powerupdif#804007::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
272 'LINE1:powerup#ff800e:Power - Up (dBm)', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
273 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
274 'DEF:powerdown=%s:powerdown:AVERAGE' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
275 'DEF:powerdownmin=%s:powerdown:MIN' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
276 'DEF:powerdownmax=%s:powerdown:MAX' % rrdname, |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
277 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
278 'CDEF:powerdowndif=powerdownmax,powerdownmin,-', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
279 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
280 'LINE0:powerdownmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
281 'AREA:powerdowndif#604872::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
282 'LINE1:powerdown#c090e5:Power - Down (dBm)', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
283 ) |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
284 |
5 | 285 rrdtool.graph("%s-hour-link.svg" % (graphbasename), |
286 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
287 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
288 '--start', 'end - 7d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
289 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
290 *linkargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
291 |
5 | 292 rrdtool.graph("%s-daily-link.svg" % (graphbasename), |
293 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
294 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
295 '--start', 'end - 365d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
296 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
297 *linkargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
298 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
299 |
5 | 300 rrdtool.graph("%s-hour-signal.svg" % (graphbasename), |
301 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
302 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
303 '--start', 'end - 7d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
304 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
305 *signalargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
306 |
5 | 307 rrdtool.graph("%s-daily-signal.svg" % (graphbasename), |
308 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
309 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
310 '--start', 'end - 365d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
311 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
312 *signalargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
313 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
314 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
|
315 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
|
316 if options.munin != None: |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
317 # 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 print '''graph_category adsl |
16 | 328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 %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
|
335 %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
|
336 %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
|
337 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
|
338 print '''graph_category adsl |
16 | 339 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
|
340 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
|
341 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
|
342 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
|
343 up.type GAUGE |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
344 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
|
345 up.min 0 |
10 | 346 down.label Down |
347 down.type GAUGE | |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
348 down.max 15000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
349 down.min 0 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
350 upmax.label Up (max) |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
351 upmax.type GAUGE |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
352 upmax.max 150000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
353 upmax.min 0 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
354 downmax.label Down (max) |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
355 downmax.type GAUGE |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
356 downmax.max 150000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 stats = getdata() |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
361 if options.verbose: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
362 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
|
363 print "Modem is offline" |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
364 else: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
365 print stats |
13
bf46efd061d7
Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 makerrd(rrdname) |
13
bf46efd061d7
Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 elif options.munin == 'sync': |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
382 s = '''up.value %.1f |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
383 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
|
384 if hasattr(stats, 'upstreammax'): |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
385 s += '''upmax.value %.1f |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
386 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
|
387 print s |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
388 if options.graph: |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
389 gengraph() |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
390 |