annotate adslstats.py @ 34:b79c03810bbe

Actually *call* python3
author Daniel O'Connor <darius@dons.net.au>
date Sat, 14 Nov 2020 15:02:55 +1030
parents 7d8bee5e3c80
children 5dbc310f1eca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
b79c03810bbe Actually *call* python3
Daniel O'Connor <darius@dons.net.au>
parents: 33
diff changeset
1 #!/usr/bin/env python3
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
33
7d8bee5e3c80 Retain backwards compatibility with 2.7
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
36 try:
7d8bee5e3c80 Retain backwards compatibility with 2.7
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
37 import configparser
7d8bee5e3c80 Retain backwards compatibility with 2.7
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
38 except ImportError:
7d8bee5e3c80 Retain backwards compatibility with 2.7
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
39 import ConfigParser as configparser
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
40 import json
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
41 import mechanize
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
42 import mysrp as srp
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
43 import argparse
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
44 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
45 import os.path
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
46 import re
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
47 import requests
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
48 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
49 import sys
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
50 import time
33
7d8bee5e3c80 Retain backwards compatibility with 2.7
Daniel O'Connor <darius@dons.net.au>
parents: 32
diff changeset
51 import urllib
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
52 from functools import reduce
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
53
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
54 conf = configparser.ConfigParser()
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
55 conf.add_section('global')
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
56
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
57 conflist = []
1
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]'''
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
63 parser = argparse.ArgumentParser(usage)
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
64 parser.add_argument('-v', '--verbose', action='store_true', default=False,
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
65 help='Enable debug output')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
66 parser.add_argument('-g', '--graph', action='store_true', default=False,
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
67 help='Generate a graph')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
68 parser.add_argument('-u', '--update', action='store_true', default=False,
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
69 help='Update RRD (implies -d)')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
70 parser.add_argument('-m', '--munin', action='store', default=None,
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
71 help='Output munin data for ARG')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
72 parser.add_argument('-a', '--username', action='store',
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
73 help='Username to login to modem')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
74 parser.add_argument('-p', '--password', action='store',
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
75 help='Password to login to modem')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
76 parser.add_argument('-n', '--name', action='store',
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
77 help='Hostname of modem')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
78 parser.add_argument('-b', '--base', action='store',
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
79 help='Base directory for RRD & PNGs')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
80 parser.add_argument('-c', '--cookiejar', action='store',
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
81 help='Location of cookiejar')
30
08cddcdb0db3 fix Munin plugin
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
82 parser.add_argument('rest', nargs = '*')
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
83
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
84 args = parser.parse_args()
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
85
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
86 # Handle options from conf and override with ini
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
87 def opthelper(args, conf, optname):
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
88 if args.__getattribute__(optname) == None:
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
89 if not conf.has_option('global', optname):
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
90 parser.error(optname + ' must be specified in config file or via commandline')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
91 else:
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
92 args.__setattr__(optname, conf.get('global', optname))
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
93
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
94 opthelper(args, conf, 'username')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
95 opthelper(args, conf, 'password')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
96 opthelper(args, conf, 'name')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
97 opthelper(args, conf, 'base')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
98 opthelper(args, conf, 'cookiejar')
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
99
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
100 # Expand path names
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
101 args.cookiejar = os.path.expanduser(args.cookiejar)
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
102 args.base = os.path.expanduser(args.base)
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
103
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
104 rrdname = "%s.rrd" % (args.base)
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
105 graphbasename = args.base
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
106
16
425d02592dce Rename ADSL to DSL
Daniel O'Connor <darius@dons.net.au>
parents: 15
diff changeset
107 class DSLStats(object):
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
108 def __str__(self):
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
109 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
110 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
111 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
112 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
113 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
114 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
115 self.upstreammax, self.downstreammax,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
116 self.nmup, self.nmdown,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
117 self.attenup, self.attendown,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
118 self.uppower, self.downpower,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
119 self.uptime)
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
120 return s
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
121
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
122 def getstats():
16
425d02592dce Rename ADSL to DSL
Daniel O'Connor <darius@dons.net.au>
parents: 15
diff changeset
123 stats = DSLStats()
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
124 parser = configparser.ConfigParser()
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
125 base = 'http://%s' % (args.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
126 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
127 #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
128 #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
129 #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
130 cj = mechanize.LWPCookieJar()
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
131 if os.path.exists(args.cookiejar):
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
132 cj.load(args.cookiejar, ignore_discard = True)
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
133 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
134 if not fillstats(br, base, stats):
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
135 if not authenticate(br, base, args.username, args.password):
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
136 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
137 return None
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
138 #print('login succeeded, getting stats')
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
139 fillstats(br, base, stats)
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
140
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
141 cj.save(args.cookiejar, ignore_discard = True)
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
142 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
143
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
144 def authenticate(br, base, username, password):
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
145 # Connect and authenticate
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
146 r = br.open(base)
26
04874587fb6e suppress new BeautifulSoup warning
Daniel O'Connor <darius@dons.net.au>
parents: 25
diff changeset
147 bs = bs4.BeautifulSoup(r, 'lxml')
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
148 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
149 #print('Got CSRF token ' + token)
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
150
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
151 usr = srp.User(username, password, hash_alg = srp.SHA256, ng_type = srp.NG_2048)
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
152 uname, A = usr.start_authentication()
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
153
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
154 req = mechanize.Request(base + '/authenticate', data = urllib.parse.urlencode({'CSRFtoken' : token, 'I' : uname, 'A' : binascii.hexlify(A)}))
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
155 r = br.open(req)
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
156 j = json.decoder.JSONDecoder().decode(r.read())
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
157 #print('Sent challenge, got ' + str(j))
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
158
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
159 M = usr.process_challenge(binascii.unhexlify(j['s']), binascii.unhexlify(j['B']))
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
160 req = mechanize.Request(base + '/authenticate', data = urllib.parse.urlencode({'CSRFtoken' : token, 'M' : binascii.hexlify(M)}))
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
161 r = br.open(req)
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
162 j = json.decoder.JSONDecoder().decode(r.read())
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
163 #print('Got response ' + str(j))
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
164
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
165 usr.verify_session(binascii.unhexlify(j['M']))
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
166 if not usr.authenticated():
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
167 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
168 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
169 return True
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
170
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
171 def fillstats(br, base, stats):
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
172 # Fetch stats and parse
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
173 r = br.open(base + '/modals/broadband-bridge-modal.lp')
26
04874587fb6e suppress new BeautifulSoup warning
Daniel O'Connor <darius@dons.net.au>
parents: 25
diff changeset
174 bs = bs4.BeautifulSoup(r, 'lxml')
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
175 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
176 return False
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
177
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
178 # Helper function to extract data
24
806b1ed7f1b5 Get units right for speeds.
Daniel O'Connor <darius@dons.net.au>
parents: 23
diff changeset
179 def getvals(bs, text, mult = 1):
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
180 subs = bs.findAll('label', text = text)[0].fetchNextSiblings()[0].strings
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
181 tmp = [float(s.split()[0]) for s in subs]
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
182 return [s * mult for s in tmp]
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
183
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
184 if list(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
185 stats.linkup = True
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
186 else:
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
187 stats.linkup = False
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
188
24
806b1ed7f1b5 Get units right for speeds.
Daniel O'Connor <darius@dons.net.au>
parents: 23
diff changeset
189 stats.upstreammax, stats.downstreammax = getvals(bs, 'Maximum Line rate', 1e3)
806b1ed7f1b5 Get units right for speeds.
Daniel O'Connor <darius@dons.net.au>
parents: 23
diff changeset
190 stats.upstream, stats.downstream = getvals(bs, 'Line Rate', 1e3)
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
191 stats.uppower, stats.downpower = getvals(bs, 'Output Power')
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
192 stats.nmup, stats.nmdown = getvals(bs, 'Noise Margin')
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
193
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
194 # Line attenuation returns several values for each direction, parse specially and just take the first one
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
195 upattens, downattens = list(bs.findAll('label', text = 'Line Attenuation')[0].fetchNextSiblings()[0].strings)
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
196 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
197 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
198
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
199 # Convert something like '2days 17hours 28min 19sec' into seconds
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
200 uptime = re.findall('([0-9]+)', list(bs.findAll('label', text = 'DSL Uptime')[0].fetchNextSiblings()[0].strings)[0])
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
201 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
202 mults = [1, 60, 60 * 60, 24 * 60 * 60]
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
203 if len(uptime) != len(mults):
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
204 print('Unexpected number of uptime elements (%s)' % str(uptime))
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
205 stats.uptime = None
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
206 else:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
207 stats.uptime = reduce(lambda a, b: a + b, [int(a[0]) * a[1] for a in zip(uptime, mults)])
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
208
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
209 return True
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
210
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
211 # Setup RRD
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
212 # We expect data to be logged every 5 minutes
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
213 # 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
214 # 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
215 # 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
216 def makerrd(filename):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
217 rrdtool.create(filename,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
218 '--step', '300',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
219 '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
220 '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
221 '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
222 '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
223 '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
224 '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
225 'DS:attenup:GAUGE:3600:0:100', # Upstream Attenuation (dB)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
226 '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
227 '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
228 '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
229 '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
230 '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
231 'DS:uptime:DERIVE:3600:0:U', # Uptime (seconds)
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
232 '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
233 'RRA:AVERAGE:0.1:288:1825',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
234 'RRA:MIN:0.1:12:168',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
235 'RRA:MAX:0.1:12:168')
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 # Update the RRD (format stats as expected)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
238 def updaterrd(filename, tstamp, stats):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
239 rrdtool.update(filename,
22
a53f90508a06 Switch to TG-1.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
240 '%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
241 tstamp,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
242 stats.upstream,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
243 stats.downstream,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
244 stats.upstreammax,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
245 stats.downstreammax,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
246 stats.nmup,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
247 stats.nmdown,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
248 stats.attenup,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
249 stats.attendown,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
250 stats.uppower,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
251 stats.downpower,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
252 stats.uptime))
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
253
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
254 # 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
255 def getdata():
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
256 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
257 return stats
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
258
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
259 # Generate a graph
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
260 def gengraph():
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
261
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
262 linkargs = (
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
263 '-a', 'SVG',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
264 '-X', '0',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
265 '-l', '0',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
266 '--vertical-label', 'kbit/sec',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
267 '--slope-mode',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
268
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
269 'DEF:upstream=%s:upstream:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
270 'DEF:upstreammin=%s:upstream:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
271 'DEF:upstreammax=%s:upstream:MAX' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
272 'CDEF:upstreamdif=upstreammax,upstreammin,-',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
273 '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
274
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
275 'LINE0.001:upstreammin#000000:',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
276 'AREA:upstreamdif#00dc76::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
277 'LINE1:upstream#00ff00:Upstream',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
278
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
279 'LINE1:maxupstream#0000ff:Upstream (maximum)',
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
280
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
281 'DEF:downstream=%s:downstream:AVERAGE' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
282 'DEF:downstreammin=%s:downstream:MIN' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
283 'DEF:downstreammax=%s:downstream:MAX' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
284 'CDEF:downstreamdif=downstreammax,downstreammin,-',
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
285 'DEF:maxdownstream=%s:downstreammax:AVERAGE' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
286
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
287 'LINE0.001:downstreammin#000000:',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
288 'AREA:downstreamdif#ff8686::STACK',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
289 'LINE1:downstream#ff0000:Downstream',
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
290
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
291 'LINE1:maxdownstream#000000:Downstream (maximum)'
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
292 )
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
293
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
294 signalargs = (
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
295 '-a', 'SVG',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
296 '--vertical-label', 'dB',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
297 '--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
298 '-l', '0',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
299
19
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
300 '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
301 '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
302 '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
303
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
304 'CDEF:nmupdif=nmupmax,nmupmin,-',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
305
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
306 'LINE0.001:nmupmin#000000:',
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
307 '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
308 '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
309
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
310 '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
311 '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
312 '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
313
19
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
314 'CDEF:nmdowndif=nmdownmax,nmdownmin,-',
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
315
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
316 'LINE0.001:nmdownmin#000000:',
19
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
317 'AREA:nmdowndif#009a00::STACK',
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
318 '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
319
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
320 'DEF:attenup=%s:attenup:AVERAGE' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
321 'DEF:attenupmin=%s:attenup:MIN' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
322 'DEF:attenupmax=%s:attenup:MAX' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
323
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
324 'CDEF:attenupdif=attenupmax,attenupmin,-',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
325
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
326 'LINE0.001:attenupmin#000000:',
19
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
327 'AREA:attenupdif#f98100::STACK',
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
328 '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
329
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
330 'DEF:attendown=%s:attendown:AVERAGE' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
331 'DEF:attendownmin=%s:attendown:MIN' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
332 'DEF:attendownmax=%s:attendown:MAX' % rrdname,
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
333
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
334 'CDEF:attendowndif=attendownmax,attendownmin,-',
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
335
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
336 'LINE0.001:attendownmin#000000:',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
337 '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
338 '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
339
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
340 '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
341 '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
342 '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
343
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
344 'CDEF:powerupdif=powerupmax,powerupmin,-',
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
345
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
346 'LINE0.001:powerupmin#000000:',
19
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
347 'AREA:powerupdif#804007::STACK',
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
348 '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
349
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
350 '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
351 '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
352 '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
353
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
354 'CDEF:powerdowndif=powerdownmax,powerdownmin,-',
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
355
27
607111929e2e rrd no longer likes LINE0 so work around it
Daniel O'Connor <darius@dons.net.au>
parents: 26
diff changeset
356 'LINE0.001:powerdownmin#000000:',
19
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
357 'AREA:powerdowndif#604872::STACK',
5bec78c876db Properly re-arrange signal graph entries, show power.
Daniel O'Connor <darius@dons.net.au>
parents: 18
diff changeset
358 '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
359
21
8c44182a2984 Plot uptime.
Daniel O'Connor <darius@dons.net.au>
parents: 20
diff changeset
360 'DEF:uptime=%s:uptime:AVERAGE' % rrdname,
8c44182a2984 Plot uptime.
Daniel O'Connor <darius@dons.net.au>
parents: 20
diff changeset
361 'CDEF:uptimepct=uptime,10,*',
8c44182a2984 Plot uptime.
Daniel O'Connor <darius@dons.net.au>
parents: 20
diff changeset
362 '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
363 )
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
364
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
365 rrdtool.graph("%s-hour-link.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
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 - 7d',
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 *linkargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
371
31
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
372 rrdtool.graph("%s-daily-5y-link.svg" % (graphbasename),
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
373 '--width', '768',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
374 '--height', '256',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
375 '--start', 'end - 1825d',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
376 '--end', 'now',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
377 *linkargs)
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
378
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
379 rrdtool.graph("%s-daily-link.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
380 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
381 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
382 '--start', 'end - 365d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
383 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
384 *linkargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
385
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
386
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
387 rrdtool.graph("%s-hour-signal.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
388 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
389 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
390 '--start', 'end - 7d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
391 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
392 *signalargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
393
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
394 rrdtool.graph("%s-daily-signal.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
395 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
396 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
397 '--start', 'end - 365d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
398 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
399 *signalargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
400
31
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
401 rrdtool.graph("%s-daily-5y-signal.svg" % (graphbasename),
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
402 '--width', '768',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
403 '--height', '256',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
404 '--start', 'end - 1825d',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
405 '--end', 'now',
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
406 *signalargs)
39bf6dec0753 Add 5 year graphs
Daniel O'Connor <darius@dons.net.au>
parents: 30
diff changeset
407
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
408 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
409 names = ['Noise Margin (up)', 'Noise Margin (down)', 'Attenuation (up)', 'Attenuation (down)']
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
410 if args.munin != None:
17
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
411 # Handle the wrapper passing us its $0 as our $1
30
08cddcdb0db3 fix Munin plugin
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
412 args.munin = args.munin.split('_')[-1]
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
413 if args.munin not in ['signal', 'sync']:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
414 print("Unknown data type ", args.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
415 sys.exit(1)
30
08cddcdb0db3 fix Munin plugin
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
416 if len(args.rest) > 0:
08cddcdb0db3 fix Munin plugin
Daniel O'Connor <darius@dons.net.au>
parents: 27
diff changeset
417 if args.rest[0] == 'config':
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
418 if args.munin == 'signal':
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
419 print('''graph_category adsl
16
425d02592dce Rename ADSL to DSL
Daniel O'Connor <darius@dons.net.au>
parents: 15
diff changeset
420 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
421 graph_args --base 1000 -l 0
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
422 graph_vlabel dB''')
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
423 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
424 name = n.translate(None, ' ()').lower()
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
425 print('''%s.label %s
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
426 %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
427 %s.max 100
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
428 %s.min 0''' % (name, n, name, name, name))
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
429 elif args.munin == 'sync':
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
430 print('''graph_category adsl
16
425d02592dce Rename ADSL to DSL
Daniel O'Connor <darius@dons.net.au>
parents: 15
diff changeset
431 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
432 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
433 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
434 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
435 up.type GAUGE
17
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
436 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
437 up.min 0
10
88cf0a88c826 Fix cut & paste error
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
438 down.label Down
88cf0a88c826 Fix cut & paste error
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
439 down.type GAUGE
17
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
440 down.max 15000
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
441 down.min 0
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
442 upmax.label Up (max)
17
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
443 upmax.type GAUGE
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
444 upmax.max 150000
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
445 upmax.min 0
18
ec994073f70a Gather more stats (not plotted yet).
Daniel O'Connor <darius@dons.net.au>
parents: 17
diff changeset
446 downmax.label Down (max)
17
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
447 downmax.type GAUGE
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
448 downmax.max 150000
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
449 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
450 sys.exit(0)
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
451 if args.update or args.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
452 stats = getdata()
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
453 if args.verbose:
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
454 if stats == None:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
455 print("Modem is offline")
14
2debc3fb4372 Update for VDSL modem (TP-Link W9970).
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
456 else:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
457 print(stats)
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
458 if (args.update or args.munin != None) and stats != None:
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
459 if args.update:
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
460 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
461 os.stat(rrdname)
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
462 except OSError as e:
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
463 if e.errno == 2:
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
464 print("rrd not found, creating..")
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
465 makerrd(rrdname)
13
bf46efd061d7 Remove debugging and restore RRD update
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
466 updaterrd(rrdname, int(time.time()), stats)
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
467 if args.munin != None:
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
468 if args.munin == 'signal':
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
469 print('''noisemarginup.value %.1f
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
470 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
471 attenuationup.value %.1f
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
472 attenuationdown.value %.1f''' % (stats.nmup, stats.nmdown, stats.attenup, stats.attendown))
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
473 elif args.munin == 'sync':
17
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
474 s = '''up.value %.1f
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
475 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
476 if hasattr(stats, 'upstreammax'):
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
477 s += '''upmax.value %.1f
43f54da8baf9 Add max sync speeds to munin (untested)
Daniel O'Connor <darius@dons.net.au>
parents: 16
diff changeset
478 downmax.value %.1f''' % (stats.upstreammax, stats.downstreammax)
32
1af6865189ce Update to work with Python 3.
Daniel O'Connor <darius@dons.net.au>
parents: 31
diff changeset
479 print(s)
25
7571c101a4ee Read options properly so it's usable by others
Daniel O'Connor <darius@dons.net.au>
parents: 24
diff changeset
480 if args.graph:
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
481 gengraph()
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
482