#!/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 }\' | cut -d/ -f1',
    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;
}

$down = pemoji(0xf0ab).$bwidth[0].'Ko/s ';
$up = $bwidth[1].'Ko/s'.pemoji(0xf0aa);

$fullText = pspan($iface, '#ccc', '#222').span($down.$up, '#ddd', '#000');

echo block(
    'bandwidth_'.$iface,
    [
        'full_text' => $fullText,
    ]
);
Insérer
<div%key%id="gist-5c87a0d648b5c-bba2ecb6f677a0877c8ee48b676b12555b0f8603" class="gist-container"></div>
<script src="https://gist.deblan.org/fr/embedjs/5c87a0d648b5c" async></script>