Merge pull request #17 from JohnsonRan/kernel-version

feat: add kernel version reporting for all platforms
This commit is contained in:
Akizon
2025-08-02 23:42:30 +08:00
committed by GitHub
5 changed files with 58 additions and 0 deletions

View File

@@ -19,3 +19,14 @@ func OSName() string {
name := strings.TrimSpace(string(output)) name := strings.TrimSpace(string(output))
return name return name
} }
// KernelVersion returns the kernel version on Darwin (macOS)
func KernelVersion() string {
cmd := exec.Command("uname", "-r")
output, err := cmd.Output()
if err != nil {
return "Unknown"
}
return strings.TrimSpace(string(output))
}

View File

@@ -19,3 +19,14 @@ func OSName() string {
name := strings.TrimSpace(string(output)) name := strings.TrimSpace(string(output))
return name return name
} }
// KernelVersion returns the kernel version on FreeBSD
func KernelVersion() string {
cmd := exec.Command("uname", "-r")
output, err := cmd.Output()
if err != nil {
return "Unknown"
}
return strings.TrimSpace(string(output))
}

View File

@@ -156,3 +156,13 @@ func detectProxmoxVE() string {
return "Proxmox VE" return "Proxmox VE"
} }
// KernelVersion returns the kernel version on Linux systems
func KernelVersion() string {
out, err := exec.Command("uname", "-r").Output()
if err != nil {
return "Unknown"
}
return strings.TrimSpace(string(out))
}

View File

@@ -48,3 +48,27 @@ func OSName() string {
return productName return productName
} }
// KernelVersion returns the kernel version on Windows systems (build number)
func KernelVersion() string {
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
return "Unknown"
}
defer key.Close()
// Get current build number
buildNumber, _, err := key.GetStringValue("CurrentBuild")
if err != nil {
return "Unknown"
}
// Get UBR (Update Build Revision) if available
ubr, _, err := key.GetIntegerValue("UBR")
if err != nil {
// UBR not available, just return build number
return buildNumber
}
return buildNumber + "." + strconv.FormatUint(ubr, 10)
}

View File

@@ -35,6 +35,7 @@ func uploadBasicInfo() error {
cpu := monitoring.Cpu() cpu := monitoring.Cpu()
osname := monitoring.OSName() osname := monitoring.OSName()
kernelVersion := monitoring.KernelVersion()
ipv4, ipv6, _ := monitoring.GetIPAddress() ipv4, ipv6, _ := monitoring.GetIPAddress()
data := map[string]interface{}{ data := map[string]interface{}{
@@ -42,6 +43,7 @@ func uploadBasicInfo() error {
"cpu_cores": cpu.CPUCores, "cpu_cores": cpu.CPUCores,
"arch": cpu.CPUArchitecture, "arch": cpu.CPUArchitecture,
"os": osname, "os": osname,
"kernel_version": kernelVersion,
"ipv4": ipv4, "ipv4": ipv4,
"ipv6": ipv6, "ipv6": ipv6,
"mem_total": monitoring.Ram().Total, "mem_total": monitoring.Ram().Total,