Refactor memory handling in Mihomo to use KiB
- Updated memory variable names and comments to reflect usage in KiB instead of KB for clarity. - Introduced a function to convert memory values from bytes to KiB, ensuring consistent data representation across components. - Adjusted chart data to display memory in KiB, enhancing accuracy in visualizations.
This commit is contained in:
@@ -83,7 +83,7 @@
|
|||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: histMem.map((_, i) => String(i)),
|
labels: histMem.map((_, i) => String(i)),
|
||||||
datasets: [{ label: 'KB', data: [...histMem], borderColor: '#a78bfa', tension: 0.2, fill: true }]
|
datasets: [{ label: 'KiB', data: [...histMem], borderColor: '#a78bfa', tension: 0.2, fill: true }]
|
||||||
},
|
},
|
||||||
options: lineOpts()
|
options: lineOpts()
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,8 @@
|
|||||||
let downBps = $state(0);
|
let downBps = $state(0);
|
||||||
let totalUp = $state(0);
|
let totalUp = $state(0);
|
||||||
let totalDown = $state(0);
|
let totalDown = $state(0);
|
||||||
let memKB = $state(0);
|
/** Память в KiB (кибибайты): из WS Mihomo приходит в байтах — нормализуем в одном месте. */
|
||||||
|
let memKiB = $state(0);
|
||||||
let connTotal = $state(0);
|
let connTotal = $state(0);
|
||||||
let tcpN = $state(0);
|
let tcpN = $state(0);
|
||||||
let udpN = $state(0);
|
let udpN = $state(0);
|
||||||
@@ -48,6 +49,12 @@
|
|||||||
let topList = $state<{ name: string; n: number }[]>([]);
|
let topList = $state<{ name: string; n: number }[]>([]);
|
||||||
|
|
||||||
const MAX_POINTS = 72;
|
const MAX_POINTS = 72;
|
||||||
|
|
||||||
|
/** Mihomo WS: `inuse` (/memory) и `memory` (/connections) — в байтах → KiB для карточки и графика. */
|
||||||
|
function mihomoWsMemoryToKiB(bytes: number): number {
|
||||||
|
if (!Number.isFinite(bytes) || bytes <= 0) return 0;
|
||||||
|
return bytes / 1024;
|
||||||
|
}
|
||||||
/** Mihomo hub/route/proxies.go: без query `url` URLTest часто даёт delay=0 → HTTP 503. */
|
/** Mihomo hub/route/proxies.go: без query `url` URLTest часто даёт delay=0 → HTTP 503. */
|
||||||
const MIHOMO_DELAY_DEFAULT_URL = 'https://www.gstatic.com/generate_204';
|
const MIHOMO_DELAY_DEFAULT_URL = 'https://www.gstatic.com/generate_204';
|
||||||
|
|
||||||
@@ -203,8 +210,8 @@
|
|||||||
if (line) {
|
if (line) {
|
||||||
try {
|
try {
|
||||||
const o = JSON.parse(line) as { inuse?: number };
|
const o = JSON.parse(line) as { inuse?: number };
|
||||||
memKB = Number(o.inuse) || 0;
|
memKiB = mihomoWsMemoryToKiB(Number(o.inuse) || 0);
|
||||||
histMem = [...histMem, memKB];
|
histMem = [...histMem, memKiB];
|
||||||
while (histMem.length > MAX_POINTS) histMem.shift();
|
while (histMem.length > MAX_POINTS) histMem.shift();
|
||||||
seen++;
|
seen++;
|
||||||
} catch {
|
} catch {
|
||||||
@@ -343,8 +350,8 @@
|
|||||||
ws.onmessage = (ev) => {
|
ws.onmessage = (ev) => {
|
||||||
try {
|
try {
|
||||||
const o = JSON.parse(String(ev.data)) as { inuse?: number };
|
const o = JSON.parse(String(ev.data)) as { inuse?: number };
|
||||||
memKB = Number(o.inuse) || 0;
|
memKiB = mihomoWsMemoryToKiB(Number(o.inuse) || 0);
|
||||||
histMem = [...histMem, memKB];
|
histMem = [...histMem, memKiB];
|
||||||
while (histMem.length > MAX_POINTS) histMem.shift();
|
while (histMem.length > MAX_POINTS) histMem.shift();
|
||||||
} catch {
|
} catch {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
@@ -397,8 +404,8 @@
|
|||||||
totalDown = j.downloadTotal;
|
totalDown = j.downloadTotal;
|
||||||
}
|
}
|
||||||
if (typeof j.memory === 'number') {
|
if (typeof j.memory === 'number') {
|
||||||
memKB = j.memory;
|
memKiB = mihomoWsMemoryToKiB(j.memory);
|
||||||
histMem = [...histMem, memKB];
|
histMem = [...histMem, memKiB];
|
||||||
while (histMem.length > MAX_POINTS) histMem.shift();
|
while (histMem.length > MAX_POINTS) histMem.shift();
|
||||||
}
|
}
|
||||||
let t = 0,
|
let t = 0,
|
||||||
@@ -486,7 +493,7 @@
|
|||||||
totalDown = 0;
|
totalDown = 0;
|
||||||
upBps = 0;
|
upBps = 0;
|
||||||
downBps = 0;
|
downBps = 0;
|
||||||
memKB = 0;
|
memKiB = 0;
|
||||||
histUp = [];
|
histUp = [];
|
||||||
histDown = [];
|
histDown = [];
|
||||||
histMem = [];
|
histMem = [];
|
||||||
@@ -676,7 +683,7 @@
|
|||||||
<Card.Description>Память</Card.Description>
|
<Card.Description>Память</Card.Description>
|
||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Content class="text-lg font-semibold">
|
<Card.Content class="text-lg font-semibold">
|
||||||
{memKB > 0 ? `${(memKB / 1024).toFixed(1)} MiB` : '—'}
|
{memKiB > 0 ? `${(memKiB / 1024).toFixed(1)} MiB` : '—'}
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card.Root>
|
</Card.Root>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user