[0.30] os: missing deprecated metric windows_os_processes (#2104) (#2144)

This commit is contained in:
Jan-Otto Kröpke
2025-07-20 08:15:58 +02:00
committed by GitHub
parent 0f7f8f2583
commit 1f0880b998
2 changed files with 30 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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.