os: missing deprecated metric windows_os_processes (#2104)

This commit is contained in:
Jan-Otto Kröpke
2025-07-02 00:50:03 +02:00
committed by GitHub
parent 492f3af317
commit d64f1316ca
2 changed files with 30 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ import (
"github.com/alecthomas/kingpin/v2" "github.com/alecthomas/kingpin/v2"
"github.com/prometheus-community/windows_exporter/internal/headers/kernel32" "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/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/headers/sysinfoapi"
"github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/mi"
"github.com/prometheus-community/windows_exporter/internal/osversion" "github.com/prometheus-community/windows_exporter/internal/osversion"
@@ -51,7 +52,9 @@ type Collector struct {
hostname *prometheus.Desc hostname *prometheus.Desc
osInformation *prometheus.Desc osInformation *prometheus.Desc
// users // Deprecated: Use windows_system_processes instead.
processes *prometheus.Desc
// Deprecated: Use windows_system_process_limit instead. // Deprecated: Use windows_system_process_limit instead.
processesLimit *prometheus.Desc processesLimit *prometheus.Desc
@@ -169,6 +172,12 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
nil, nil,
) )
c.processes = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "processes"),
"Deprecated: Use `windows_system_processes` instead.",
nil,
nil,
)
c.processesLimit = prometheus.NewDesc( c.processesLimit = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "processes_limit"), prometheus.BuildFQName(types.Namespace, Name, "processes_limit"),
"Deprecated: Use `windows_system_process_limit` instead.", "Deprecated: Use `windows_system_process_limit` instead.",
@@ -216,6 +225,10 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
c.collect(ch) 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 { if err := c.collectHostname(ch); err != nil {
errs = append(errs, fmt.Errorf("failed to collect hostname metrics: %w", err)) 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 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 { func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
timeZoneInfo, err := kernel32.GetDynamicTimeZoneInformation() timeZoneInfo, err := kernel32.GetDynamicTimeZoneInformation()
if err != nil { if err != nil {

View File

@@ -303,6 +303,8 @@ windows_exporter_collector_timeout{collector="udp"} 0
# TYPE windows_os_physical_memory_free_bytes gauge # TYPE windows_os_physical_memory_free_bytes gauge
# HELP windows_os_process_memory_limit_bytes Deprecated: Use `windows_memory_process_memory_limit_bytes` instead. # HELP windows_os_process_memory_limit_bytes Deprecated: Use `windows_memory_process_memory_limit_bytes` instead.
# TYPE windows_os_process_memory_limit_bytes gauge # 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. # HELP windows_os_processes_limit Deprecated: Use `windows_system_process_limit` instead.
# TYPE windows_os_processes_limit gauge # TYPE windows_os_processes_limit gauge
# HELP windows_os_time Deprecated: Use windows_time_current_timestamp_seconds instead. # HELP windows_os_time Deprecated: Use windows_time_current_timestamp_seconds instead.