1
0
mirror of https://github.com/prometheus-community/windows_exporter.git synced 2025-04-18 19:24:05 +03:00

fix: return Windows 11 as product name, if build number is >= 22000 (#1935)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke 2025-03-19 22:50:54 +01:00 committed by GitHub
parent 29307eb2b2
commit 041c2cd170
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ import (
"fmt"
"log/slog"
"strconv"
"strings"
"time"
"github.com/alecthomas/kingpin/v2"
@ -117,6 +118,11 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
version := windows.RtlGetVersion()
// Microsoft has decided to keep the major version as "10" for Windows 11, including the product name.
if version.BuildNumber >= 22000 {
productName = strings.Replace(productName, " 10 ", " 11 ", 1)
}
c.osInformation = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "info"),
`Contains full product name & version in labels. Note that the "major_version" for Windows 11 is \"10\"; a build number greater than 22000 represents Windows 11.`,
@ -371,5 +377,5 @@ func (c *Collector) getWindowsVersion() (string, string, error) {
return "", "", err
}
return productName, strconv.FormatUint(revision, 10), nil
return strings.TrimSpace(productName), strconv.FormatUint(revision, 10), nil
}