mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-20 19:56:36 +00:00
feat: increase time resolution when possible (collectors: os, system, time) (#2047)
This commit is contained in:
@@ -172,7 +172,7 @@ func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.fileMTime,
|
||||
prometheus.GaugeValue,
|
||||
float64(fileInfo.ModTime().UTC().Unix()),
|
||||
float64(fileInfo.ModTime().UTC().UnixMicro())/1e6,
|
||||
filePath,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.sessionInfo,
|
||||
prometheus.GaugeValue,
|
||||
float64(session.LogonTime.Unix()),
|
||||
float64(session.LogonTime.UnixMicro())/1e6,
|
||||
session.LogonId.String(), session.UserName, session.LogonDomain, session.LogonType.String(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.time,
|
||||
prometheus.GaugeValue,
|
||||
float64(time.Now().Unix()),
|
||||
float64(time.Now().UnixMicro())/1e6,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
|
||||
@@ -142,7 +142,7 @@ func (c *Collector) collectWorker() {
|
||||
name, pidString, parentPID, strconv.Itoa(int(processGroupID)), processOwner, cmdLine,
|
||||
)
|
||||
|
||||
startTime := float64(time.Now().Unix() - int64(data.ElapsedTime))
|
||||
startTime := float64(time.Now().UnixMicro())/1e6 - data.ElapsedTime
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.startTimeOld,
|
||||
|
||||
@@ -141,7 +141,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
nil,
|
||||
)
|
||||
|
||||
c.bootTimeTimestamp = float64(time.Now().Unix() - int64(kernel32.GetTickCount64()/1000))
|
||||
c.bootTimeTimestamp = float64(uint64(time.Now().UnixMilli())-kernel32.GetTickCount64()) / 1000
|
||||
|
||||
var err error
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.currentTime,
|
||||
prometheus.GaugeValue,
|
||||
float64(time.Now().Unix()),
|
||||
float64(time.Now().UnixMicro())/1e6,
|
||||
)
|
||||
|
||||
timeZoneInfo, err := kernel32.GetDynamicTimeZoneInformation()
|
||||
|
||||
@@ -405,7 +405,7 @@ func (c *Collector) fetchUpdates(logger *slog.Logger, usd *ole.IDispatch) ([]pro
|
||||
metricsBuf = append(metricsBuf, prometheus.MustNewConstMetric(
|
||||
c.lastScrapeMetric,
|
||||
prometheus.GaugeValue,
|
||||
float64(time.Now().Unix()),
|
||||
float64(time.Now().UnixMicro())/1e6,
|
||||
))
|
||||
|
||||
return metricsBuf, nil
|
||||
|
||||
Reference in New Issue
Block a user