annotate adslstats.py @ 12:a6297e8a42a3

Fix running with -g
author Daniel O'Connor <darius@dons.net.au>
date Thu, 08 Jan 2015 11:24:09 +1030
parents 88cf0a88c826
children bf46efd061d7
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 #
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
4 # Parse ADSL link stats for Billion 7300G & generate RRD archives & graphs
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
5 #
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
6 ############################################################################
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
7 #
9
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
8 # Copyright (C) 2015 Daniel O'Connor. All rights reserved.
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
9 #
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
10 # Redistribution and use in source and binary forms, with or without
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
11 # modification, are permitted provided that the following conditions
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
12 # are met:
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
13 # 1. Redistributions of source code must retain the above copyright
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
14 # notice, this list of conditions and the following disclaimer.
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
15 # 2. Redistributions in binary form must reproduce the above copyright
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
16 # notice, this list of conditions and the following disclaimer in the
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
17 # documentation and/or other materials provided with the distribution.
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
18 #
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
19 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
22 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
29 # SUCH DAMAGE.
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
30 #
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
31 ############################################################################
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
32
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
33 import ConfigParser
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
34 import optparse
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
35 import os
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
36 import re
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
37 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
38 import sys
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
39 import time
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
40 import urllib
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
41 from bs4 import BeautifulSoup
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
42
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
43 conf = ConfigParser.ConfigParser()
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
44 conf.add_section('global')
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
45 conf.set('global', 'username', 'admin')
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
46 conf.set('global', 'password', 'admin')
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
47 conf.set('global', 'name', 'dsl.dons.net.au')
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 conflist = ['adslstats.ini']
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
50 if ('HOME' in os.environ):
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
51 conflist.append(os.path.expanduser('~/.adslstats.ini'))
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
52 conf.read(conflist)
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
53
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
54 usage = '''%prog [options]'''
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
55 opts = optparse.OptionParser(usage)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
56 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
57 help="Enable debug output")
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
58 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
59 help="Generate a graph")
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
60 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
61 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
62 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
63 help="Output munin data for ARG")
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
64 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
65 help="Username to login to modem")
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
66 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
67 help="Password to login to modem")
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
68 opts.add_option('-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
69 help="Hostname of modem")
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
70 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
71 help="Base directory for RRD & PNGs")
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
72
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
73 (options, args) = opts.parse_args()
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
74
4
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
75 statsurl = "http://%s/statsadsl.html" % (options.name)
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
76 rrdname = "%s.rrd" % (options.base)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
77 graphbasename = options.base
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 matchnum = re.compile('([0-9]+(\.[0-9]+)?)')
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
80 statsdict = {
4
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
81 3 : 'Status:',
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
82 8 : 'SNR Margin (0.1 dB):',
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
83 9 : 'Attenuation (0.1 dB):',
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
84 14 : 'Rate (Kbps):',
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
85 }
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
86
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
87 class ADSLStats(object):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
88 def __str__(self):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
89 return """Line Rate - Up: %d kbits, Down %d kbits
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
90 Noise Margin - Up: %.1f dB, Down %.1f dB
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
91 Attenuation - Up: %.1f dB, Down %.1f dB""" % (self.upstream, self.downstream,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
92 self.nmup, self.nmdown,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
93 self.attenup, self.attendown)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
94 def getstats(f):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
95 s = BeautifulSoup(f)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
96 a = s.findAll('tr')
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
97
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
98 for i in statsdict:
4
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
99 assert a[i].td.contents[0] == statsdict[i]
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
100
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
101 stats = ADSLStats()
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
102
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
103 # Check if the modem is offline
6
671e66da2cb9 Fix check for modem being connected.
Daniel O'Connor <darius@dons.net.au>
parents: 5
diff changeset
104 if a[3].td.findNext('td').contents[0] != 'Up':
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
105 return None
4
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
106
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
107 # dB
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
108 stats.nmdown = float(a[8].td.findNext('td').contents[0]) / 10.0
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
109 stats.nmup = float(a[8].td.findNext('td').findNext('td').contents[0]) / 10.0
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
110 stats.attendown = float(a[9].td.findNext('td').contents[0]) / 10.0
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
111 stats.attenup = float(a[9].td.findNext('td').findNext('td').contents[0]) / 10.0
f50214bca1ae Update for Billion 7700NR2
Daniel O'Connor <darius@dons.net.au>
parents: 1
diff changeset
112 # kBit
8
e69ad89061dc Unswap up & down stream bit rates.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
113 stats.downstream = float(a[14].td.findNext('td').contents[0])
e69ad89061dc Unswap up & down stream bit rates.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
114 stats.upstream = float(a[14].td.findNext('td').findNext('td').contents[0])
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
115
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
116 return stats
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
117
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
118 # Setup RRD
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
119 # We expect data to be logged every 5 minutes
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
120 # Average 12 5 minute points -> hourly stats (keep 168 - a weeks worth)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
121 # Average 288 5 minute points -> daily stats (keep 365 - a 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
122 # 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
123 def makerrd(filename):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
124 rrdtool.create(filename,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
125 '--step', '300',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
126 'DS:upstream:GAUGE:3600:32:25000', # Upstream (kbits) - 24mbit is ADSL2+ max
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
127 'DS:downstream:GAUGE:3600:32:25000', # Downstream (kbits)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
128 '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
129 '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
130 'DS:attenup:GAUGE:3600:0:100', # Upstream Attenuation (dB)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
131 'DS:attendown:GAUGE:3600:0:100', # Downstream Attenuation (dB)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
132 'RRA:AVERAGE:0.1:12:168',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
133 'RRA:AVERAGE:0.1:288:365',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
134 'RRA:MIN:0.1:12:168',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
135 'RRA:MAX:0.1:12:168')
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
136
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
137 # Update the RRD (format stats as expected)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
138 def updaterrd(filename, tstamp, stats):
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
139 rrdtool.update(filename,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
140 '%d:%d:%d:%f:%f:%f:%f' % (tstamp,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
141 stats.upstream,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
142 stats.downstream,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
143 stats.nmup,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
144 stats.nmdown,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
145 stats.attenup,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
146 stats.attendown))
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
147
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
148 # 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
149 def getdata():
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
150 opener = urllib.FancyURLopener()
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
151 opener.prompt_user_passwd = lambda host, realm: (options.authname, options.password)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
152 f = opener.open(statsurl)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
153 #f = open("adsl.html")
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
154 stats = getstats(f)
1
a795b6cd8b1a Add command line options.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
155 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
156 return 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
157 return stats
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
158
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
159 # Generate a graph
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
160 def gengraph():
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
161
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
162 linkargs = (
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
163 '-a', 'SVG',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
164 '-X', '0',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
165 '--vertical-label', 'kbit/sec',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
166 '--slope-mode',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
167
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
168 'DEF:upstream=%s:upstream:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
169 'DEF:upstreammin=%s:upstream:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
170 'DEF:upstreammax=%s:upstream:MAX' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
171
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
172 'DEF:downstream=%s:downstream:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
173 'DEF:downstreammin=%s:downstream:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
174 'DEF:downstreammax=%s:downstream:MAX' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
175
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
176 'CDEF:upstreamdif=upstreammax,upstreammin,-',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
177 'CDEF:downstreamdif=downstreammax,downstreammin,-',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
178
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
179 'LINE0:upstreammin#000000:',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
180 'AREA:upstreamdif#00dc76::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
181 'LINE1:upstream#00ff00:Upstream',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
182
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
183 'LINE0:downstreammin#000000:',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
184 'AREA:downstreamdif#ff8686::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
185 'LINE1:downstream#ff0000:Downstream')
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
186
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
187 signalargs = (
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
188 '-a', 'SVG',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
189 '--vertical-label', 'dB',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
190 '--slope-mode',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
191
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
192 'DEF:upstream=%s:upstream:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
193 'DEF:downstream=%s:downstream:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
194
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
195 'DEF:nmup_=%s:nmup:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
196 'DEF:nmupmin_=%s:nmup:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
197 'DEF:nmupmax_=%s:nmup:MAX' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
198
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
199 'DEF:nmdown_=%s:nmdown:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
200 'DEF:nmdownmin_=%s:nmdown:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
201 'DEF:nmdownmax_=%s:nmdown:MAX' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
202
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
203 'DEF:attenup=%s:attenup:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
204 'DEF:attenupmin=%s:attenup:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
205 'DEF:attenupmax=%s:attenup:MAX' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
206
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
207 'DEF:attendown=%s:attendown:AVERAGE' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
208 'DEF:attendownmin=%s:attendown:MIN' % rrdname,
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
209 'DEF:attendownmax=%s:attendown:MAX' % rrdname,
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 'CDEF:nmup=nmup_,10,*',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
212 'CDEF:nmupmin=nmupmin_,10,*',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
213 'CDEF:nmupmax=nmupmax_,10,*',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
214 'CDEF:nmupdif=nmupmax,nmupmin,-',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
215
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
216 'CDEF:nmdown=nmdown_,10,*',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
217 'CDEF:nmdownmin=nmdownmin_,10,*',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
218 'CDEF:nmdownmax=nmdownmax_,10,*',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
219 'CDEF:nmdowndif=nmdownmax,nmdownmin,-',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
220
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
221 'CDEF:attenupdif=attenupmax,attenupmin,-',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
222
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
223 'CDEF:attendowndif=attendownmax,attendownmin,-',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
224
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
225 'LINE0:nmupmin#000000:',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
226 'AREA:nmupdif#5c5cff::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
227 'LINE1:nmup#0000ff:Noise Margin - Up (1/10 dB)',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
228
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
229 'LINE0:nmdownmin#000000:',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
230 'AREA:nmdowndif#009a00::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
231 'LINE1:nmdown#00ff00:Noise Margin - Down (1/10 dB)',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
232
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
233 'LINE0:attenupmin#000000:',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
234 'AREA:attenupdif#f98100::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
235 'LINE1:attenup#ff0000:Attenuation - Up',
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 'LINE0:attendownmin#000000:',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
238 'AREA:attendowndif#aaaaaa::STACK',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
239 'LINE1:attendown#000000:Attenuation - Down')
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
240
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
241 rrdtool.graph("%s-hour-link.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
242 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
243 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
244 '--start', 'end - 7d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
245 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
246 *linkargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
247
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
248 rrdtool.graph("%s-daily-link.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
249 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
250 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
251 '--start', 'end - 365d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
252 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
253 *linkargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
254
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
255
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
256 rrdtool.graph("%s-hour-signal.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
257 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
258 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
259 '--start', 'end - 7d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
260 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
261 *signalargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
262
5
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
263 rrdtool.graph("%s-daily-signal.svg" % (graphbasename),
072489c80c51 Change from PNG to SVG
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
264 '--width', '768',
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
265 '--height', '256',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
266 '--start', 'end - 365d',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
267 '--end', 'now',
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
268 *signalargs)
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
269
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
270 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
271 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
272 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
273 # Handle the wrapper passing us $0 directly
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
274 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
275 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
276 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
277 if options.munin not in ['signal', '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
278 print "Unknown data type"
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
279 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
280 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
281 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
282 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
283 print '''graph_category adsl
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
284 graph_title ADSL Signal Quality
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
285 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
286 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
287 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
288 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
289 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
290 %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
291 %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
292 %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
293 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
294 print '''graph_category adsl
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
295 graph_title ADSL Sync Speed
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
296 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
297 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
298 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
299 up.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
300 up.max 24000
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
301 up.min 0
10
88cf0a88c826 Fix cut & paste error
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
302 down.label Down
88cf0a88c826 Fix cut & paste error
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
303 down.type GAUGE
88cf0a88c826 Fix cut & paste error
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
304 down.max 24000
88cf0a88c826 Fix cut & paste error
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
305 down.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
306 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
307 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
308 stats = getdata()
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
309 if stats == 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
310 if options.verbose:
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
311 print "Modem is offline"
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
312
12
a6297e8a42a3 Fix running with -g
Daniel O'Connor <darius@dons.net.au>
parents: 10
diff changeset
313 if (options.update or options.munin) 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
314 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
315 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
316 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
317 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
318 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
319 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
320 makerrd(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
321
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
322 print '%d:%d:%d:%f:%f:%f:%f' % (int(time.time()),
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
323 stats.upstream,
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
324 stats.downstream,
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
325 stats.nmup,
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
326 stats.nmdown,
8b5958404f81 Add support for running as a munin plugin and a simple wrapper script.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
327 stats.attenup,
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
328 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
329 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
330 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
331 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
332 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
333 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
334 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
335 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
336 print '''up.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
337 down.value %.1f''' % (stats.upstream, stats.downstream)
0
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
338
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
339 if options.graph:
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
340 gengraph()
98fe11ea4c82 Initial commit of Billion ADSL stats monitor using RRD.
darius@Inchoate
parents:
diff changeset
341