3x-ui/util/sys
MHSanaei fa3c7a7a0e
fix(sys): correct CPU/connection accounting on linux + darwin
util/sys/sys_linux.go:
- GetTCPCount/GetUDPCount were counting the column header row in
  /proc/net/{tcp,udp}[6] as a connection, inflating the reported total
  by 1 per non-empty file (so the panel status line always showed 2
  more connections than actually existed). Replace getLinesNum +
  safeGetLinesNum with a single bufio.Scanner-based countConnections
  that skips the header.
- CPUPercentRaw now opens HostProc("stat") instead of a hardcoded
  /proc/stat so HOST_PROC overrides apply, matching the connection
  counters in the same file.
- Simplify CPU field unpacking: pad nums to 8 once instead of guarding
  every assignment with a len check.

util/sys/sys_darwin.go:
- Fix swapped idle/intr indices on kern.cp_time. BSD CPUSTATES order
  is user, nice, sys, intr, idle (CP_INTR=3, CP_IDLE=4) — gopsutil's
  cpu_darwin_nocgo.go reads the same layout. The previous code used
  out[3] as idle and out[4] as intr, so busy = total - dIdle was
  actually subtracting interrupt time, making the panel report CPU
  usage close to 100% on macOS regardless of actual load.
- Collapse the per-field delta math into a single loop.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 23:07:20 +02:00
..
psutil.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
sys_darwin.go fix(sys): correct CPU/connection accounting on linux + darwin 2026-05-18 23:07:20 +02:00
sys_linux.go fix(sys): correct CPU/connection accounting on linux + darwin 2026-05-18 23:07:20 +02:00
sys_windows.go fix(windows): clean shutdown, working panel restart, harden kernel32 load 2026-05-18 22:57:36 +02:00