mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-21 20:26:36 +00: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:
@@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
@@ -117,6 +118,11 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
|||||||
|
|
||||||
version := windows.RtlGetVersion()
|
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(
|
c.osInformation = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
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.`,
|
`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 "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return productName, strconv.FormatUint(revision, 10), nil
|
return strings.TrimSpace(productName), strconv.FormatUint(revision, 10), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user