From: Michael Tremer Date: Sun, 5 Jan 2014 13:40:06 +0000 (+0100) Subject: speedmeter: Show speeds in Bit/s, kBit/s, MBit/s, ... X-Git-Url: http://git.ipfire.org/?p=people%2Fteissler%2Fipfire-2.x.git;a=commitdiff_plain;h=865c76157580b18551df1033781fbf3b8fccc8e6 speedmeter: Show speeds in Bit/s, kBit/s, MBit/s, ... Also clean up the dirty HTML code. --- diff --git a/html/html/themes/ipfire-new/include/functions.pl b/html/html/themes/ipfire-new/include/functions.pl index b644c073d..a060ead7d 100644 --- a/html/html/themes/ipfire-new/include/functions.pl +++ b/html/html/themes/ipfire-new/include/functions.pl @@ -73,13 +73,19 @@ sub showmenu() { &showsubmenu($submenus) if ($submenus); print ""; } + print ""; + if ($settings{'SPEED'} ne 'off') { - print"
"; - print""; - print""; - print"
Traffic:  In   Out
"; - print '
'; + print < + Traffic: + In --.-- Bit/s   + Out --.-- Bit/s + +EOF } + + print ""; } ############################################################################### diff --git a/html/html/themes/ipfire-new/include/js/refreshInetInfo.js b/html/html/themes/ipfire-new/include/js/refreshInetInfo.js index ed4a966b4..f17b50a9a 100644 --- a/html/html/themes/ipfire-new/include/js/refreshInetInfo.js +++ b/html/html/themes/ipfire-new/include/js/refreshInetInfo.js @@ -20,30 +20,27 @@ $(document).ready(function(){ function refreshInetInfo() { $.ajax({ url: '/cgi-bin/speed.cgi', - success: function(xml){ - + success: function(xml) { t_current = new Date(); var t_diff = t_current - t_last; - rxb_current = $("rxb",xml).text(); + rxb_current = $("rxb", xml).text(); var rxb_diff = rxb_current - rxb_last; rxb_last = rxb_current; - var rx_kbs = rxb_diff/t_diff; - rx_kbs = Math.round(rx_kbs*10)/10; + var rx_bits = rxb_diff * 1024 / t_diff; + var rx_fmt = format_bytes(rx_bits); - txb_current = $("txb",xml).text(); + txb_current = $("txb", xml).text(); var txb_diff = txb_current - txb_last; txb_last = txb_current; - var tx_kbs = txb_diff/t_diff; - tx_kbs = Math.round(tx_kbs*10)/10; + var tx_bits = txb_diff * 1024 / t_diff; + var tx_fmt = format_bytes(tx_bits); if (t_last != 0) { - $("#rx_kbs").text(rx_kbs + ' kb/s'); - $("#tx_kbs").text(tx_kbs + ' kb/s'); - if ($("#bandwidthCalculationContainer").css('display') == 'none') - $("#bandwidthCalculationContainer").css('display','block'); + $("#rx_kbs").text(rx_fmt); + $("#tx_kbs").text(tx_fmt); } t_last = t_current; @@ -52,3 +49,21 @@ function refreshInetInfo() { window.setTimeout("refreshInetInfo()", 2000); } + +function format_bytes(bytes) { + var units = ["Bit/s", "kBit/s", "MBit/s", "GBit/s", "TBit/s"]; + + var unit = units[0]; + for (var i = 1; i < units.length; i++) { + if (bytes < 1024) + break; + + unit = units[i]; + bytes /= 1024; + } + + // Round the output. + bytes = bytes.toFixed(2); + + return bytes + " " + unit; +}