Ntpstat exit code changes with time

hey everyone!
I’m here because i’m at my wit’s end, I can’t solve this issue. thanks in advanced for the help!
I have a script running every 5 mins, the script essentially calls ntpstat. There is a program monitoring the script (sensu), the monitoring provides a history of the check results, the problem is, the result seems to change quite often, every few minutes it seems to switch between 0 and 1, I’ve seen it switch to 2 before, but very rarely.

So far I’ve tried:
service ntpd stop > ntpdate [timeserver] > service ntpd start
double checking ntp.conf has the correct server (I only have 1 server as this is a test environment, could that be the cause of the issue?)
I’ve ensured time of all the servers where this is an issue is correct to within 2 seconds.
googling, seems no one else has had this issue :frowning:

Thanks for any assistance you can offer.

Very likely having only one server is the cause of the issue. Put at least three working servers into the ntpd configuration. Do not restart the ntpd service.

1 Like

What does the output of ‘ntpq -pn’ produce? Is it actually locking to the one source or does it flag it as ignore? Like NTPman said, you really need a minimum of 3 valid servers…

IIRC, ntpstat simply parses the output of ‘ntpq -c rv’ and does a little math for the “time correct to within” number… You can find the source for ntpstat in a current ntpd src rpm.

ntpstat exits with a status of 0 if the clock is synchronised, 1 if the clock is not synchronised, or 2 if the status could not be determined, e.g. when the daemon is not running.

Thanks for the replies, I’ve check ntpq -pn before, indeed it’s locking onto the 1 source (indicated by a * right?). There are more servers being assigned, hopefully this solves the problem.
Thanks again for the reply :slight_smile:

1 Like