From d64f1316cae65beda6cb68b9094ab462422a0517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Wed, 2 Jul 2025 00:50:03 +0200 Subject: [PATCH] os: missing deprecated metric windows_os_processes (#2104) --- internal/collector/os/os.go | 29 ++++++++++++++++++++++++++++- tools/e2e-output.txt | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/internal/collector/os/os.go b/internal/collector/os/os.go index bf02442e..276f49bc 100644 --- a/internal/collector/os/os.go +++ b/internal/collector/os/os.go @@ -28,6 +28,7 @@ import ( "github.com/alecthomas/kingpin/v2" "github.com/prometheus-community/windows_exporter/internal/headers/kernel32" "github.com/prometheus-community/windows_exporter/internal/headers/netapi32" + "github.com/prometheus-community/windows_exporter/internal/headers/psapi" "github.com/prometheus-community/windows_exporter/internal/headers/sysinfoapi" "github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/osversion" @@ -51,7 +52,9 @@ type Collector struct { hostname *prometheus.Desc osInformation *prometheus.Desc - // users + // Deprecated: Use windows_system_processes instead. + processes *prometheus.Desc + // Deprecated: Use windows_system_process_limit instead. processesLimit *prometheus.Desc @@ -169,6 +172,12 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { nil, ) + c.processes = prometheus.NewDesc( + prometheus.BuildFQName(types.Namespace, Name, "processes"), + "Deprecated: Use `windows_system_processes` instead.", + nil, + nil, + ) c.processesLimit = prometheus.NewDesc( prometheus.BuildFQName(types.Namespace, Name, "processes_limit"), "Deprecated: Use `windows_system_process_limit` instead.", @@ -216,6 +225,10 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { c.collect(ch) + if err := c.collectProcessCount(ch); err != nil { + errs = append(errs, fmt.Errorf("failed to collect process count metrics: %w", err)) + } + if err := c.collectHostname(ch); err != nil { errs = append(errs, fmt.Errorf("failed to collect hostname metrics: %w", err)) } @@ -278,6 +291,20 @@ func (c *Collector) collectHostname(ch chan<- prometheus.Metric) error { return nil } +func (c *Collector) collectProcessCount(ch chan<- prometheus.Metric) error { + gpi, err := psapi.GetPerformanceInfo() + if err != nil { + return err + } + + ch <- prometheus.MustNewConstMetric(c.processes, + prometheus.GaugeValue, + float64(gpi.ProcessCount), + ) + + return nil +} + func (c *Collector) collectTime(ch chan<- prometheus.Metric) error { timeZoneInfo, err := kernel32.GetDynamicTimeZoneInformation() if err != nil { diff --git a/tools/e2e-output.txt b/tools/e2e-output.txt index 8582c870..0c28795a 100644 --- a/tools/e2e-output.txt +++ b/tools/e2e-output.txt @@ -303,6 +303,8 @@ windows_exporter_collector_timeout{collector="udp"} 0 # TYPE windows_os_physical_memory_free_bytes gauge # HELP windows_os_process_memory_limit_bytes Deprecated: Use `windows_memory_process_memory_limit_bytes` instead. # TYPE windows_os_process_memory_limit_bytes gauge +# HELP windows_os_processes Deprecated: Use `windows_system_processes` instead. +# TYPE windows_os_processes gauge # HELP windows_os_processes_limit Deprecated: Use `windows_system_process_limit` instead. # TYPE windows_os_processes_limit gauge # HELP windows_os_time Deprecated: Use windows_time_current_timestamp_seconds instead.