@@ -20,8 +20,10 @@ package system
2020import (
2121 "fmt"
2222 "log/slog"
23+ "time"
2324
2425 "github.com/alecthomas/kingpin/v2"
26+ "github.com/prometheus-community/windows_exporter/internal/headers/kernel32"
2527 "github.com/prometheus-community/windows_exporter/internal/mi"
2628 "github.com/prometheus-community/windows_exporter/internal/pdh"
2729 "github.com/prometheus-community/windows_exporter/internal/types"
@@ -39,6 +41,8 @@ var ConfigDefaults = Config{}
3941type Collector struct {
4042 config Config
4143
44+ bootTimeTimestamp float64
45+
4246 perfDataCollector * pdh.Collector
4347 perfDataObject []perfDataCounterValues
4448
@@ -48,8 +52,10 @@ type Collector struct {
4852 processes * prometheus.Desc
4953 processesLimit * prometheus.Desc
5054 systemCallsTotal * prometheus.Desc
51- bootTime * prometheus.Desc
52- threads * prometheus.Desc
55+ // Deprecated: Use windows_system_boot_time_timestamp instead
56+ bootTimeSeconds * prometheus.Desc
57+ bootTime * prometheus.Desc
58+ threads * prometheus.Desc
5359}
5460
5561func New (config * Config ) * Collector {
@@ -80,11 +86,17 @@ func (c *Collector) Close() error {
8086
8187func (c * Collector ) Build (_ * slog.Logger , _ * mi.Session ) error {
8288 c .bootTime = prometheus .NewDesc (
83- prometheus .BuildFQName (types .Namespace , Name , "boot_time_timestamp_seconds " ),
89+ prometheus .BuildFQName (types .Namespace , Name , "boot_time_timestamp " ),
8490 "Unix timestamp of system boot time" ,
8591 nil ,
8692 nil ,
8793 )
94+ c .bootTimeSeconds = prometheus .NewDesc (
95+ prometheus .BuildFQName (types .Namespace , Name , "boot_time_timestamp_seconds" ),
96+ "Deprecated: Use windows_system_boot_time_timestamp instead" ,
97+ nil ,
98+ nil ,
99+ )
88100 c .contextSwitchesTotal = prometheus .NewDesc (
89101 prometheus .BuildFQName (types .Namespace , Name , "context_switches_total" ),
90102 "Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)" ,
@@ -129,6 +141,8 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
129141 nil ,
130142 )
131143
144+ c .bootTimeTimestamp = float64 (time .Now ().Unix () - int64 (kernel32 .GetTickCount64 ()/ 1000 ))
145+
132146 var err error
133147
134148 c .perfDataCollector , err = pdh .NewCollector [perfDataCounterValues ](pdh .CounterTypeRaw , "System" , nil )
@@ -173,14 +187,21 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
173187 c .perfDataObject [0 ].SystemCallsPerSec ,
174188 )
175189 ch <- prometheus .MustNewConstMetric (
176- c .bootTime ,
190+ c .threads ,
177191 prometheus .GaugeValue ,
178- c .perfDataObject [0 ].SystemUpTime ,
192+ c .perfDataObject [0 ].Threads ,
179193 )
194+
180195 ch <- prometheus .MustNewConstMetric (
181- c .threads ,
196+ c .bootTimeSeconds ,
182197 prometheus .GaugeValue ,
183- c .perfDataObject [0 ].Threads ,
198+ c .bootTimeTimestamp ,
199+ )
200+
201+ ch <- prometheus .MustNewConstMetric (
202+ c .bootTime ,
203+ prometheus .GaugeValue ,
204+ c .bootTimeTimestamp ,
184205 )
185206
186207 // Windows has no defined limit, and is based off available resources. This currently isn't calculated by WMI and is set to default value.
0 commit comments