doti3/bar/src/bandwidth.php

39 lines
779 B
PHP
Raw Normal View History

2021-03-03 21:31:06 +01:00
#!/usr/bin/env php
2017-06-19 16:36:59 +02:00
<?php
require __DIR__.'/base/block.php';
$iface = $argv[1] ?? 'eth0';
$inet = ($argv[2] ?? 'inet').' ';
2021-03-03 21:31:06 +01:00
$name = ($argv[3] ?? $iface);
2017-06-19 16:36:59 +02:00
$command = sprintf(
2020-01-14 11:35:27 +01:00
'ip address show %s | grep %s | awk \'{ print $2 }\' | cut -d/ -f1',
2017-06-19 16:36:59 +02:00
escapeshellarg($iface),
escapeshellarg($inet)
);
$ip = trim(shell_exec($command));
if (empty($ip)) {
die;
}
2019-01-28 11:13:11 +01:00
$bwidth = explode(' ', preg_replace('/ +/', ' ', trim(shell_exec('ifstat -i '.escapeshellcmd($iface).' 0.1 1 | tail -n 1'))));
2017-06-19 16:36:59 +02:00
if (empty($bwidth)) {
die;
}
2019-01-28 11:13:11 +01:00
$down = pemoji(0xf0ab).$bwidth[0].'Ko/s ';
2020-01-14 11:35:27 +01:00
$up = $bwidth[1].'Ko/s'.pemoji(0xf0aa);
2019-01-28 11:13:11 +01:00
2021-03-03 21:31:06 +01:00
$fullText = pspan($name, '#ccc', '#222').span($down.$up, '#ddd', '#000');
2017-06-19 16:36:59 +02:00
echo block(
'bandwidth_'.$iface,
[
'full_text' => $fullText,
]
);