Skip to content

Commit 1288597

Browse files
committed
Merge pull request tariqbuilds#211 from Fuxy22/master
bandwidth use first interface not eth0
2 parents 303be91 + 7ba345f commit 1288597

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ <h3>
328328
</div><!-- /widget-header -->
329329
<div class="widget-content">
330330
<div style="padding:10px;text-align:center;">
331-
RX: <span class="lead odometer" style="margin-top:11px;" id="bw-rx">0</span>&nbsp;&nbsp;|&nbsp;&nbsp; TX: <span class="lead odometer" style="margin-top:11px;" id="bw-tx"></span>
331+
<i style="color:#19bc9c; font:20px/2em 'Open Sans',sans-serif;" class="icon-#" id="bw-int">eth0:</i>&nbsp; RX: <span class="lead odometer" style="margin-top:11px;" id="bw-rx">0</span>&nbsp;&nbsp;|&nbsp;&nbsp; TX: <span class="lead odometer" style="margin-top:11px;" id="bw-tx"></span>
332332
</div>
333333
</div><!-- /widget-content -->
334334
</div><!-- /widget -->

js/dashboard.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,9 @@ dashboard.getBandwidth = function () {
483483
cache: false,
484484
dataType: 'json',
485485
success: function (data) {
486-
$('#bw-tx').text(data.tx);
487-
$('#bw-rx').text(data.rx);
486+
$('#bw-int').text(data['0'].interface + ":");
487+
$('#bw-tx').text(data['0'].tx);
488+
$('#bw-rx').text(data['0'].rx);
488489
},
489490
complete: function() {
490491
refreshIcon.removeClass('icon-spin');

sh/bandwidth.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
<?php
2+
$interface_path = 'ls /sys/class/net';
23

3-
$tx_path = 'cat /sys/class/net/eth0/statistics/tx_bytes';
4-
$rx_path = 'cat /sys/class/net/eth0/statistics/rx_bytes';
4+
$interfaces = explode("\n", shell_exec($interface_path));
5+
array_pop($interfaces);
6+
$key = array_search("lo", $interfaces);
7+
unset($interfaces[$key]);
58

6-
$tx_start = intval(shell_exec($tx_path));
7-
$rx_start = intval(shell_exec($rx_path));
9+
$results = array();
810

9-
sleep(2);
11+
sleep(5);
1012

11-
$tx_end = intval(shell_exec($tx_path));
12-
$rx_end = intval(shell_exec($rx_path));
13+
foreach ($interfaces as $interface) {
1314

14-
$result['tx'] = ($tx_end - $tx_start);
15-
$result['rx'] = ($rx_end - $rx_start);
15+
$tx_path = "cat /sys/class/net/{$interface}/statistics/tx_bytes";
16+
$rx_path = "cat /sys/class/net/{$interface}/statistics/rx_bytes";
1617

17-
echo json_encode($result);
18+
$tx_start = intval(shell_exec($tx_path));
19+
$rx_start = intval(shell_exec($rx_path));
20+
21+
sleep(2);
22+
23+
$tx_end = intval(shell_exec($tx_path));
24+
$rx_end = intval(shell_exec($rx_path));
25+
26+
$result['interface'] = $interface;
27+
$result['tx'] = ($tx_end - $tx_start);
28+
$result['rx'] = ($rx_end - $rx_start);
29+
30+
$results[] = $result;
31+
}
32+
33+
echo json_encode($results);

0 commit comments

Comments
 (0)