mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-17 18:26:36 +00:00
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:
committed by
Jan-Otto Kröpke
parent
a56e1ac71a
commit
6f0209ddb7
@@ -23,6 +23,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/kernel32"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
@@ -58,14 +59,17 @@ type Collector struct {
|
||||
perfDataCollector *pdh.Collector
|
||||
perfDataObject []perfDataCounterValues
|
||||
|
||||
currentTime *prometheus.Desc
|
||||
timezone *prometheus.Desc
|
||||
clockFrequencyAdjustmentPPBTotal *prometheus.Desc
|
||||
computedTimeOffset *prometheus.Desc
|
||||
ntpClientTimeSourceCount *prometheus.Desc
|
||||
ntpRoundTripDelay *prometheus.Desc
|
||||
ntpServerIncomingRequestsTotal *prometheus.Desc
|
||||
ntpServerOutgoingResponsesTotal *prometheus.Desc
|
||||
ppbCounterPresent bool
|
||||
|
||||
currentTime *prometheus.Desc
|
||||
timezone *prometheus.Desc
|
||||
clockFrequencyAdjustment *prometheus.Desc
|
||||
clockFrequencyAdjustmentPPB *prometheus.Desc
|
||||
computedTimeOffset *prometheus.Desc
|
||||
ntpClientTimeSourceCount *prometheus.Desc
|
||||
ntpRoundTripDelay *prometheus.Desc
|
||||
ntpServerIncomingRequestsTotal *prometheus.Desc
|
||||
ntpServerOutgoingResponsesTotal *prometheus.Desc
|
||||
}
|
||||
|
||||
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(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "current_timestamp_seconds"),
|
||||
"OperatingSystem.LocalDateTime",
|
||||
@@ -137,9 +144,15 @@ func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
[]string{"timezone"},
|
||||
nil,
|
||||
)
|
||||
c.clockFrequencyAdjustmentPPBTotal = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "clock_frequency_adjustment_ppb_total"),
|
||||
"Total adjustment made to the local system clock frequency by W32Time in Parts Per Billion (PPB) units.",
|
||||
c.clockFrequencyAdjustment = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "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.",
|
||||
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's of PPB. This counter helps visualize the finer actions being taken by W32time to synchronize the local clock.",
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
@@ -232,14 +245,23 @@ func (c *Collector) collectTime(ch chan<- prometheus.Metric) error {
|
||||
func (c *Collector) collectNTP(ch chan<- prometheus.Metric) error {
|
||||
err := c.perfDataCollector.Collect(&c.perfDataObject)
|
||||
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(
|
||||
c.clockFrequencyAdjustmentPPBTotal,
|
||||
prometheus.CounterValue,
|
||||
c.perfDataObject[0].ClockFrequencyAdjustmentPPBTotal,
|
||||
c.clockFrequencyAdjustment,
|
||||
prometheus.GaugeValue,
|
||||
c.perfDataObject[0].ClockFrequencyAdjustment,
|
||||
)
|
||||
|
||||
if c.ppbCounterPresent {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.clockFrequencyAdjustmentPPB,
|
||||
prometheus.GaugeValue,
|
||||
c.perfDataObject[0].ClockFrequencyAdjustmentPPB,
|
||||
)
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.computedTimeOffset,
|
||||
prometheus.GaugeValue,
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
package time
|
||||
|
||||
type perfDataCounterValues struct {
|
||||
ClockFrequencyAdjustmentPPBTotal float64 `perfdata:"Clock Frequency Adjustment (ppb)"`
|
||||
ComputedTimeOffset float64 `perfdata:"Computed Time Offset"`
|
||||
NTPClientTimeSourceCount float64 `perfdata:"NTP Client Time Source Count"`
|
||||
NTPRoundTripDelay float64 `perfdata:"NTP Roundtrip Delay"`
|
||||
NTPServerIncomingRequestsTotal float64 `perfdata:"NTP Server Incoming Requests"`
|
||||
NTPServerOutgoingResponsesTotal float64 `perfdata:"NTP Server Outgoing Responses"`
|
||||
ClockFrequencyAdjustment float64 `perfdata:"Clock Frequency Adjustment"`
|
||||
ClockFrequencyAdjustmentPPB float64 `perfdata:"Clock Frequency Adjustment (ppb)" perfdata_min_build:"17763"`
|
||||
ComputedTimeOffset float64 `perfdata:"Computed Time Offset"`
|
||||
NTPClientTimeSourceCount float64 `perfdata:"NTP Client Time Source Count"`
|
||||
NTPRoundTripDelay float64 `perfdata:"NTP Roundtrip Delay"`
|
||||
NTPServerIncomingRequestsTotal float64 `perfdata:"NTP Server Incoming Requests"`
|
||||
NTPServerOutgoingResponsesTotal float64 `perfdata:"NTP Server Outgoing Responses"`
|
||||
}
|
||||
|
||||
@@ -20,10 +20,12 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"golang.org/x/sys/windows"
|
||||
@@ -151,7 +153,18 @@ func NewCollectorWithReflection(resultType CounterType, object string, instances
|
||||
|
||||
var counterHandle pdhCounterHandle
|
||||
|
||||
//nolint:nestif
|
||||
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)))
|
||||
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user