checker

package
v0.0.0-...-49e71f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package checker provides an easy way to talk to NTPD/Chronyd and get NTPCheckResult, which abstracts away Chrony/NTP control protocol implementation details and contains tons of information useful for NTP monitoring, like NTP server variables including offset, peers and their variables and statuses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialUnix

func DialUnix(address string) (*chronyConn, error)

DialUnix opens a unixgram connection with chrony

func NewNTPPeerStats

func NewNTPPeerStats(r *NTPCheckResult) (map[string]interface{}, error)

NewNTPPeerStats constructs NTPStats from NTPCheckResult

Types

type ChronyCheck

type ChronyCheck struct {
	Client chronyClient
}

ChronyCheck gathers NTP stats using chronyc/chronyd protocol client

func NewChronyCheck

func NewChronyCheck(conn io.ReadWriter) *ChronyCheck

NewChronyCheck is a constructor for ChronyCheck

func (*ChronyCheck) Run

func (n *ChronyCheck) Run() (*NTPCheckResult, error)

Run is the main method of ChronyCheck and it fetches all information to return NTPCheckResult. Essentially we request tracking info, num of peers, and then request source_data and ntp_data for each peer individually.

func (*ChronyCheck) ServerStats

func (n *ChronyCheck) ServerStats() (*ServerStats, error)

ServerStats return server stats

func (*ChronyCheck) Unix

func (n *ChronyCheck) Unix() bool

Unix returns true if connected via a unix socket

type NTPCheck

type NTPCheck struct {
	Client ntpClient
}

NTPCheck gathers NTP stats using UDP network client

func NewNTPCheck

func NewNTPCheck(conn io.ReadWriter) *NTPCheck

NewNTPCheck is a contructor for NTPCheck

func (*NTPCheck) ReadServerVariables

func (n *NTPCheck) ReadServerVariables() (*control.NTPControlMsg, error)

ReadServerVariables sends Read Variables packet asking for server vars and returns response packet

func (*NTPCheck) ReadStatus

func (n *NTPCheck) ReadStatus() (*control.NTPControlMsg, error)

ReadStatus sends Read Status packet and returns response packet

func (*NTPCheck) ReadVariables

func (n *NTPCheck) ReadVariables(associationID uint16) (*control.NTPControlMsg, error)

ReadVariables sends Read Variables packet for associationID. associationID set to 0 means 'read local system variables'

func (*NTPCheck) Run

func (n *NTPCheck) Run() (*NTPCheckResult, error)

Run is the main method of NTPCheck and it fetches all information to return NTPCheckResult. Essentially we request system status that contains list of peers, and then request variables for our server and each peer individually.

func (*NTPCheck) ServerStats

func (n *NTPCheck) ServerStats() (*ServerStats, error)

ServerStats return server stats

type NTPCheckResult

type NTPCheckResult struct {
	// parsed from SystemStatusWord
	LI          uint8
	LIDesc      string
	ClockSource string
	Correction  float64
	Event       string
	EventCount  uint8
	// data parsed from System Variables
	SysVars *SystemVariables
	// map of peers with data from PeerStatusWord and Peer Variables
	Peers map[uint16]*Peer
}

NTPCheckResult represents result of NTPCheck run polulated with information about server and it's peers.

func NewNTPCheckResult

func NewNTPCheckResult() *NTPCheckResult

NewNTPCheckResult returns new instance of NewNTPCheckResult

func RunCheck

func RunCheck(address string) (*NTPCheckResult, error)

RunCheck is a simple wrapper to connect to address and run NTPCheck.Run()

func RunNTPData

func RunNTPData(address string) (*NTPCheckResult, error)

RunNTPData is a simple wrapper to connect to address and run NTPCheck.Run() If using chrony it gathers extra info about the peers using the unix socket

func (*NTPCheckResult) FindGoodPeers

func (r *NTPCheckResult) FindGoodPeers() ([]*Peer, error)

FindGoodPeers returns list of peers suitable for syncronization

func (*NTPCheckResult) FindSysPeer

func (r *NTPCheckResult) FindSysPeer() (*Peer, error)

FindSysPeer returns sys.peer (main source of NTP information for server)

type NTPStats

type NTPStats struct {
	PeerDelay   float64 `json:"ntp.peer.delay"`    // sys.peer delay in ms
	PeerPoll    int     `json:"ntp.peer.poll"`     // sys.peer poll in seconds
	PeerJitter  float64 `json:"ntp.peer.jitter"`   // sys.peer jitter in ms
	PeerOffset  float64 `json:"ntp.peer.offset"`   // sys.peer offset in ms
	PeerStratum int     `json:"ntp.peer.stratum"`  // sys.peer stratum
	Frequency   float64 `json:"ntp.sys.frequency"` // clock frequency in PPM
	StatError   bool    `json:"ntp.stat.error"`    // error reported in Leap Status
	Correction  float64 `json:"ntp.correction"`    // current correction
}

NTPStats is what we want to report as stats for FBAgent to put into ODS

func NewNTPStats

func NewNTPStats(r *NTPCheckResult) (*NTPStats, error)

NewNTPStats constructs NTPStats from NTPCheckResult

type Peer

type Peer struct {
	// from PeerStatusWord
	Configured   bool
	AuthPossible bool
	Authentic    bool
	Reachable    bool
	Broadcast    bool
	Selection    uint8
	Condition    string
	// from variables
	SRCAdr     string
	SRCPort    int
	DSTAdr     string
	DSTPort    int
	Leap       int
	Stratum    int
	Precision  int
	RootDelay  float64
	RootDisp   float64
	RefID      string
	RefTime    string
	Reach      uint8
	Unreach    int
	HMode      int
	PMode      int
	HPoll      int
	PPoll      int
	Headway    int
	Flash      uint16
	Flashers   []string
	Offset     float64
	Delay      float64
	Dispersion float64
	Jitter     float64
	Xleave     float64
	Rec        string
	FiltDelay  string
	FiltOffset string
	FiltDisp   string
}

Peer contains parsed information from Peer Variables and peer status word, as described in http://doc.ntp.org/current-stable/ntpq.html

func NewPeerFromChrony

func NewPeerFromChrony(s *chrony.ReplySourceData, p *chrony.ReplyNTPData) (*Peer, error)

NewPeerFromChrony constructs Peer from two chrony packets

func NewPeerFromNTP

func NewPeerFromNTP(p *control.NTPControlMsg) (*Peer, error)

NewPeerFromNTP constructs Peer from NTPControlMsg packet

type Runner

type Runner interface {
	Run() (*NTPCheckResult, error)
	ServerStats() (*ServerStats, error)
}

Runner is something that can produce NTPCheckResult

type ServerStats

type ServerStats struct {
	PacketsReceived uint64 `json:"ntp.server.packets_received"`
	PacketsDropped  uint64 `json:"ntp.server.packets_dropped"`
}

ServerStats holds NTP server operational stats

func NewServerStatsFromChrony

func NewServerStatsFromChrony(s *chrony.ReplyServerStats) *ServerStats

NewServerStatsFromChrony constructs ServerStats from chrony ServerStats packet

func NewServerStatsFromChrony2

func NewServerStatsFromChrony2(s *chrony.ReplyServerStats2) *ServerStats

NewServerStatsFromChrony2 constructs ServerStats from chrony ServerStats2 packet

func NewServerStatsFromNTP

func NewServerStatsFromNTP(p *control.NTPControlMsg) (*ServerStats, error)

NewServerStatsFromNTP constructs ServerStats from NTPControlMsg packet

func RunServerStats

func RunServerStats(address string) (*ServerStats, error)

RunServerStats is a simple wrapper to connect to address and run NTPCheck.ServerStats()

type SystemVariables

type SystemVariables struct {
	Version   string
	Processor string
	System    string
	Leap      int
	Stratum   int
	Precision int
	RootDelay float64
	RootDisp  float64
	Peer      int
	TC        int
	MinTC     int
	Clock     string
	RefID     string
	RefTime   string
	Offset    float64
	SysJitter float64
	Frequency float64
	ClkWander float64
	ClkJitter float64
	Tai       int
}

SystemVariables holds System Variables extracted from k=v pairs, as described in http://doc.ntp.org/current-stable/ntpq.html

func NewSystemVariablesFromChrony

func NewSystemVariablesFromChrony(p *chrony.ReplyTracking) *SystemVariables

func NewSystemVariablesFromNTP

func NewSystemVariablesFromNTP(p *control.NTPControlMsg) (*SystemVariables, error)

NewSystemVariablesFromNTP constructs System from NTPControlMsg packet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL