네트워크 오류 드롭 누적 표시 정리

This commit is contained in:
seo
2026-07-26 00:06:54 +09:00
parent 7f9a5d1a81
commit f2b34ebc7a
5 changed files with 206 additions and 126 deletions
+143
View File
@@ -1057,6 +1057,8 @@ function add_network_usage_log_for_interface(array $iface): void
}
$pdo = db();
update_network_quality_totals($name, $rxErrors, $txErrors, $rxDropped, $txDropped);
$stmt = $pdo->prepare("
SELECT
recorded_at,
@@ -1179,6 +1181,103 @@ function add_network_usage_log_for_interface(array $iface): void
]);
}
function update_network_quality_totals(string $iface, int $rxErrors, int $txErrors, int $rxDropped, int $txDropped): void
{
$pdo = db();
$stmt = $pdo->prepare("
SELECT
last_rx_errors,
last_tx_errors,
last_rx_dropped,
last_tx_dropped
FROM network_quality_totals
WHERE iface = :iface
LIMIT 1
");
$stmt->execute([':iface' => $iface]);
$previous = $stmt->fetch() ?: null;
if (!$previous) {
$stmt = $pdo->prepare("
INSERT INTO network_quality_totals
(
iface,
rx_errors_total,
tx_errors_total,
rx_dropped_total,
tx_dropped_total,
last_rx_errors,
last_tx_errors,
last_rx_dropped,
last_tx_dropped
)
VALUES
(
:iface,
:rx_errors_total,
:tx_errors_total,
:rx_dropped_total,
:tx_dropped_total,
:last_rx_errors,
:last_tx_errors,
:last_rx_dropped,
:last_tx_dropped
)
");
$stmt->execute([
':iface' => $iface,
':rx_errors_total' => $rxErrors,
':tx_errors_total' => $txErrors,
':rx_dropped_total' => $rxDropped,
':tx_dropped_total' => $txDropped,
':last_rx_errors' => $rxErrors,
':last_tx_errors' => $txErrors,
':last_rx_dropped' => $rxDropped,
':last_tx_dropped' => $txDropped,
]);
return;
}
$rxErrorDelta = $rxErrors >= (int)$previous['last_rx_errors']
? $rxErrors - (int)$previous['last_rx_errors']
: $rxErrors;
$txErrorDelta = $txErrors >= (int)$previous['last_tx_errors']
? $txErrors - (int)$previous['last_tx_errors']
: $txErrors;
$rxDroppedDelta = $rxDropped >= (int)$previous['last_rx_dropped']
? $rxDropped - (int)$previous['last_rx_dropped']
: $rxDropped;
$txDroppedDelta = $txDropped >= (int)$previous['last_tx_dropped']
? $txDropped - (int)$previous['last_tx_dropped']
: $txDropped;
$stmt = $pdo->prepare("
UPDATE network_quality_totals
SET
rx_errors_total = rx_errors_total + :rx_error_delta,
tx_errors_total = tx_errors_total + :tx_error_delta,
rx_dropped_total = rx_dropped_total + :rx_dropped_delta,
tx_dropped_total = tx_dropped_total + :tx_dropped_delta,
last_rx_errors = :last_rx_errors,
last_tx_errors = :last_tx_errors,
last_rx_dropped = :last_rx_dropped,
last_tx_dropped = :last_tx_dropped,
updated_at = NOW(3)
WHERE iface = :iface
");
$stmt->execute([
':rx_error_delta' => $rxErrorDelta,
':tx_error_delta' => $txErrorDelta,
':rx_dropped_delta' => $rxDroppedDelta,
':tx_dropped_delta' => $txDroppedDelta,
':last_rx_errors' => $rxErrors,
':last_tx_errors' => $txErrors,
':last_rx_dropped' => $rxDropped,
':last_tx_dropped' => $txDropped,
':iface' => $iface,
]);
}
function add_network_usage_log(array $network): void
{
foreach (network_log_interfaces($network) as $iface) {
@@ -1186,6 +1285,48 @@ function add_network_usage_log(array $network): void
}
}
function network_quality_totals(): array
{
$stmt = db()->query("
SELECT
iface,
rx_errors_total,
tx_errors_total,
rx_dropped_total,
tx_dropped_total,
last_rx_errors,
last_tx_errors,
last_rx_dropped,
last_tx_dropped,
updated_at
FROM network_quality_totals
ORDER BY iface
");
$totals = [];
foreach ($stmt->fetchAll() as $row) {
$iface = (string)($row['iface'] ?? '');
if ($iface === '') {
continue;
}
$totals[$iface] = [
'iface' => $iface,
'rx_errors_total' => (int)$row['rx_errors_total'],
'tx_errors_total' => (int)$row['tx_errors_total'],
'rx_dropped_total' => (int)$row['rx_dropped_total'],
'tx_dropped_total' => (int)$row['tx_dropped_total'],
'last_rx_errors' => (int)$row['last_rx_errors'],
'last_tx_errors' => (int)$row['last_tx_errors'],
'last_rx_dropped' => (int)$row['last_rx_dropped'],
'last_tx_dropped' => (int)$row['last_tx_dropped'],
'updated_at' => $row['updated_at'],
];
}
return $totals;
}
function network_usage_history(int $limit = 240): array
{
$limit = max(1, min(1500, $limit));
@@ -4604,6 +4745,7 @@ function collect_snapshot(bool $applyFan = true): array
$network = network_info();
add_network_usage_log($network);
$networkHistory = network_usage_history(1000);
$networkQualityTotals = network_quality_totals();
$shouldLogNotice = !empty($fanSpike['alert_started'])
|| (!empty($fanSpike['active']) && (bool)setting_value('notice.log_during_alert'));
@@ -4626,6 +4768,7 @@ function collect_snapshot(bool $applyFan = true): array
'wifi' => wifi_data(),
'network' => $network,
'network_history' => $networkHistory,
'network_quality_totals' => $networkQualityTotals,
'history' => $history,
'processes' => $processes,
'custom_services' => custom_systemd_services(),