Mercurial > ~darius > hgwebdir.cgi > adslstats
annotate adslstats.py @ 23:4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
It seems even successful auth attemps are rate limited and get a 503.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 17 Jun 2017 15:59:23 +0930 |
parents | a53f90508a06 |
children | 806b1ed7f1b5 |
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 # |
22 | 4 # Parse DSL link stats for iiNet TG-1 & 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 # |
22 | 8 # Copyright (C) 2017 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 |
22 | 34 import binascii |
35 import bs4 | |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
36 import ConfigParser |
22 | 37 import json |
38 import mechanize | |
39 import mysrp as srp | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
40 import optparse |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
41 import os |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
42 import os.path |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
43 import re |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
44 import requests |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
45 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
|
46 import sys |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
47 import time |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
48 import urllib |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
49 |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
50 conf = ConfigParser.ConfigParser() |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
51 conf.add_section('global') |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
52 conf.set('global', 'username', 'admin') |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
53 conf.set('global', 'password', 'admin') |
22 | 54 conf.set('global', 'name', '10.0.2.14') |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
55 conf.set('global', 'cookiejar', os.path.expanduser('~/.adslstats.cj')) |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
56 |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
57 conflist = ['adslstats.ini'] |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
58 if ('HOME' in os.environ): |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
59 conflist.append(os.path.expanduser('~/.adslstats.ini')) |
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
60 conf.read(conflist) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
61 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
62 usage = '''%prog [options]''' |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
63 opts = optparse.OptionParser(usage) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
64 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
|
65 help="Enable debug output") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
66 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
|
67 help="Generate a graph") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 help="Output munin data for ARG") |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
72 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
|
73 help="Username to login to modem") |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
74 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
|
75 help="Password to login to modem") |
1
a795b6cd8b1a
Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
76 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
|
77 help="Hostname of modem") |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
78 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
|
79 help="Base directory for RRD & PNGs") |
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 (options, args) = opts.parse_args() |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
82 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
83 rrdname = "%s.rrd" % (options.base) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
84 graphbasename = options.base |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
85 |
16 | 86 class DSLStats(object): |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
87 def __str__(self): |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 self.upstreammax, self.downstreammax, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
95 self.nmup, self.nmdown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
96 self.attenup, self.attendown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
97 self.uppower, self.downpower, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
98 self.uptime) |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
99 return s |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
100 |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
101 def getstats(): |
16 | 102 stats = DSLStats() |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
103 parser = ConfigParser.ConfigParser() |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
104 base = 'http://%s' % (conf.get('global', 'name')) |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
105 br = mechanize.Browser() |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
106 #br.set_debug_http(True) |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
107 #br.set_debug_responses(True) |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
108 #br.set_debug_redirects(True) |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
109 cj = mechanize.LWPCookieJar() |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
110 if os.path.exists(conf.get('global', 'cookiejar')): |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
111 cj.load(conf.get('global', 'cookiejar'), ignore_discard = True) |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
112 br.set_cookiejar(cj) |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
113 if not fillstats(br, base, stats): |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
114 if not authenticate(br, base, conf.get('global', 'username'), conf.get('global', 'password')): |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
115 print('login failed') |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
116 return None |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
117 print('login succeeded, getting stats') |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
118 fillstats(br, base, stats) |
22 | 119 |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
120 cj.save(conf.get('global', 'cookiejar'), ignore_discard = True) |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
121 return stats |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
122 |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
123 def authenticate(br, base, username, password): |
22 | 124 # Connect and authenticate |
125 r = br.open(base) | |
126 bs = bs4.BeautifulSoup(r) | |
127 token = bs.head.find(lambda tag: tag.has_attr('name') and tag['name'] == 'CSRFtoken')['content'] | |
128 #print('Got CSRF token ' + token) | |
129 | |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
130 usr = srp.User(username, password, hash_alg = srp.SHA256, ng_type = srp.NG_2048) |
22 | 131 uname, A = usr.start_authentication() |
132 | |
133 req = mechanize.Request(base + '/authenticate', data = urllib.urlencode({'CSRFtoken' : token, 'I' : uname, 'A' : binascii.hexlify(A)})) | |
134 r = br.open(req) | |
135 j = json.decoder.JSONDecoder().decode(r.read()) | |
136 #print('Sent challenge, got ' + str(j)) | |
137 | |
138 M = usr.process_challenge(binascii.unhexlify(j['s']), binascii.unhexlify(j['B'])) | |
139 req = mechanize.Request(base + '/authenticate', data = urllib.urlencode({'CSRFtoken' : token, 'M' : binascii.hexlify(M)})) | |
140 r = br.open(req) | |
141 j = json.decoder.JSONDecoder().decode(r.read()) | |
142 #print('Got response ' + str(j)) | |
143 | |
144 usr.verify_session(binascii.unhexlify(j['M'])) | |
145 if not usr.authenticated(): | |
146 print('Failed to authenticate') | |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
147 return False |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
148 return True |
22 | 149 |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
150 def fillstats(br, base, stats): |
22 | 151 # Fetch stats and parse |
152 r = br.open(base + '/modals/broadband-bridge-modal.lp') | |
153 bs = bs4.BeautifulSoup(r) | |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
154 if bs.find('div', 'login') != None: |
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
155 return False |
22 | 156 |
157 # Helper function to extract data | |
158 def getvals(bs, text): | |
159 subs = bs.findAll('label', text = text)[0].fetchNextSiblings()[0].strings | |
160 return map(lambda s: float(s.split()[0]), subs) | |
161 | |
162 if map(None, bs.findAll('label', text = 'DSL Status')[0].fetchNextSiblings()[0].strings)[0] == 'Up': | |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
163 stats.linkup = True |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
164 else: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
165 stats.linkup = False |
22 | 166 |
167 stats.upstreammax, stats.downstreammax = getvals(bs, 'Maximum Line rate') | |
168 stats.upstream, stats.downstream = getvals(bs, 'Line Rate') | |
169 stats.uppower, stats.downpower = getvals(bs, 'Output Power') | |
170 stats.nmup, stats.nmdown = getvals(bs, 'Noise Margin') | |
171 | |
172 # Line attenuation returns several values for each direction, parse specially and just take the first one | |
173 upattens, downattens = map(None, bs.findAll('label', text = 'Line Attenuation')[0].fetchNextSiblings()[0].strings) | |
174 stats.attenup = float(re.findall('([0-9.N/A]+)', upattens)[0]) | |
175 stats.attendown = float(re.findall('([0-9.N/A]+)', downattens)[0]) | |
176 | |
177 # Convert something like '2days 17hours 28min 19sec' into seconds | |
178 uptime = re.findall('([0-9]+)', map(None, bs.findAll('label', text = 'DSL Uptime')[0].fetchNextSiblings()[0].strings)[0]) | |
179 uptime.reverse() # End up with an array of seconds, minutes, hours, etc | |
180 mults = [1, 60, 60 * 60, 24 * 60 * 60] | |
181 if len(uptime) > mults: | |
182 print('Too many uptime elements to work out') | |
183 stats.uptime = None | |
184 else: | |
185 stats.uptime = reduce(lambda a, b: a + b, map(lambda a: int(a[0]) * a[1], zip(uptime, mults))) | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
186 |
23
4b6c811e77df
Save & load session cookie so we don't have to reauth every time.
Daniel O'Connor <darius@dons.net.au>
parents:
22
diff
changeset
|
187 return True |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
188 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
189 # Setup RRD |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
190 # We expect data to be logged every 5 minutes |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
191 # 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
|
192 # 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
|
193 # 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
|
194 def makerrd(filename): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
195 rrdtool.create(filename, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
196 '--step', '300', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
197 '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
|
198 '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
|
199 '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
|
200 '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
|
201 '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
|
202 '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
|
203 'DS:attenup:GAUGE:3600:0:100', # Upstream Attenuation (dB) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
204 '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
|
205 '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
|
206 '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
|
207 '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
|
208 '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
|
209 'DS:uptime:DERIVE:3600:0:U', # Uptime (seconds) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
210 '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
|
211 'RRA:AVERAGE:0.1:288:1825', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
212 'RRA:MIN:0.1:12:168', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
213 'RRA:MAX:0.1:12:168') |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
214 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
215 # Update the RRD (format stats as expected) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
216 def updaterrd(filename, tstamp, stats): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
217 rrdtool.update(filename, |
22 | 218 '%d:%d:%d:%d:%d:%f:%f:%f:%f:U:U:%f:%f:%d' % ( |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
219 tstamp, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
220 stats.upstream, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
221 stats.downstream, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
222 stats.upstreammax, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
223 stats.downstreammax, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
224 stats.nmup, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
225 stats.nmdown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
226 stats.attenup, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
227 stats.attendown, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
228 stats.uppower, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
229 stats.downpower, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
230 stats.uptime)) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
231 |
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
|
232 # 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
|
233 def getdata(): |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
234 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
|
235 return stats |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
236 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
237 # Generate a graph |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
238 def gengraph(): |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
239 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
240 linkargs = ( |
5 | 241 '-a', 'SVG', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
242 '-X', '0', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
243 '-l', '0', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
244 '--vertical-label', 'kbit/sec', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
245 '--slope-mode', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
246 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
247 'DEF:upstream=%s:upstream:AVERAGE' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
248 'DEF:upstreammin=%s:upstream:MIN' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
249 'DEF:upstreammax=%s:upstream:MAX' % rrdname, |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
250 'CDEF:upstreamdif=upstreammax,upstreammin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
251 '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
|
252 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
253 'LINE0:upstreammin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
254 'AREA:upstreamdif#00dc76::STACK', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
255 'LINE1:upstream#00ff00:Upstream', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
256 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
257 'LINE1:maxupstream#0000ff:Upstream (maximum)', |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
258 |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
259 'DEF:downstream=%s:downstream:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
260 'DEF:downstreammin=%s:downstream:MIN' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
261 'DEF:downstreammax=%s:downstream:MAX' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
262 'CDEF:downstreamdif=downstreammax,downstreammin,-', |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
263 'DEF:maxdownstream=%s:downstreammax:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
264 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
265 'LINE0:downstreammin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
266 'AREA:downstreamdif#ff8686::STACK', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
267 'LINE1:downstream#ff0000:Downstream', |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
268 |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
269 'LINE1:maxdownstream#000000:Downstream (maximum)' |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
270 ) |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
271 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
272 signalargs = ( |
5 | 273 '-a', 'SVG', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
274 '--vertical-label', 'dB', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
275 '--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
|
276 '-l', '0', |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
277 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
278 '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
|
279 '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
|
280 '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
|
281 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
282 'CDEF:nmupdif=nmupmax,nmupmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
283 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
284 'LINE0:nmupmin#000000:', |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
285 '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
|
286 '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
|
287 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
288 '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
|
289 '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
|
290 '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
|
291 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
292 'CDEF:nmdowndif=nmdownmax,nmdownmin,-', |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
293 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
294 'LINE0:nmdownmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
295 'AREA:nmdowndif#009a00::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
296 '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
|
297 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
298 'DEF:attenup=%s:attenup:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
299 'DEF:attenupmin=%s:attenup:MIN' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
300 'DEF:attenupmax=%s:attenup:MAX' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
301 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
302 'CDEF:attenupdif=attenupmax,attenupmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
303 |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
304 'LINE0:attenupmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
305 'AREA:attenupdif#f98100::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
306 '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
|
307 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
308 'DEF:attendown=%s:attendown:AVERAGE' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
309 'DEF:attendownmin=%s:attendown:MIN' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
310 'DEF:attendownmax=%s:attendown:MAX' % rrdname, |
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
311 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
312 'CDEF:attendowndif=attendownmax,attendownmin,-', |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
313 |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
314 'LINE0:attendownmin#000000:', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
315 '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
|
316 '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
|
317 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
318 '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
|
319 '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
|
320 '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
|
321 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
322 'CDEF:powerupdif=powerupmax,powerupmin,-', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
323 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
324 'LINE0:powerupmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
325 'AREA:powerupdif#804007::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
326 '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
|
327 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
328 '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
|
329 '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
|
330 '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
|
331 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
332 'CDEF:powerdowndif=powerdownmax,powerdownmin,-', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
333 |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
334 'LINE0:powerdownmin#000000:', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
335 'AREA:powerdowndif#604872::STACK', |
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
336 'LINE1:powerdown#c090e5:Power - Down (dBm)', |
20
38e3804d4f80
Plot FEC errors (probably, hard to test)
Daniel O'Connor <darius@dons.net.au>
parents:
19
diff
changeset
|
337 |
21 | 338 'DEF:uptime=%s:uptime:AVERAGE' % rrdname, |
339 'CDEF:uptimepct=uptime,10,*', | |
340 'LINE1:uptimepct#606060:Uptime (10\'s%)', | |
19
5bec78c876db
Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents:
18
diff
changeset
|
341 ) |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
342 |
5 | 343 rrdtool.graph("%s-hour-link.svg" % (graphbasename), |
344 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
345 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
346 '--start', 'end - 7d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
347 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
348 *linkargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
349 |
5 | 350 rrdtool.graph("%s-daily-link.svg" % (graphbasename), |
351 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
352 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
353 '--start', 'end - 365d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
354 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
355 *linkargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
356 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
357 |
5 | 358 rrdtool.graph("%s-hour-signal.svg" % (graphbasename), |
359 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
360 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
361 '--start', 'end - 7d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
362 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
363 *signalargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
364 |
5 | 365 rrdtool.graph("%s-daily-signal.svg" % (graphbasename), |
366 '--width', '768', | |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
367 '--height', '256', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
368 '--start', 'end - 365d', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
369 '--end', 'now', |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
370 *signalargs) |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
371 |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
372 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
|
373 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
|
374 if options.munin != None: |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
375 # 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 print '''graph_category adsl |
16 | 386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 %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
|
393 %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
|
394 %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
|
395 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
|
396 print '''graph_category adsl |
16 | 397 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
|
398 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
|
399 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
|
400 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
|
401 up.type GAUGE |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
402 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
|
403 up.min 0 |
10 | 404 down.label Down |
405 down.type GAUGE | |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
406 down.max 15000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
407 down.min 0 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
408 upmax.label Up (max) |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
409 upmax.type GAUGE |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
410 upmax.max 150000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
411 upmax.min 0 |
18
ec994073f70a
Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents:
17
diff
changeset
|
412 downmax.label Down (max) |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
413 downmax.type GAUGE |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
414 downmax.max 150000 |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 stats = getdata() |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
419 if options.verbose: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
420 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
|
421 print "Modem is offline" |
14
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
422 else: |
2debc3fb4372
Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
423 print stats |
13
bf46efd061d7
Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 makerrd(rrdname) |
13
bf46efd061d7
Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents:
12
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 elif options.munin == 'sync': |
17
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
440 s = '''up.value %.1f |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
441 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
|
442 if hasattr(stats, 'upstreammax'): |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
443 s += '''upmax.value %.1f |
43f54da8baf9
Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents:
16
diff
changeset
|
444 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
|
445 print s |
0
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
446 if options.graph: |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
447 gengraph() |
98fe11ea4c82
Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff
changeset
|
448 |