From 61ad08c278a003e4553ff3911fbb076dc2c4b84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 25 Jan 2025 13:39:37 +0100 Subject: [PATCH 1/2] fix: negative values with windows_process_start_time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- internal/collector/process/process.go | 11 ++++++++++- internal/collector/process/process_v1.go | 7 +++++++ internal/collector/process/process_v2.go | 12 +++++++++++- internal/pdh/collector.go | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/internal/collector/process/process.go b/internal/collector/process/process.go index eef2ca162..eb63082e3 100644 --- a/internal/collector/process/process.go +++ b/internal/collector/process/process.go @@ -76,6 +76,8 @@ type Collector struct { poolBytes *prometheus.Desc priorityBase *prometheus.Desc privateBytes *prometheus.Desc + // DEPRECATED: Use start_time_seconds_timestamp instead + startTimeOld *prometheus.Desc startTime *prometheus.Desc threadCount *prometheus.Desc virtualBytes *prometheus.Desc @@ -214,8 +216,15 @@ func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error { nil, ) - c.startTime = prometheus.NewDesc( + c.startTimeOld = prometheus.NewDesc( prometheus.BuildFQName(types.Namespace, Name, "start_time"), + "DEPRECATED: Use start_time_seconds_timestamp instead", + []string{"process", "process_id"}, + nil, + ) + + c.startTime = prometheus.NewDesc( + prometheus.BuildFQName(types.Namespace, Name, "start_time_seconds_timestamp"), "Time of process start.", []string{"process", "process_id"}, nil, diff --git a/internal/collector/process/process_v1.go b/internal/collector/process/process_v1.go index a50308aff..5735fd886 100644 --- a/internal/collector/process/process_v1.go +++ b/internal/collector/process/process_v1.go @@ -141,6 +141,13 @@ func (c *Collector) collectWorkerV1() { name, pidString, ) + ch <- prometheus.MustNewConstMetric( + c.startTimeOld, + prometheus.GaugeValue, + data.ElapsedTime, + name, pidString, + ) + ch <- prometheus.MustNewConstMetric( c.handleCount, prometheus.GaugeValue, diff --git a/internal/collector/process/process_v2.go b/internal/collector/process/process_v2.go index 2e0d1a887..5f8488c4d 100644 --- a/internal/collector/process/process_v2.go +++ b/internal/collector/process/process_v2.go @@ -23,6 +23,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/prometheus-community/windows_exporter/internal/pdh" "github.com/prometheus/client_golang/prometheus" @@ -134,10 +135,19 @@ func (c *Collector) collectWorkerV2() { name, pidString, parentPID, strconv.Itoa(int(processGroupID)), processOwner, cmdLine, ) + startTime := float64(time.Now().Unix() - int64(data.ElapsedTime)) + + ch <- prometheus.MustNewConstMetric( + c.startTimeOld, + prometheus.GaugeValue, + startTime, + name, pidString, + ) + ch <- prometheus.MustNewConstMetric( c.startTime, prometheus.GaugeValue, - data.ElapsedTime, + startTime, name, pidString, ) diff --git a/internal/pdh/collector.go b/internal/pdh/collector.go index 6a8672be0..1aa689395 100644 --- a/internal/pdh/collector.go +++ b/internal/pdh/collector.go @@ -390,7 +390,7 @@ func (c *Collector) collectWorkerRaw() { case PERF_ELAPSED_TIME: dv.Index(index). Field(counter.FieldIndexValue). - SetFloat(float64((item.RawValue.FirstValue - WindowsEpoch) / counter.Frequency)) + SetFloat(float64((item.RawValue.SecondValue - item.RawValue.FirstValue) / counter.Frequency)) case PERF_100NSEC_TIMER, PERF_PRECISION_100NS_TIMER: dv.Index(index). Field(counter.FieldIndexValue). From 8515a41ac9b30e7fc349fd41edc7a873d6b71ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 25 Jan 2025 13:54:54 +0100 Subject: [PATCH 2/2] rename: `windows_process_start_time` -> `windows_process_start_time_seconds_timestamp` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- internal/collector/process/process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/collector/process/process.go b/internal/collector/process/process.go index eb63082e3..bd9bbc9c2 100644 --- a/internal/collector/process/process.go +++ b/internal/collector/process/process.go @@ -76,7 +76,7 @@ type Collector struct { poolBytes *prometheus.Desc priorityBase *prometheus.Desc privateBytes *prometheus.Desc - // DEPRECATED: Use start_time_seconds_timestamp instead + // Deprecated: Use start_time_seconds_timestamp instead startTimeOld *prometheus.Desc startTime *prometheus.Desc threadCount *prometheus.Desc