Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvTime indicates that the local time has drifted too much // from the monitored NTP servers. ErrInvTime = errors.New("local time differs from observed") // ErrTooFewServers means that the number of trusted servers are // smaller then the selected num servers to query. ErrTooFewServers = errors.New("too few ntp servers configured") // ErrNoResponse indicates that there is an error to communicate with // the remote NTP servers ErrNoResponse = errors.New("no ntp response") // ErrThreshold means that there is no positive threshold value ErrThreshold = errors.New("no valid server threshold set") // ErrDeltaTooSmall is referring to when the max delta time is // smaller than the request timeout which can give unstable behaviour. ErrDeltaTooSmall = errors.New("delta is too small") )
Functions ¶
func RandomChoice ¶
RandomChoice returns a random selection of n items from the slice s. The choice is made using a PSEUDO RANDOM selection. If n is greater than len(s), an empty slice is returned.
Types ¶
type Config ¶
type Config struct { RequestAttempts int `yaml:"request_attempts"` RequestTimeout int `yaml:"request_timeout"` NumServers int `yaml:"num_servers"` MaxTimeDelta int `yaml:"max_time_delta"` ServerThreshold int `yaml:"server_threshold"` Period int `yaml:"period"` Servers []string `yaml:"servers"` }
Config holds the configuration for a NTPMonitor
func LoadConfig ¶
LoadConfig reads a yaml file from a provided path, instantiating a new Config object with the vales found. No sanity checking is made of the loaded values.
type LiveNTPClient ¶ added in v1.0.0
type LiveNTPClient struct{}
func (LiveNTPClient) QueryWithOptions ¶ added in v1.0.0
func (c LiveNTPClient) QueryWithOptions(srv string, opts ntp.QueryOptions) (*ntp.Response, error)
type NTPMonitor ¶
type NTPMonitor struct {
// contains filtered or unexported fields
}
NTPMonitor compares the local time with a set of trusted NTP servers.
func New ¶
func New(configFile string) (*NTPMonitor, error)
New creates a NTPMonitor, reading the configuration from the provided path.
func NewFromConfig ¶
func NewFromConfig(cfg *Config) (*NTPMonitor, error)
NewFromConfig creates a NTPMonitor from an instantiated configuration.
func NewFromConfigWithClient ¶ added in v1.0.0
func NewFromConfigWithClient(cfg *Config, client NTPClient) (*NTPMonitor, error)
func (*NTPMonitor) Start ¶
func (n *NTPMonitor) Start()
Start the periodic monitor. Once started, it runs until Stop() is called,