네트워크 사용량 이력 차트 추가
This commit is contained in:
+23
-1
@@ -947,6 +947,11 @@ function os_info(): array
|
||||
function network_info(): array
|
||||
{
|
||||
$rows = [];
|
||||
$defaultInterface = '';
|
||||
$route = trim((string)sh(['/usr/sbin/ip', 'route', 'show', 'default'], false, 3)['out']);
|
||||
if (preg_match('/\bdev\s+([^\s]+)/', $route, $matches)) {
|
||||
$defaultInterface = (string)$matches[1];
|
||||
}
|
||||
|
||||
foreach (glob('/sys/class/net/*') ?: [] as $dir) {
|
||||
$name = basename($dir);
|
||||
@@ -957,22 +962,38 @@ function network_info(): array
|
||||
|
||||
$rx = (int)first_readable([$dir . '/statistics/rx_bytes']);
|
||||
$tx = (int)first_readable([$dir . '/statistics/tx_bytes']);
|
||||
$rxPackets = (int)first_readable([$dir . '/statistics/rx_packets']);
|
||||
$txPackets = (int)first_readable([$dir . '/statistics/tx_packets']);
|
||||
$rxErrors = (int)first_readable([$dir . '/statistics/rx_errors']);
|
||||
$txErrors = (int)first_readable([$dir . '/statistics/tx_errors']);
|
||||
$rxDropped = (int)first_readable([$dir . '/statistics/rx_dropped']);
|
||||
$txDropped = (int)first_readable([$dir . '/statistics/tx_dropped']);
|
||||
|
||||
$rows[] = [
|
||||
'name' => $name,
|
||||
'default' => $name === $defaultInterface,
|
||||
'state' => first_readable([$dir . '/operstate']) ?: 'unknown',
|
||||
'carrier' => first_readable([$dir . '/carrier']) === '1' ? 'up' : 'down',
|
||||
'mac' => first_readable([$dir . '/address']) ?: 'N/A',
|
||||
'mtu' => first_readable([$dir . '/mtu']) ?: 'N/A',
|
||||
'rx_bytes' => $rx,
|
||||
'tx_bytes' => $tx,
|
||||
'rx_packets' => $rxPackets,
|
||||
'tx_packets' => $txPackets,
|
||||
'rx_errors' => $rxErrors,
|
||||
'tx_errors' => $txErrors,
|
||||
'rx_dropped' => $rxDropped,
|
||||
'tx_dropped' => $txDropped,
|
||||
'rx_human' => bytes_human($rx),
|
||||
'tx_human' => bytes_human($tx),
|
||||
'ipv4' => trim(sh(['/usr/sbin/ip', '-4', '-o', 'addr', 'show', 'dev', $name], false, 3)['out']) ?: 'N/A',
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
return [
|
||||
'default_interface' => $defaultInterface,
|
||||
'interfaces' => $rows,
|
||||
];
|
||||
}
|
||||
|
||||
function latest_sensor(): array
|
||||
@@ -4381,6 +4402,7 @@ function collect_snapshot(bool $applyFan = true): array
|
||||
'battery' => $battery,
|
||||
|
||||
'wifi' => wifi_data(),
|
||||
'network' => network_info(),
|
||||
'history' => $history,
|
||||
'processes' => $processes,
|
||||
'custom_services' => custom_systemd_services(),
|
||||
|
||||
Reference in New Issue
Block a user