36 lines
677 B
PHP
Executable file
36 lines
677 B
PHP
Executable file
#!/usr/bin/php
|
|
<?php
|
|
|
|
require __DIR__.'/base/block.php';
|
|
|
|
$iface = $argv[1] ?? 'eth0';
|
|
$inet = ($argv[2] ?? 'inet').' ';
|
|
|
|
$command = sprintf(
|
|
'ip address show %s | grep %s | awk \'{ print $2 }\'',
|
|
escapeshellarg($iface),
|
|
escapeshellarg($inet)
|
|
);
|
|
|
|
$ip = trim(shell_exec($command));
|
|
|
|
if (empty($ip)) {
|
|
die;
|
|
}
|
|
|
|
$bwidth = explode(' ', preg_replace('/ +/', ' ', trim(shell_exec('ifstat -i '.escapeshellcmd($iface).' 1 1 | tail -n 1'))));
|
|
|
|
if (empty($bwidth)) {
|
|
die;
|
|
}
|
|
|
|
$fullText = '['.$iface.'] '.$bwidth[0].'Ko/s↓ '.$bwidth[1].'Ko/s↑';
|
|
|
|
echo block(
|
|
'bandwidth_'.$iface,
|
|
[
|
|
'full_text' => $fullText,
|
|
'color' => color('info'),
|
|
]
|
|
);
|