diff options
Diffstat (limited to 'modules/admin-full/luasrc/view/admin_status/bandwidth.htm')
-rw-r--r-- | modules/admin-full/luasrc/view/admin_status/bandwidth.htm | 202 |
1 files changed, 97 insertions, 105 deletions
diff --git a/modules/admin-full/luasrc/view/admin_status/bandwidth.htm b/modules/admin-full/luasrc/view/admin_status/bandwidth.htm index d898cb1c1..da6837370 100644 --- a/modules/admin-full/luasrc/view/admin_status/bandwidth.htm +++ b/modules/admin-full/luasrc/view/admin_status/bandwidth.htm @@ -96,109 +96,6 @@ $Id$ ); } - function update_graph() - { - bwxhr.get('<%=build_url("admin/status/bandwidth_status", curdev)%>', null, - function(x, data) - { - var data_max = 0; - var data_scale = 0; - - var data_rx_avg = 0; - var data_tx_avg = 0; - - var data_rx_peak = 0; - var data_tx_peak = 0; - - for (var i = data_stamp ? 0 : 1; i < data.length; i++) - { - /* skip overlapping entries */ - if (data[i][TIME] <= data_stamp) - continue; - - /* normalize difference against time interval */ - var time_delta = data[i][TIME] - data[i-1][TIME]; - if (time_delta) - { - data_rx.push((data[i][RXB] - data[i-1][RXB]) / time_delta); - data_tx.push((data[i][TXB] - data[i-1][TXB]) / time_delta); - } - } - - /* cut off outdated entries */ - data_rx = data_rx.slice(data_rx.length - data_wanted, data_rx.length); - data_tx = data_tx.slice(data_tx.length - data_wanted, data_tx.length); - - /* find peak */ - for (var i = 0; i < data_rx.length; i++) - { - data_max = Math.max(data_max, data_rx[i]); - data_max = Math.max(data_max, data_tx[i]); - - data_rx_peak = Math.max(data_rx_peak, data_rx[i]); - data_tx_peak = Math.max(data_tx_peak, data_tx[i]); - - if (i > 0) - { - data_rx_avg = (data_rx_avg + data_rx[i]) / 2; - data_tx_avg = (data_tx_avg + data_tx[i]) / 2; - } - else - { - data_rx_avg = data_rx[i]; - data_tx_avg = data_tx[i]; - } - } - - /* remember current timestamp, calculate horizontal scale */ - data_stamp = data[data.length-1][TIME]; - data_scale = height / (data_max * 1.1); - - - /* plot data */ - var pt_rx = '0,' + height; - var pt_tx = '0,' + height; - - var y_rx = 0; - var y_tx = 0; - - for (var i = 0; i < data_rx.length; i++) - { - var x = i * step; - - y_rx = height - Math.floor(data_rx[i] * data_scale); - y_tx = height - Math.floor(data_tx[i] * data_scale); - - pt_rx += ' ' + x + ',' + y_rx; - pt_tx += ' ' + x + ',' + y_tx; - } - - pt_rx += ' ' + width + ',' + y_rx + ' ' + width + ',' + height; - pt_tx += ' ' + width + ',' + y_tx + ' ' + width + ',' + height; - - - line_rx.setAttribute('points', pt_rx); - line_tx.setAttribute('points', pt_tx); - - label_25.firstChild.data = bandwidth_label(1.1 * 0.25 * data_max); - label_50.firstChild.data = bandwidth_label(1.1 * 0.50 * data_max); - label_75.firstChild.data = bandwidth_label(1.1 * 0.75 * data_max); - - label_rx_cur.innerHTML = bandwidth_label(data_rx[data_rx.length-1], true); - label_tx_cur.innerHTML = bandwidth_label(data_tx[data_tx.length-1], true); - - label_rx_avg.innerHTML = bandwidth_label(data_rx_avg, true); - label_tx_avg.innerHTML = bandwidth_label(data_tx_avg, true); - - label_rx_peak.innerHTML = bandwidth_label(data_rx_peak, true); - label_tx_peak.innerHTML = bandwidth_label(data_tx_peak, true); - - /* reset timer */ - window.setTimeout(update_graph, 1000); - } - ) - } - /* wait for SVG */ window.setTimeout( function() { @@ -269,10 +166,105 @@ $Id$ label_25.parentNode.appendChild(text); } - label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 1); + label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); /* render datasets, start update interval */ - update_graph(); + XHR.poll(3, '<%=build_url("admin/status/bandwidth_status", curdev)%>', null, + function(x, data) + { + var data_max = 0; + var data_scale = 0; + + var data_rx_avg = 0; + var data_tx_avg = 0; + + var data_rx_peak = 0; + var data_tx_peak = 0; + + for (var i = data_stamp ? 0 : 1; i < data.length; i++) + { + /* skip overlapping entries */ + if (data[i][TIME] <= data_stamp) + continue; + + /* normalize difference against time interval */ + var time_delta = data[i][TIME] - data[i-1][TIME]; + if (time_delta) + { + data_rx.push((data[i][RXB] - data[i-1][RXB]) / time_delta); + data_tx.push((data[i][TXB] - data[i-1][TXB]) / time_delta); + } + } + + /* cut off outdated entries */ + data_rx = data_rx.slice(data_rx.length - data_wanted, data_rx.length); + data_tx = data_tx.slice(data_tx.length - data_wanted, data_tx.length); + + /* find peak */ + for (var i = 0; i < data_rx.length; i++) + { + data_max = Math.max(data_max, data_rx[i]); + data_max = Math.max(data_max, data_tx[i]); + + data_rx_peak = Math.max(data_rx_peak, data_rx[i]); + data_tx_peak = Math.max(data_tx_peak, data_tx[i]); + + if (i > 0) + { + data_rx_avg = (data_rx_avg + data_rx[i]) / 2; + data_tx_avg = (data_tx_avg + data_tx[i]) / 2; + } + else + { + data_rx_avg = data_rx[i]; + data_tx_avg = data_tx[i]; + } + } + + /* remember current timestamp, calculate horizontal scale */ + data_stamp = data[data.length-1][TIME]; + data_scale = height / (data_max * 1.1); + + + /* plot data */ + var pt_rx = '0,' + height; + var pt_tx = '0,' + height; + + var y_rx = 0; + var y_tx = 0; + + for (var i = 0; i < data_rx.length; i++) + { + var x = i * step; + + y_rx = height - Math.floor(data_rx[i] * data_scale); + y_tx = height - Math.floor(data_tx[i] * data_scale); + + pt_rx += ' ' + x + ',' + y_rx; + pt_tx += ' ' + x + ',' + y_tx; + } + + pt_rx += ' ' + width + ',' + y_rx + ' ' + width + ',' + height; + pt_tx += ' ' + width + ',' + y_tx + ' ' + width + ',' + height; + + + line_rx.setAttribute('points', pt_rx); + line_tx.setAttribute('points', pt_tx); + + label_25.firstChild.data = bandwidth_label(1.1 * 0.25 * data_max); + label_50.firstChild.data = bandwidth_label(1.1 * 0.50 * data_max); + label_75.firstChild.data = bandwidth_label(1.1 * 0.75 * data_max); + + label_rx_cur.innerHTML = bandwidth_label(data_rx[data_rx.length-1], true); + label_tx_cur.innerHTML = bandwidth_label(data_tx[data_tx.length-1], true); + + label_rx_avg.innerHTML = bandwidth_label(data_rx_avg, true); + label_tx_avg.innerHTML = bandwidth_label(data_tx_avg, true); + + label_rx_peak.innerHTML = bandwidth_label(data_rx_peak, true); + label_tx_peak.innerHTML = bandwidth_label(data_tx_peak, true); + } + ); } }, 1000 ); |