fix(agent): read /proc/uptime on linux instead of sysinfo(2) (#2180)

gopsutil's host.Uptime() calls the sysinfo(2) syscall. Inside an LXC
container lxcfs virtualizes /proc/uptime but cannot intercept a
syscall, so every container reported the host's uptime.

Reads /proc/uptime on linux and falls back to host.Uptime() if the file
is missing or unparseable, so other platforms are unchanged.
This commit is contained in:
Alec Rubin
2026-08-18 15:18:33 -04:00
committed by GitHub
parent 0eb3426619
commit 68a3f8962a
4 changed files with 156 additions and 1 deletions

10
agent/uptime_stub.go Normal file
View File

@@ -0,0 +1,10 @@
//go:build !linux
package agent
import "github.com/shirou/gopsutil/v4/host"
// getUptime returns the system uptime in seconds.
func getUptime() (uint64, error) {
return host.Uptime()
}