Skip to content

Commit

Permalink
Merge pull request #11 from dfberger/host-aggregation
Browse files Browse the repository at this point in the history
Calculate per-host aggregate rows
  • Loading branch information
Kiougar authored Jun 4, 2017
2 parents 66c58bf + e2d779a commit 9352095
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions luci-wrtbwmon/htdocs/luci-static/wrtbwmon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// interval in seconds
var scheduleTimeout, updateTimeout, isScheduled = true, interval = 5;
var sortedColumn = 7, sortedEltId = "thTotal", sortDirection = "desc";
var perHostTotals = false, showPerHostTotalsOnly = false;

(function () {
var oldDate, oldValues = [];
Expand Down Expand Up @@ -51,6 +52,41 @@ var sortedColumn = 7, sortedEltId = "thTotal", sortDirection = "desc";
}
}

// aggregate (sub-total) by hostname (or MAC address) after the global totals are computed, before sort and display
if (perHostTotals) {
var curHost = 0, insertAt = 1;
while (curHost < data.length && insertAt < data.length) {
// grab the current hostname/mac, and walk the data looking for rows with the same host/mac
var hostName = data[curHost][1][0].toLowerCase();
for (var k = curHost+1; k < data.length; k++) {
if (data[k][1][0].toLowerCase() == hostName) {
// this is another row for the same host, group it with any other rows for this host
data.splice(insertAt, 0, data.splice(k, 1)[0]);
insertAt++;
}
}

// if we found more than one row for the host, add a subtotal row
if (insertAt > curHost+1) {
var hostTotals = [data[curHost][1][0], '', '', 0, 0, 0, 0, 0];
for (var i = curHost; i < insertAt && i < data.length; i++) {
for (var j = 3; j < hostTotals.length; j++) {
hostTotals[j] += data[i][1][j];
}
}
var hostTotalRow = '<tr><th title="' + data[curHost][1][1] + '">' + data[curHost][1][0] + '<br/> (host total) </th>';
for (var m = 3; m < hostTotals.length; m++) {
var t = hostTotals[m];
hostTotalRow += '<td align="right">' + getSize(t) + (m < 5 ? '/s' : '') + '</td>'
}
hostTotalRow += '</tr>';
data.splice(insertAt, 0, [hostTotalRow, hostTotals]);
}
curHost = insertAt;
insertAt = curHost+1;
}
}

data.sort(function (x, y) {
var a = x[1][sortedColumn];
var b = y[1][sortedColumn];
Expand Down Expand Up @@ -222,6 +258,15 @@ var sortedColumn = 7, sortedEltId = "thTotal", sortDirection = "desc";
}
});

document.getElementById('perHostTotals').addEventListener('change', function () {
perHostTotals = !perHostTotals;
});

//document.getElementById('showPerHostTotalsOnly').addEventListener('change', function () {
// showPerHostTotalsOnly = !showPerHostTotalsOnly;
//});


function stopSchedule() {
window.clearTimeout(scheduleTimeout);
window.clearTimeout(updateTimeout);
Expand Down
9 changes: 9 additions & 0 deletions luci-wrtbwmon/luasrc/view/wrtbwmon.htm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ <h2>Network Usage:</h2>
<option value="360">5 minutes</option>
</select>
</label>
<br/>
<label>
<small>Calculate per host totals at update</small>
<input id="perHostTotals" type="checkbox"/>
</label>
<!-- label>
<small>Show per host aggregates only</small>
<input id="showPerHostTotalsOnly" type="checkbox"/>
</label -->
</span>
</p>
<table>
Expand Down

0 comments on commit 9352095

Please sign in to comment.