네트워크 오류 드롭 이력 추가

This commit is contained in:
seo
2026-07-25 23:15:18 +09:00
parent e500eb2876
commit 7f9a5d1a81
5 changed files with 201 additions and 3 deletions
+51 -1
View File
@@ -1048,6 +1048,10 @@ function add_network_usage_log_for_interface(array $iface): void
$txBytes = isset($iface['tx_bytes']) ? (int)$iface['tx_bytes'] : -1;
$rxPackets = isset($iface['rx_packets']) ? (int)$iface['rx_packets'] : -1;
$txPackets = isset($iface['tx_packets']) ? (int)$iface['tx_packets'] : -1;
$rxErrors = isset($iface['rx_errors']) ? (int)$iface['rx_errors'] : 0;
$txErrors = isset($iface['tx_errors']) ? (int)$iface['tx_errors'] : 0;
$rxDropped = isset($iface['rx_dropped']) ? (int)$iface['rx_dropped'] : 0;
$txDropped = isset($iface['tx_dropped']) ? (int)$iface['tx_dropped'] : 0;
if ($name === '' || $rxBytes < 0 || $txBytes < 0 || $rxPackets < 0 || $txPackets < 0) {
return;
}
@@ -1060,6 +1064,10 @@ function add_network_usage_log_for_interface(array $iface): void
tx_bytes,
rx_packets,
tx_packets,
rx_errors,
tx_errors,
rx_dropped,
tx_dropped,
TIMESTAMPDIFF(MICROSECOND, recorded_at, NOW(3)) AS elapsed_us
FROM network_usage_logs
WHERE iface = :iface
@@ -1073,6 +1081,10 @@ function add_network_usage_log_for_interface(array $iface): void
$txMbps = null;
$rxPps = null;
$txPps = null;
$rxErrorsPerSec = null;
$txErrorsPerSec = null;
$rxDroppedPerSec = null;
$txDroppedPerSec = null;
if ($previous) {
$seconds = max(0.0, (float)($previous['elapsed_us'] ?? 0) / 1000000);
if ($seconds < 0.8) {
@@ -1083,12 +1095,22 @@ function add_network_usage_log_for_interface(array $iface): void
$txDelta = $txBytes - (int)$previous['tx_bytes'];
$rxPacketDelta = $rxPackets - (int)$previous['rx_packets'];
$txPacketDelta = $txPackets - (int)$previous['tx_packets'];
$rxErrorDelta = $rxErrors - (int)$previous['rx_errors'];
$txErrorDelta = $txErrors - (int)$previous['tx_errors'];
$rxDroppedDelta = $rxDropped - (int)$previous['rx_dropped'];
$txDroppedDelta = $txDropped - (int)$previous['tx_dropped'];
if ($seconds > 0 && $seconds <= 60 && $rxDelta >= 0 && $txDelta >= 0 && $rxPacketDelta >= 0 && $txPacketDelta >= 0) {
$rxMbps = round(($rxDelta * 8) / $seconds / 1000000, 4);
$txMbps = round(($txDelta * 8) / $seconds / 1000000, 4);
$rxPps = round($rxPacketDelta / $seconds, 2);
$txPps = round($txPacketDelta / $seconds, 2);
}
if ($seconds > 0 && $seconds <= 60 && $rxErrorDelta >= 0 && $txErrorDelta >= 0 && $rxDroppedDelta >= 0 && $txDroppedDelta >= 0) {
$rxErrorsPerSec = round($rxErrorDelta / $seconds, 2);
$txErrorsPerSec = round($txErrorDelta / $seconds, 2);
$rxDroppedPerSec = round($rxDroppedDelta / $seconds, 2);
$txDroppedPerSec = round($txDroppedDelta / $seconds, 2);
}
}
$stmt = $pdo->prepare("
@@ -1099,10 +1121,18 @@ function add_network_usage_log_for_interface(array $iface): void
tx_bytes,
rx_packets,
tx_packets,
rx_errors,
tx_errors,
rx_dropped,
tx_dropped,
rx_mbps,
tx_mbps,
rx_pps,
tx_pps,
rx_errors_per_sec,
tx_errors_per_sec,
rx_dropped_per_sec,
tx_dropped_per_sec,
create_ip
)
VALUES
@@ -1112,10 +1142,18 @@ function add_network_usage_log_for_interface(array $iface): void
:tx_bytes,
:rx_packets,
:tx_packets,
:rx_errors,
:tx_errors,
:rx_dropped,
:tx_dropped,
:rx_mbps,
:tx_mbps,
:rx_pps,
:tx_pps,
:rx_errors_per_sec,
:tx_errors_per_sec,
:rx_dropped_per_sec,
:tx_dropped_per_sec,
:create_ip
)
");
@@ -1125,10 +1163,18 @@ function add_network_usage_log_for_interface(array $iface): void
':tx_bytes' => $txBytes,
':rx_packets' => $rxPackets,
':tx_packets' => $txPackets,
':rx_errors' => $rxErrors,
':tx_errors' => $txErrors,
':rx_dropped' => $rxDropped,
':tx_dropped' => $txDropped,
':rx_mbps' => $rxMbps,
':tx_mbps' => $txMbps,
':rx_pps' => $rxPps,
':tx_pps' => $txPps,
':rx_errors_per_sec' => $rxErrorsPerSec,
':tx_errors_per_sec' => $txErrorsPerSec,
':rx_dropped_per_sec' => $rxDroppedPerSec,
':tx_dropped_per_sec' => $txDroppedPerSec,
':create_ip' => $_SERVER['REMOTE_ADDR'] ?? 'cli',
]);
}
@@ -1152,7 +1198,11 @@ function network_usage_history(int $limit = 240): array
ROUND(rx_mbps / 8, 4) AS rx_mbytes,
ROUND(tx_mbps / 8, 4) AS tx_mbytes,
rx_pps,
tx_pps
tx_pps,
rx_errors_per_sec,
tx_errors_per_sec,
rx_dropped_per_sec,
tx_dropped_per_sec
FROM network_usage_logs
WHERE rx_mbps IS NOT NULL
AND tx_mbps IS NOT NULL