]>
Commit | Line | Data |
---|---|---|
ceda40f2 MT |
1 | /* refreshInetInfo.js |
2 | * functions for retrieving status information via jQuery | |
3 | * Modified: March 6th, 2013 by michael@koehler.tk | |
4 | * Authors: IPFire Team (info@ipfire.org) | |
5 | Kay-Michael Köhler (michael@koehler.tk) | |
6 | * Visit http://www.ipfire.org/ | |
7 | */ | |
8 | ||
9 | var t_current; | |
10 | var t_last = 0; | |
11 | var rxb_current; | |
12 | var rxb_last = 0; | |
13 | var txb_current; | |
14 | var txb_last = 0; | |
15 | ||
16 | $(document).ready(function(){ | |
17 | refreshInetInfo(); | |
18 | }); | |
19 | ||
20 | function refreshInetInfo() { | |
21 | $.ajax({ | |
22 | url: '/cgi-bin/speed.cgi', | |
865c7615 | 23 | success: function(xml) { |
ceda40f2 MT |
24 | t_current = new Date(); |
25 | var t_diff = t_current - t_last; | |
26 | ||
865c7615 | 27 | rxb_current = $("rxb", xml).text(); |
ceda40f2 MT |
28 | var rxb_diff = rxb_current - rxb_last; |
29 | rxb_last = rxb_current; | |
30 | ||
926241ae | 31 | var rx_bits = rxb_diff * 8192 / t_diff; |
865c7615 | 32 | var rx_fmt = format_bytes(rx_bits); |
ceda40f2 | 33 | |
865c7615 | 34 | txb_current = $("txb", xml).text(); |
ceda40f2 MT |
35 | var txb_diff = txb_current - txb_last; |
36 | txb_last = txb_current; | |
37 | ||
926241ae | 38 | var tx_bits = txb_diff * 8192 / t_diff; |
865c7615 | 39 | var tx_fmt = format_bytes(tx_bits); |
ceda40f2 MT |
40 | |
41 | if (t_last != 0) { | |
865c7615 MT |
42 | $("#rx_kbs").text(rx_fmt); |
43 | $("#tx_kbs").text(tx_fmt); | |
ceda40f2 MT |
44 | } |
45 | ||
46 | t_last = t_current; | |
47 | } | |
48 | }); | |
49 | ||
50 | window.setTimeout("refreshInetInfo()", 2000); | |
51 | } | |
865c7615 MT |
52 | |
53 | function format_bytes(bytes) { | |
54 | var units = ["Bit/s", "kBit/s", "MBit/s", "GBit/s", "TBit/s"]; | |
55 | ||
56 | var unit = units[0]; | |
57 | for (var i = 1; i < units.length; i++) { | |
58 | if (bytes < 1024) | |
59 | break; | |
60 | ||
61 | unit = units[i]; | |
62 | bytes /= 1024; | |
63 | } | |
64 | ||
65 | // Round the output. | |
66 | bytes = bytes.toFixed(2); | |
67 | ||
68 | return bytes + " " + unit; | |
69 | } |