diff --git a/internal/collector/os/os.go b/internal/collector/os/os.go index ac052326..549f518b 100644 --- a/internal/collector/os/os.go +++ b/internal/collector/os/os.go @@ -26,6 +26,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/types" @@ -48,7 +49,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 @@ -166,6 +169,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.", @@ -213,6 +222,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)) } @@ -275,6 +288,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 fcd2f3bc..5493ca7e 100644 --- a/tools/e2e-output.txt +++ b/tools/e2e-output.txt @@ -301,6 +301,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.