Programmatically detect Chrony time sync events
438 million second offset is 13 years. If this system has a real time clock, check it is functional.
Decide if, on system boot, you wish to wait for NTP to be synchronized before starting your application. On RHEL, your unit can have a dependency on chrony-wait.service
. Its implementation makes use of chronyc waitsync
Typical NTP metrics are the number of reachable peers, and the offset of this system. See Paul Gear's ntpmon for an implementation that parses the output of chronyc
or ntpq
binaries.
Kernel time discipline is a frequent and gradual thing, chrony will be calling ntp_adjtime()
a lot.
Perhaps you wish to detect large steps like this one chrony logged? chrony has an email callback, the mailonchange
directive. It calls sendmail
, so you can do something with that mail, or put in place some other script.
And there are ways to detect these from a C program. Call ntp_adjtime()
yourself and detect a return of TIME_ERROR
to be a problem. Or on Linux, set a long running timer with timerfd_settime
and provide the TFD_TIMER_CANCEL_ON_SET
flag. This has the neat trick of being canceled if the clock is stepped or otherwise has a discontinuous change.