shirou / gopsutil

psutil for golang
Other
10.63k stars 1.59k forks source link

host.PlatformInformation() not precise on Ubuntu #1666

Open the-hotmann opened 5 months ago

the-hotmann commented 5 months ago

When I get run:

_, _, host_version, _ := host.PlatformInformation()
fmt.Println(host_version)

On debian I get 11.9 while cat /etc/*release* just shows:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Which means the tool is more precise than simple shell calls.

But on Ubuntu it gives me back 22.04 While cat /etc/*release* lets me exactly know that it is 22.04.4. I would like it to display the exact version - including the patch-version - on Ubuntu (22.04.4), not just the Major and Minir version.

I hope this is not too much to ask for :)

Thanks for this nice tool!

davidnewhall commented 4 months ago

The version likely comes from /etc/lsb-release, which doesn't contain the patch revision in a correct format for machines. Changing that output would also break any app that's looking for a specific version that suddenly includes a patch revision.

sni commented 4 months ago

same is true for windows build version. The information would be available from host.platformInformation() but that's not exported as public interface anywhere (anymore). v3 host.PlatformInformationWithContext() contained the build number. How can i access this information with v4?

shirou commented 3 months ago

Sorry for the late reply.

  1. Agree with @davidnewhall, retrieving the patch version of Ubuntu would significantly break compatibility, so I believe a major version upgrade is necessary.

  2. As you mentioned, in the v4 major version upgrade, PlatformVersion() was changed from the Windows build version (e.g., 10.0.22631.3447) to something like 23H2. However, you can still obtain the build version using KernelVersion(). See #1629.