mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-08-20 18:33:52 -07:00
* Add metrics from SNTPv4 packet to ntp collector & add ntpd sanity check 1. Checking local clock against remote NTP daemon is bad idea, local ntpd acting as a client should do it better and avoid excessive load on remote NTP server so the collector is refactored to query local NTP server. 2. Checking local clock against remote one does not check local ntpd itself. Local ntpd may be down or out of sync due to network issues, but clock will be OK. 3. Checking NTP server using sanity of it's response is tricky and depends on ntpd implementation, that's why common `node_ntp_sanity` variable is exported. * `govendor add golang.org/x/net/ipv4`, it is dependency of github.com/beevik/ntp * Update github.com/beevik/ntp to include boring SNTP fix * Use variable name from RFC5905 * ntp: move code to make export of raw metrics more explicit * Move NTP math to `github.com/beevik/ntp` * Make `golint` happy * Add some brief docs explaining `ntp` #655 and `timex` #664 modules * ntp: drop XXX comment that got its decision * ntp: add `_seconds` suffix to relevant metrics * Better `node_ntp_leap` comment * s/node_ntp_reftime/node_ntp_reference_timestamp_seconds/ as requested by @discordianfish * Extract subsystem name to const as suggested by @SuperQ
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
// Copyright 2017 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package socket
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func probeProtocolStack() int { return 8 }
|
|
|
|
const (
|
|
sysSETSOCKOPT = 0xe
|
|
sysGETSOCKOPT = 0xf
|
|
sysSENDMSG = 0x10
|
|
sysRECVMSG = 0x11
|
|
sysRECVMMSG = 0x13
|
|
sysSENDMMSG = 0x14
|
|
)
|
|
|
|
func socketcall(call, a0, a1, a2, a3, a4, a5 uintptr) (uintptr, syscall.Errno)
|
|
func rawsocketcall(call, a0, a1, a2, a3, a4, a5 uintptr) (uintptr, syscall.Errno)
|
|
|
|
func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
|
|
l := uint32(len(b))
|
|
_, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
|
|
return int(l), errnoErr(errno)
|
|
}
|
|
|
|
func setsockopt(s uintptr, level, name int, b []byte) error {
|
|
_, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
|
|
return errnoErr(errno)
|
|
}
|
|
|
|
func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
|
|
n, errno := socketcall(sysRECVMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
|
|
return int(n), errnoErr(errno)
|
|
}
|
|
|
|
func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
|
|
n, errno := socketcall(sysSENDMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
|
|
return int(n), errnoErr(errno)
|
|
}
|
|
|
|
func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
|
n, errno := socketcall(sysRECVMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
|
return int(n), errnoErr(errno)
|
|
}
|
|
|
|
func sendmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
|
n, errno := socketcall(sysSENDMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
|
return int(n), errnoErr(errno)
|
|
}
|