doti3/bar/src/bandwidth.php
2019-01-21 16:20:04 +01:00

39 lines
815 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 = span(' '.$iface.' ', '#ccc', '#222').span(' '.$bwidth[0].'Ko/s↓ '.$bwidth[1].'Ko/s↑', '#ddd', '#000').' ';
echo block(
'bandwidth_'.$iface,
[
'full_text' => $fullText,
'color' => '#ffffff',
'urgent' => 1,
'separator' => false,
'separator_block_width' => 0,
]
);