time: windows_time_clock_frequency_adjustment_ppb_total -> windows_time_clock_frequency_adjustment_ppb and add windows_time_clock_frequency_adjustment metric for Win2016 (#1910)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
Signed-off-by: Jan-Otto Kröpke <github@jkroepke.de>
(cherry picked from commit d6196c5c6b)
This commit is contained in:
Jan-Otto Kröpke
2025-03-12 08:28:30 +01:00
committed by Jan-Otto Kröpke
parent a56e1ac71a
commit 6f0209ddb7
6 changed files with 73 additions and 34 deletions

View File

@@ -13,4 +13,4 @@ indent_size = 4
[*.{yml,yaml}] [*.{yml,yaml}]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

View File

@@ -21,16 +21,17 @@ Matching is case-sensitive.
## Metrics ## Metrics
| Name | Description | Type | Labels | | Name | Description | Type | Labels |
|-----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|------------| |----------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|------------|
| `windows_time_clock_frequency_adjustment_ppb_total` | Total adjustment made to the local system clock frequency by W32Time in parts per billion (PPB) units. 1 PPB adjustment implies the system clock was adjusted at a rate of 1 nanosecond per second (1 ns/s). The smallest possible adjustment can vary and is expected to be in the order of 100's of PPB. | counter | None | | `windows_time_clock_frequency_adjustment` | Adjustment made to the local system clock frequency by W32Time in parts per billion (PPB) units. 1 PPB adjustment implies the system clock was adjusted at a rate of 1 nanosecond per second (1 ns/s). The smallest possible adjustment can vary and is expected to be in the order of 100's of PPB. | gauge | None |
| `windows_time_computed_time_offset_seconds` | The absolute time offset between the system clock and the chosen time source, as computed by the W32Time service in microseconds. When a new valid sample is available, the computed time is updated with the time offset indicated by the sample. This time is the actual time offset of the local clock. W32Time initiates clock correction by using this offset and updates the computed time in between samples with the remaining time offset that needs to be applied to the local clock. Clock accuracy can be tracked by using this performance counter with a low polling interval (for example, 256 seconds or less) and looking for the counter value to be smaller than the desired clock accuracy limit. | gauge | None | | `windows_time_clock_frequency_adjustment_ppb` | Adjustment made to the local system clock frequency by W32Time in parts per billion (PPB) units. 1 PPB adjustment implies the system clock was adjusted at a rate of 1 nanosecond per second (1 ns/s). The smallest possible adjustment can vary and is expected to be in the order of 100's of PPB. | gauge | None |
| `windows_time_ntp_client_time_sources` | Active number of NTP Time sources being used by the client. This is a count of active, distinct IP addresses of time servers that are responding to this client's requests. | gauge | None | | `windows_time_computed_time_offset_seconds` | The absolute time offset between the system clock and the chosen time source, as computed by the W32Time service in microseconds. When a new valid sample is available, the computed time is updated with the time offset indicated by the sample. This time is the actual time offset of the local clock. W32Time initiates clock correction by using this offset and updates the computed time in between samples with the remaining time offset that needs to be applied to the local clock. Clock accuracy can be tracked by using this performance counter with a low polling interval (for example, 256 seconds or less) and looking for the counter value to be smaller than the desired clock accuracy limit. | 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_client_time_sources` | Active number of NTP Time sources being used by the client. This is a count of active, distinct IP addresses of time servers that are responding to this client's requests. | gauge | None |
| `windows_time_ntp_server_outgoing_responses_total` | Total number of requests responded to by the NTP server. | counter | 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_incoming_requests_total` | Total number of requests received 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_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_ntp_server_incoming_requests_total` | Total number of requests received by the NTP server. | counter | None |
| `windows_time_timezone` | Current timezone as reported by the operating system. | gauge | `timezone` | | `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_timezone` | Current timezone as reported by the operating system. | gauge | `timezone` |
### Example metric ### Example metric
_This collector does not yet have explained examples, we would appreciate your help adding them!_ _This collector does not yet have explained examples, we would appreciate your help adding them!_

View File

@@ -23,6 +23,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/Microsoft/hcsshim/osversion"
"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/mi" "github.com/prometheus-community/windows_exporter/internal/mi"
@@ -58,14 +59,17 @@ type Collector struct {
perfDataCollector *pdh.Collector perfDataCollector *pdh.Collector
perfDataObject []perfDataCounterValues perfDataObject []perfDataCounterValues
currentTime *prometheus.Desc ppbCounterPresent bool
timezone *prometheus.Desc
clockFrequencyAdjustmentPPBTotal *prometheus.Desc currentTime *prometheus.Desc
computedTimeOffset *prometheus.Desc timezone *prometheus.Desc
ntpClientTimeSourceCount *prometheus.Desc clockFrequencyAdjustment *prometheus.Desc
ntpRoundTripDelay *prometheus.Desc clockFrequencyAdjustmentPPB *prometheus.Desc
ntpServerIncomingRequestsTotal *prometheus.Desc computedTimeOffset *prometheus.Desc
ntpServerOutgoingResponsesTotal *prometheus.Desc ntpClientTimeSourceCount *prometheus.Desc
ntpRoundTripDelay *prometheus.Desc
ntpServerIncomingRequestsTotal *prometheus.Desc
ntpServerOutgoingResponsesTotal *prometheus.Desc
} }
func New(config *Config) *Collector { func New(config *Config) *Collector {
@@ -125,6 +129,9 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
} }
} }
// https://github.com/prometheus-community/windows_exporter/issues/1891
c.ppbCounterPresent = osversion.Build() >= osversion.LTSC2019
c.currentTime = prometheus.NewDesc( c.currentTime = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "current_timestamp_seconds"), prometheus.BuildFQName(types.Namespace, Name, "current_timestamp_seconds"),
"OperatingSystem.LocalDateTime", "OperatingSystem.LocalDateTime",
@@ -137,9 +144,15 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
[]string{"timezone"}, []string{"timezone"},
nil, nil,
) )
c.clockFrequencyAdjustmentPPBTotal = prometheus.NewDesc( c.clockFrequencyAdjustment = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "clock_frequency_adjustment_ppb_total"), prometheus.BuildFQName(types.Namespace, Name, "clock_frequency_adjustment"),
"Total adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units.", "This value reflects the adjustment made to the local system clock frequency by W32Time in nominal clock units. This counter helps visualize the finer adjustments being made by W32time to synchronize the local clock.",
nil,
nil,
)
c.clockFrequencyAdjustmentPPB = prometheus.NewDesc(
prometheus.BuildFQName(types.Namespace, Name, "clock_frequency_adjustment_ppb"),
"This value reflects the adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units. 1 PPB adjustment imples the system clock was adjusted at a rate of 1 nanosecond per second. The smallest possible adjustment can vary and can be expected to be in the order of 100&apos;s of PPB. This counter helps visualize the finer actions being taken by W32time to synchronize the local clock.",
nil, nil,
nil, nil,
) )
@@ -232,14 +245,23 @@ func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
func (c *Collector) collectNTP(ch chan<- prometheus.Metric) error { func (c *Collector) collectNTP(ch chan<- prometheus.Metric) error {
err := c.perfDataCollector.Collect(&c.perfDataObject) err := c.perfDataCollector.Collect(&c.perfDataObject)
if err != nil { if err != nil {
return fmt.Errorf("failed to collect VM Memory metrics: %w", err) return fmt.Errorf("failed to collect time metrics: %w", err)
} }
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.clockFrequencyAdjustmentPPBTotal, c.clockFrequencyAdjustment,
prometheus.CounterValue, prometheus.GaugeValue,
c.perfDataObject[0].ClockFrequencyAdjustmentPPBTotal, c.perfDataObject[0].ClockFrequencyAdjustment,
) )
if c.ppbCounterPresent {
ch <- prometheus.MustNewConstMetric(
c.clockFrequencyAdjustmentPPB,
prometheus.GaugeValue,
c.perfDataObject[0].ClockFrequencyAdjustmentPPB,
)
}
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.computedTimeOffset, c.computedTimeOffset,
prometheus.GaugeValue, prometheus.GaugeValue,

View File

@@ -16,10 +16,11 @@
package time package time
type perfDataCounterValues struct { type perfDataCounterValues struct {
ClockFrequencyAdjustmentPPBTotal float64 `perfdata:"Clock Frequency Adjustment (ppb)"` ClockFrequencyAdjustment float64 `perfdata:"Clock Frequency Adjustment"`
ComputedTimeOffset float64 `perfdata:"Computed Time Offset"` ClockFrequencyAdjustmentPPB float64 `perfdata:"Clock Frequency Adjustment (ppb)" perfdata_min_build:"17763"`
NTPClientTimeSourceCount float64 `perfdata:"NTP Client Time Source Count"` ComputedTimeOffset float64 `perfdata:"Computed Time Offset"`
NTPRoundTripDelay float64 `perfdata:"NTP Roundtrip Delay"` NTPClientTimeSourceCount float64 `perfdata:"NTP Client Time Source Count"`
NTPServerIncomingRequestsTotal float64 `perfdata:"NTP Server Incoming Requests"` NTPRoundTripDelay float64 `perfdata:"NTP Roundtrip Delay"`
NTPServerOutgoingResponsesTotal float64 `perfdata:"NTP Server Outgoing Responses"` NTPServerIncomingRequestsTotal float64 `perfdata:"NTP Server Incoming Requests"`
NTPServerOutgoingResponsesTotal float64 `perfdata:"NTP Server Outgoing Responses"`
} }

View File

@@ -20,10 +20,12 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"slices" "slices"
"strconv"
"strings" "strings"
"sync" "sync"
"unsafe" "unsafe"
"github.com/Microsoft/hcsshim/osversion"
"github.com/prometheus-community/windows_exporter/internal/mi" "github.com/prometheus-community/windows_exporter/internal/mi"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
@@ -151,7 +153,18 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
var counterHandle pdhCounterHandle var counterHandle pdhCounterHandle
//nolint:nestif
if ret := AddEnglishCounter(handle, counterPath, 0, &counterHandle); ret != ErrorSuccess { if ret := AddEnglishCounter(handle, counterPath, 0, &counterHandle); ret != ErrorSuccess {
if ret == CstatusNoCounter {
if minOSBuildTag, ok := f.Tag.Lookup("perfdata_min_build"); ok {
if minOSBuild, err := strconv.Atoi(minOSBuildTag); err == nil {
if uint16(minOSBuild) > osversion.Build() {
continue
}
}
}
}
errs = append(errs, fmt.Errorf("failed to add counter %s: %w", counterPath, NewPdhError(ret))) errs = append(errs, fmt.Errorf("failed to add counter %s: %w", counterPath, NewPdhError(ret)))
continue continue

View File

@@ -427,8 +427,10 @@ windows_service_state{name="Themes",state="stopped"} 0
# TYPE windows_tcp_segments_total counter # TYPE windows_tcp_segments_total counter
# HELP windows_textfile_mtime_seconds Unixtime mtime of textfiles successfully read. # HELP windows_textfile_mtime_seconds Unixtime mtime of textfiles successfully read.
# TYPE windows_textfile_mtime_seconds gauge # TYPE windows_textfile_mtime_seconds gauge
# HELP windows_time_clock_frequency_adjustment_ppb_total Total adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units. # HELP windows_time_clock_frequency_adjustment This value reflects the adjustment made to the local system clock frequency by W32Time in nominal clock units. This counter helps visualize the finer adjustments being made by W32time to synchronize the local clock.
# TYPE windows_time_clock_frequency_adjustment_ppb_total counter # TYPE windows_time_clock_frequency_adjustment gauge
# HELP windows_time_clock_frequency_adjustment_ppb This value reflects the adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units. 1 PPB adjustment imples the system clock was adjusted at a rate of 1 nanosecond per second. The smallest possible adjustment can vary and can be expected to be in the order of 100&apos;s of PPB. This counter helps visualize the finer actions being taken by W32time to synchronize the local clock.
# TYPE windows_time_clock_frequency_adjustment_ppb gauge
# HELP windows_time_computed_time_offset_seconds Absolute time offset between the system clock and the chosen time source, in seconds # HELP windows_time_computed_time_offset_seconds Absolute time offset between the system clock and the chosen time source, in seconds
# TYPE windows_time_computed_time_offset_seconds gauge # TYPE windows_time_computed_time_offset_seconds gauge
# HELP windows_time_current_timestamp_seconds OperatingSystem.LocalDateTime # HELP windows_time_current_timestamp_seconds OperatingSystem.LocalDateTime