네트워크 이력 DB 저장 전환

This commit is contained in:
seo
2026-07-25 22:28:58 +09:00
parent bc89dcf9c0
commit 30c0cb4663
4 changed files with 187 additions and 74 deletions
+10 -73
View File
@@ -105,8 +105,6 @@
settingsOpen: false,
settingsDirty: false,
customServiceScrollHoldUntil: 0,
networkLast: null,
networkHistory: [],
};
const storageKeys = {
@@ -1835,74 +1833,6 @@
}
}
function primaryNetworkInterface(network) {
const rows = Array.isArray(network?.interfaces) ? network.interfaces : [];
const preferred = String(network?.default_interface || 'eth0');
return rows.find(row => row.name === preferred)
|| rows.find(row => row.name === 'eth0')
|| rows.find(row => row.carrier === 'up' && row.name !== 'br0')
|| rows[0]
|| null;
}
function networkCounter(row, key) {
const value = Number(row?.[key]);
return Number.isFinite(value) && value >= 0 ? value : null;
}
function pushNetworkSample(data) {
const iface = primaryNetworkInterface(data.network);
if (!iface) return;
const nowMs = Number(data.time_ms || Date.now());
const sample = {
iface: String(iface.name || ''),
time_ms: nowMs,
rx_bytes: networkCounter(iface, 'rx_bytes'),
tx_bytes: networkCounter(iface, 'tx_bytes'),
rx_packets: networkCounter(iface, 'rx_packets'),
tx_packets: networkCounter(iface, 'tx_packets'),
};
if (!sample.iface || sample.rx_bytes === null || sample.tx_bytes === null || sample.rx_packets === null || sample.tx_packets === null) {
return;
}
const previous = state.networkLast;
state.networkLast = sample;
if (!previous || previous.iface !== sample.iface || sample.time_ms <= previous.time_ms) {
return;
}
const seconds = (sample.time_ms - previous.time_ms) / 1000;
if (seconds <= 0 || seconds > 30) {
return;
}
const delta = key => sample[key] - previous[key];
const rxBytes = delta('rx_bytes');
const txBytes = delta('tx_bytes');
const rxPackets = delta('rx_packets');
const txPackets = delta('tx_packets');
if (rxBytes < 0 || txBytes < 0 || rxPackets < 0 || txPackets < 0) {
return;
}
state.networkHistory.push({
time: String(data.generated_at || '').replace('T', ' ') || new Date(sample.time_ms).toISOString().slice(0, 19).replace('T', ' '),
rx_mbps: (rxBytes * 8) / seconds / 1000000,
tx_mbps: (txBytes * 8) / seconds / 1000000,
rx_pps: rxPackets / seconds,
tx_pps: txPackets / seconds,
});
if (state.networkHistory.length > 180) {
state.networkHistory.splice(0, state.networkHistory.length - 180);
}
}
function renderSystemStatus(data) {
const system = data.system || {};
const disk = system.disk || {};
@@ -2379,6 +2309,13 @@
return xTickMarkers.get(index) || '';
};
const xTickCallback = (_value, index) => isXGridTick(index) ? xTickLabel(index) : '';
const yTickCallback = value => {
const numeric = Number(value);
const display = Number.isFinite(numeric)
? numeric.toLocaleString(undefined, { maximumFractionDigits: 2 })
: String(value);
return suffix ? `${display}${suffix}` : display;
};
const xGridColor = context => {
const index = Number(context.index ?? context.tick?.value ?? -1);
return isXGridTick(index) ? 'rgba(203,213,225,.18)' : 'rgba(203,213,225,0)';
@@ -2481,7 +2418,7 @@
y: {
min: 0,
...scaleOptions,
ticks: { color: '#8d98aa', maxTicksLimit: 4 },
ticks: { color: '#8d98aa', maxTicksLimit: 4, callback: yTickCallback },
grid: { color: 'rgba(255,255,255,.045)', drawTicks: false },
border: { display: false },
},
@@ -2496,6 +2433,7 @@
c.data.datasets = datasets;
c.options.scales.x.ticks.callback = xTickCallback;
c.options.scales.x.grid.color = xGridColor;
c.options.scales.y.ticks.callback = yTickCallback;
c.options.scales.y.min = scaleOptions.min ?? 0;
c.options.scales.y.max = scaleOptions.max;
c.update('none');
@@ -2557,7 +2495,7 @@
chart('batteryVoltageChart', 'BATTERYV', rows, 'battery_voltage', '#14b8a6', 'V', dynamicScale(rows, 'battery_voltage', { minSpan: 0.2, padding: 0.06 }));
}
const networkRows = state.networkHistory.slice(-180);
const networkRows = (data.network_history || []).slice(-180);
chart('netRxChart', 'NETRX', networkRows, 'rx_mbps', '#0ea5e9', ' Mbit/s', dynamicScale(networkRows, 'rx_mbps', { minSpan: 1, padding: 0.3 }));
chart('netTxChart', 'NETTX', networkRows, 'tx_mbps', '#22c55e', ' Mbit/s', dynamicScale(networkRows, 'tx_mbps', { minSpan: 1, padding: 0.3 }));
chart('netRxPacketsChart', 'NETRXPKT', networkRows, 'rx_pps', '#f97316', ' pps', dynamicScale(networkRows, 'rx_pps', { minSpan: 10, padding: 5 }));
@@ -2582,7 +2520,6 @@
renderSettings(data.settings);
}
}
pushNetworkSample(data);
renderTop(data);
renderSystemStatus(data);
renderWifi(data);