doti3/bar/src/bandwidth.php

38 lines
736 B
PHP
Executable File

#!/usr/bin/php7.1
<?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).' 0.1 1 | tail -n 1'))));
if (empty($bwidth)) {
die;
}
$up = $bwidth[1].'Ko/s'.pemoji(0xf0aa);
$down = pemoji(0xf0ab).$bwidth[0].'Ko/s ';
$fullText = pspan($iface, '#ccc', '#222').pspan($down.$up, '#ddd', '#000');
echo block(
'bandwidth_'.$iface,
[
'full_text' => $fullText,
]
);