Skip to content

Commit

Permalink
Merge pull request #211 from Fuxy22/master
Browse files Browse the repository at this point in the history
bandwidth use first interface not eth0
  • Loading branch information
tariqbuilds committed Jun 26, 2014
2 parents 303be91 + 7ba345f commit 1288597
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ <h3>
</div><!-- /widget-header -->
<div class="widget-content">
<div style="padding:10px;text-align:center;">
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>
<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>
</div>
</div><!-- /widget-content -->
</div><!-- /widget -->
Expand Down
5 changes: 3 additions & 2 deletions js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,9 @@ dashboard.getBandwidth = function () {
cache: false,
dataType: 'json',
success: function (data) {
$('#bw-tx').text(data.tx);
$('#bw-rx').text(data.rx);
$('#bw-int').text(data['0'].interface + ":");
$('#bw-tx').text(data['0'].tx);
$('#bw-rx').text(data['0'].rx);
},
complete: function() {
refreshIcon.removeClass('icon-spin');
Expand Down
36 changes: 26 additions & 10 deletions sh/bandwidth.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
<?php
$interface_path = 'ls /sys/class/net';

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

$tx_start = intval(shell_exec($tx_path));
$rx_start = intval(shell_exec($rx_path));
$results = array();

sleep(2);
sleep(5);

$tx_end = intval(shell_exec($tx_path));
$rx_end = intval(shell_exec($rx_path));
foreach ($interfaces as $interface) {

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

echo json_encode($result);
$tx_start = intval(shell_exec($tx_path));
$rx_start = intval(shell_exec($rx_path));

sleep(2);

$tx_end = intval(shell_exec($tx_path));
$rx_end = intval(shell_exec($rx_path));

$result['interface'] = $interface;
$result['tx'] = ($tx_end - $tx_start);
$result['rx'] = ($rx_end - $rx_start);

$results[] = $result;
}

echo json_encode($results);

0 comments on commit 1288597

Please sign in to comment.