annotate adslstats.py @ 22:a53f90508a06

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