mirror of https://github.com/jetkvm/kvm.git
Merge c13e1e11c5
into d79f359c43
This commit is contained in:
commit
dd5d4f541d
|
@ -13,7 +13,8 @@ var defaultNTPServers = []string{
|
||||||
"time.aws.com",
|
"time.aws.com",
|
||||||
"time.windows.com",
|
"time.windows.com",
|
||||||
"time.google.com",
|
"time.google.com",
|
||||||
"162.159.200.123", // time.cloudflare.com
|
"162.159.200.123", // time.cloudflare.com IPv4
|
||||||
|
"2606:4700:f1::123", // time.cloudflare.com IPv6
|
||||||
"0.pool.ntp.org",
|
"0.pool.ntp.org",
|
||||||
"1.pool.ntp.org",
|
"1.pool.ntp.org",
|
||||||
"2.pool.ntp.org",
|
"2.pool.ntp.org",
|
||||||
|
@ -57,6 +58,13 @@ func (t *TimeSync) queryMultipleNTP(servers []string, timeout time.Duration) (no
|
||||||
|
|
||||||
// query the server
|
// query the server
|
||||||
now, response, err := queryNtpServer(server, timeout)
|
now, response, err := queryNtpServer(server, timeout)
|
||||||
|
if err != nil {
|
||||||
|
scopedLogger.Warn().
|
||||||
|
Str("error", err.Error()).
|
||||||
|
Msg("failed to query NTP server")
|
||||||
|
results <- nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// set the last RTT
|
// set the last RTT
|
||||||
metricNtpServerLastRTT.WithLabelValues(
|
metricNtpServerLastRTT.WithLabelValues(
|
||||||
|
@ -76,7 +84,6 @@ func (t *TimeSync) queryMultipleNTP(servers []string, timeout time.Duration) (no
|
||||||
strconv.Itoa(int(response.Precision)),
|
strconv.Itoa(int(response.Precision)),
|
||||||
).Set(1)
|
).Set(1)
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
// increase success count
|
// increase success count
|
||||||
metricNtpTotalSuccessCount.Inc()
|
metricNtpTotalSuccessCount.Inc()
|
||||||
metricNtpSuccessCount.WithLabelValues(server).Inc()
|
metricNtpSuccessCount.WithLabelValues(server).Inc()
|
||||||
|
@ -92,16 +99,18 @@ func (t *TimeSync) queryMultipleNTP(servers []string, timeout time.Duration) (no
|
||||||
now: now,
|
now: now,
|
||||||
offset: &response.ClockOffset,
|
offset: &response.ClockOffset,
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
scopedLogger.Warn().
|
|
||||||
Str("error", err.Error()).
|
|
||||||
Msg("failed to query NTP server")
|
|
||||||
}
|
|
||||||
}(server)
|
}(server)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for range servers {
|
||||||
result := <-results
|
result := <-results
|
||||||
return result.now, result.offset
|
if result == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
now, offset = result.now, result.offset
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryNtpServer(server string, timeout time.Duration) (now *time.Time, response *ntp.Response, err error) {
|
func queryNtpServer(server string, timeout time.Duration) (now *time.Time, response *ntp.Response, err error) {
|
||||||
|
|
Loading…
Reference in New Issue