feat: increase time resolution when possible (collectors: os, system, time) (#2047)

This commit is contained in:
Lapo Luchini
2025-06-20 13:12:26 +02:00
committed by GitHub
parent 66cd489c4a
commit 59ac3072b1
8 changed files with 8 additions and 8 deletions

View File

@@ -30,7 +30,7 @@ Matching is case-sensitive.
| `windows_time_ntp_round_trip_delay_seconds` | Total roundtrip delay experienced by the NTP client in receiving a response from the server for the most recent request, in seconds. This is the time elapsed on the NTP client between transmitting a request to the NTP server and receiving a valid response from the server. | gauge | None | | `windows_time_ntp_round_trip_delay_seconds` | Total roundtrip delay experienced by the NTP client in receiving a response from the server for the most recent request, in seconds. This is the time elapsed on the NTP client between transmitting a request to the NTP server and receiving a valid response from the server. | gauge | None |
| `windows_time_ntp_server_outgoing_responses_total` | Total number of requests responded to by the NTP server. | counter | None | | `windows_time_ntp_server_outgoing_responses_total` | Total number of requests responded to by the NTP server. | counter | None |
| `windows_time_ntp_server_incoming_requests_total` | Total number of requests received by the NTP server. | counter | None | | `windows_time_ntp_server_incoming_requests_total` | Total number of requests received by the NTP server. | counter | None |
| `windows_time_current_timestamp_seconds` | Current time as reported by the operating system, in [Unix time](https://en.wikipedia.org/wiki/Unix_time). See [time.Unix()](https://golang.org/pkg/time/#Unix) for details | gauge | None | | `windows_time_current_timestamp_seconds` | Current time as reported by the operating system, in [Unix time](https://en.wikipedia.org/wiki/Unix_time). See [time.UnixMicro()](https://golang.org/pkg/time/#UnixMicro) for details | gauge | None |
| `windows_time_timezone` | Current timezone as reported by the operating system. | gauge | `timezone` | | `windows_time_timezone` | Current timezone as reported by the operating system. | gauge | `timezone` |
| `windows_time_clock_sync_source` | This value reflects the sync source of the system clock. | gauge | `type` | | `windows_time_clock_sync_source` | This value reflects the sync source of the system clock. | gauge | `type` |

View File

@@ -172,7 +172,7 @@ func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.fileMTime, c.fileMTime,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(fileInfo.ModTime().UTC().Unix()), float64(fileInfo.ModTime().UTC().UnixMicro())/1e6,
filePath, filePath,
) )
} }

View File

@@ -96,7 +96,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.sessionInfo, c.sessionInfo,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(session.LogonTime.Unix()), float64(session.LogonTime.UnixMicro())/1e6,
session.LogonId.String(), session.UserName, session.LogonDomain, session.LogonType.String(), session.LogonId.String(), session.UserName, session.LogonDomain, session.LogonType.String(),
) )
} }

View File

@@ -290,7 +290,7 @@ func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.time, c.time,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(time.Now().Unix()), float64(time.Now().UnixMicro())/1e6,
) )
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(

View File

@@ -142,7 +142,7 @@ func (c *Collector) collectWorker() {
name, pidString, parentPID, strconv.Itoa(int(processGroupID)), processOwner, cmdLine, 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( ch <- prometheus.MustNewConstMetric(
c.startTimeOld, c.startTimeOld,

View File

@@ -141,7 +141,7 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
nil, nil,
) )
c.bootTimeTimestamp = float64(time.Now().Unix() - int64(kernel32.GetTickCount64()/1000)) c.bootTimeTimestamp = float64(uint64(time.Now().UnixMilli())-kernel32.GetTickCount64()) / 1000
var err error var err error

View File

@@ -245,7 +245,7 @@ func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.currentTime, c.currentTime,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(time.Now().Unix()), float64(time.Now().UnixMicro())/1e6,
) )
timeZoneInfo, err := kernel32.GetDynamicTimeZoneInformation() timeZoneInfo, err := kernel32.GetDynamicTimeZoneInformation()

View File

@@ -405,7 +405,7 @@ func (c *Collector) fetchUpdates(logger *slog.Logger, usd *ole.IDispatch) ([]pro
metricsBuf = append(metricsBuf, prometheus.MustNewConstMetric( metricsBuf = append(metricsBuf, prometheus.MustNewConstMetric(
c.lastScrapeMetric, c.lastScrapeMetric,
prometheus.GaugeValue, prometheus.GaugeValue,
float64(time.Now().Unix()), float64(time.Now().UnixMicro())/1e6,
)) ))
return metricsBuf, nil return metricsBuf, nil