changeset 7:98d351a87043

merge
author Daniel O'Connor <darius@dons.net.au>
date Sat, 08 Feb 2014 09:21:57 +1030
parents 671e66da2cb9 (diff) 3748cec0e322 (current diff)
children e69ad89061dc
files adsl.html adslstats.py
diffstat 1 files changed, 32 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/adslstats.py	Wed Nov 20 23:56:29 2013 +1030
+++ b/adslstats.py	Sat Feb 08 09:21:57 2014 +1030
@@ -69,10 +69,18 @@
 
 (options, args) = opts.parse_args()
 
-statsurl = "http://%s/status/status_deviceinfo.htm" % (options.name)
+statsurl = "http://%s/statsadsl.html" % (options.name)
 rrdname = "%s.rrd" % (options.base)
 graphbasename = options.base
 
+matchnum = re.compile('([0-9]+(\.[0-9]+)?)')
+statsdict = {
+    3 : 'Status:',
+    8 : 'SNR Margin (0.1 dB):',
+    9 : 'Attenuation (0.1 dB):',
+    14 : 'Rate (Kbps):',
+}
+
 class ADSLStats(object):
     def __str__(self):
         return """Line Rate - Up: %d kbits, Down %d kbits
@@ -83,38 +91,25 @@
 
 def getstats(f):
     s = BeautifulSoup(f)
-    a = s.findAll('td')
+    a = s.findAll('tr')
     
-    # Sanity check in case the firmware changes page layout
-    assert(a[122]('font')[0].contents[0] == 'SNR Margin')
-    assert(a[129]('font')[0].contents[0] == 'Line Attenuation')
-    assert(a[136]('font')[0].contents[0] == 'Data Rate')
-
-    # Check if the modem is offline
-    if a[124].contents[0].strip() == 'N/A':
-	return None
+    for i in statsdict:
+        assert a[i].td.contents[0] == statsdict[i]
 
     stats = ADSLStats()
-
-    stats.nmdown = float(a[124].contents[0])		# dB
-    stats.nmup = float(a[125].contents[0])		# dB
-
-    stats.attendown = float(a[131].contents[0])		# dB
-    stats.attenup = float(a[132].contents[0])		# dB
-
-    stats.downstream = float(a[138].contents[0])	# kbit/sec
-    stats.upstream = float(a[139].contents[0])		# kbit/sec
     
     # Check if the modem is offline
-    if a[9].td.findNext('td').contents[0].contents[0].find('N/A') != -1:
+    if a[3].td.findNext('td').contents[0] != 'Up':
 	return None
-    stats.upstream = cleannum(a[7].td.findNext('td').contents[0].contents[0])   # kbits
-    stats.downstream = cleannum(a[8].td.findNext('td').contents[0].contents[0]) # kbits
-    stats.nmup = cleannum(a[9].td.findNext('td').contents[0].contents[0])       # dB
-    stats.nmdown = cleannum(a[10].td.findNext('td').contents[0].contents[0])    # dB
-    stats.attenup = cleannum(a[11].td.findNext('td').contents[0].contents[0])   # dB
-    stats.attendown = cleannum(a[12].td.findNext('td').contents[0].contents[0]) # dB
->>>>>>> other
+
+    # dB
+    stats.nmdown = float(a[8].td.findNext('td').contents[0]) / 10.0
+    stats.nmup = float(a[8].td.findNext('td').findNext('td').contents[0]) / 10.0
+    stats.attendown = float(a[9].td.findNext('td').contents[0]) / 10.0
+    stats.attenup = float(a[9].td.findNext('td').findNext('td').contents[0]) / 10.0
+    # kBit
+    stats.upstream = float(a[14].td.findNext('td').contents[0])
+    stats.downstream = float(a[14].td.findNext('td').findNext('td').contents[0])
 
     return stats
 
@@ -167,7 +162,7 @@
 def gengraph():
 
     linkargs = (
-        '-a', 'PNG',
+        '-a', 'SVG',
         '-X', '0',
         '--vertical-label', 'kbit/sec',
         '--slope-mode',
@@ -192,7 +187,7 @@
         'LINE1:downstream#ff0000:Downstream')
 
     signalargs = (
-        '-a', 'PNG',
+        '-a', 'SVG',
         '--vertical-label', 'dB',
         '--slope-mode',
 
@@ -245,30 +240,30 @@
         'AREA:attendowndif#aaaaaa::STACK',
         'LINE1:attendown#000000:Attenuation - Down')
     
-    rrdtool.graph("%s-hour-link.png" % (graphbasename),
-                  '--width', '1024',
+    rrdtool.graph("%s-hour-link.svg" % (graphbasename),
+                  '--width', '768',
                   '--height', '256',
                   '--start', 'end - 7d',
                   '--end', 'now',
                   *linkargs)
 
-    rrdtool.graph("%s-daily-link.png" % (graphbasename),
-                  '--width', '1024',
+    rrdtool.graph("%s-daily-link.svg" % (graphbasename),
+                  '--width', '768',
                   '--height', '256',
                   '--start', 'end - 365d',
                   '--end', 'now',
                   *linkargs)
 
 
-    rrdtool.graph("%s-hour-signal.png" % (graphbasename),
-                  '--width', '1024',
+    rrdtool.graph("%s-hour-signal.svg" % (graphbasename),
+                  '--width', '768',
                   '--height', '256',
                   '--start', 'end - 7d',
                   '--end', 'now',
                   *signalargs)
 
-    rrdtool.graph("%s-daily-signal.png" % (graphbasename),
-                  '--width', '1024',
+    rrdtool.graph("%s-daily-signal.svg" % (graphbasename),
+                  '--width', '768',
                   '--height', '256',
                   '--start', 'end - 365d',
                   '--end', 'now',