comparison adslstats.py @ 16:425d02592dce

Rename ADSL to DSL
author Daniel O'Connor <darius@dons.net.au>
date Fri, 20 May 2016 15:09:03 +0930
parents 7dbe86981f6b
children 43f54da8baf9
comparison
equal deleted inserted replaced
15:7dbe86981f6b 16:425d02592dce
1 #!/usr/bin/env python2 1 #!/usr/bin/env python2
2 ############################################################################ 2 ############################################################################
3 # 3 #
4 # Parse ADSL link stats for TP-Link W9970 & generate RRD archives & graphs 4 # Parse DSL link stats for TP-Link W9970 & generate RRD archives & graphs
5 # 5 #
6 ############################################################################ 6 ############################################################################
7 # 7 #
8 # Copyright (C) 2015 Daniel O'Connor. All rights reserved. 8 # Copyright (C) 2015 Daniel O'Connor. All rights reserved.
9 # 9 #
84 8 : 'SNR Margin (0.1 dB):', 84 8 : 'SNR Margin (0.1 dB):',
85 9 : 'Attenuation (0.1 dB):', 85 9 : 'Attenuation (0.1 dB):',
86 14 : 'Rate (Kbps):', 86 14 : 'Rate (Kbps):',
87 } 87 }
88 88
89 class ADSLStats(object): 89 class DSLStats(object):
90 def __str__(self): 90 def __str__(self):
91 s = "Line Rate - Up: %d kbits, Down %d kbits\n" % (self.upstream, self.downstream) 91 s = "Line Rate - Up: %d kbits, Down %d kbits\n" % (self.upstream, self.downstream)
92 if hasattr(self, 'upstreammax'): 92 if hasattr(self, 'upstreammax'):
93 s += "Maximum Rate - Up: %d kbit, Down %s kbit\n" % (self.upstreammax, self.downstreammax) 93 s += "Maximum Rate - Up: %d kbit, Down %s kbit\n" % (self.upstreammax, self.downstreammax)
94 s += """Noise Margin - Up: %.1f dB, Down %.1f dB 94 s += """Noise Margin - Up: %.1f dB, Down %.1f dB
95 Attenuation - Up: %.1f dB, Down %.1f dB""" % (self.nmup, self.nmdown, 95 Attenuation - Up: %.1f dB, Down %.1f dB""" % (self.nmup, self.nmdown,
96 self.attenup, self.attendown) 96 self.attenup, self.attendown)
97 return s 97 return s
98 98
99 def getstats(): 99 def getstats():
100 stats = ADSLStats() 100 stats = DSLStats()
101 parser = ConfigParser.ConfigParser() 101 parser = ConfigParser.ConfigParser()
102 base = 'http://%s' % (conf.get('global', 'name')) 102 base = 'http://%s' % (conf.get('global', 'name'))
103 # Gunk extracted from Chrome (what the page is requesting). Note it's sensitive to line ending type... 103 # Gunk extracted from Chrome (what the page is requesting). Note it's sensitive to line ending type...
104 # We could get more data, eg error rates.. 104 # We could get more data, eg error rates..
105 data = '[WAN_DSL_INTF_CFG#1,0,0,0,0,0#0,0,0,0,0,0]0,12\r\nstatus\r\nmodulationType\r\nX_TP_AdslModulationCfg\r\nupstreamCurrRate\r\ndownstreamCurrRate\r\nX_TP_AnnexType\r\nupstreamMaxRate\r\ndownstreamMaxRate\r\nupstreamNoiseMargin\r\ndownstreamNoiseMargin\r\nupstreamAttenuation\r\ndownstreamAttenuation\r\n[WAN_DSL_INTF_STATS_TOTAL#1,0,0,0,0,0#0,0,0,0,0,0]1,8\r\nATUCCRCErrors\r\nCRCErrors\r\nATUCFECErrors\r\nFECErrors\r\nSeverelyErroredSecs\r\nX_TP_US_SeverelyErroredSecs\r\nerroredSecs\r\nX_TP_US_ErroredSecs\r\n' 105 data = '[WAN_DSL_INTF_CFG#1,0,0,0,0,0#0,0,0,0,0,0]0,12\r\nstatus\r\nmodulationType\r\nX_TP_AdslModulationCfg\r\nupstreamCurrRate\r\ndownstreamCurrRate\r\nX_TP_AnnexType\r\nupstreamMaxRate\r\ndownstreamMaxRate\r\nupstreamNoiseMargin\r\ndownstreamNoiseMargin\r\nupstreamAttenuation\r\ndownstreamAttenuation\r\n[WAN_DSL_INTF_STATS_TOTAL#1,0,0,0,0,0#0,0,0,0,0,0]1,8\r\nATUCCRCErrors\r\nCRCErrors\r\nATUCFECErrors\r\nFECErrors\r\nSeverelyErroredSecs\r\nX_TP_US_SeverelyErroredSecs\r\nerroredSecs\r\nX_TP_US_ErroredSecs\r\n'
295 sys.exit(1) 295 sys.exit(1)
296 if len(args) > 0: 296 if len(args) > 0:
297 if args[0] == 'config': 297 if args[0] == 'config':
298 if options.munin == 'signal': 298 if options.munin == 'signal':
299 print '''graph_category adsl 299 print '''graph_category adsl
300 graph_title ADSL Signal Quality 300 graph_title DSL Signal Quality
301 graph_args --base 1000 -l 0 301 graph_args --base 1000 -l 0
302 graph_vlabel dB''' 302 graph_vlabel dB'''
303 for n in names: 303 for n in names:
304 name = n.translate(None, ' ()').lower() 304 name = n.translate(None, ' ()').lower()
305 print '''%s.label %s 305 print '''%s.label %s
306 %s.type GAUGE 306 %s.type GAUGE
307 %s.max 100 307 %s.max 100
308 %s.min 0''' % (name, n, name, name, name) 308 %s.min 0''' % (name, n, name, name, name)
309 elif options.munin == 'sync': 309 elif options.munin == 'sync':
310 print '''graph_category adsl 310 print '''graph_category adsl
311 graph_title ADSL Sync Speed 311 graph_title DSL Sync Speed
312 graph_args --base 1024 -l 0 312 graph_args --base 1024 -l 0
313 graph_vlabel kbit/sec 313 graph_vlabel kbit/sec
314 up.label Up 314 up.label Up
315 up.type GAUGE 315 up.type GAUGE
316 up.max 24000 316 up.max 24000