Skip to content
Snippets Groups Projects
Commit 16f16439 authored by Tibo's avatar Tibo
Browse files

Show human readable traffic

parent 8276bf60
No related branches found
No related tags found
No related merge requests found
......@@ -100,4 +100,19 @@ class NetworkInterface {
public $address;
public $rx;
public $tx;
public function humanReadableSize($bytes, $decimals = 2) {
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
public function humanReadableRx() {
return $this->humanReadableSize($this->rx);
}
public function humanReadableTx() {
return $this->humanReadableSize($this->tx);
}
}
<table class="table table-striped table-sm">
<tr>
<th>Name</th>
<th>Address</th>
<th>RX</th>
<th>TX</th>
</tr>
@foreach ($interfaces as $interface)
<tr>
<td>{{ $interface->name }}</td>
<td>{{ $interface->address }}</td>
<td>{{ $interface->rx }}</td>
<td>{{ $interface->tx }}</td>
<td>{{ $interface->humanReadableRx() }}</td>
<td>{{ $interface->humanReadableTx() }}</td>
</tr>
@endforeach
</table>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment