NAME
Monitoring::Sneck::Checks::time_sync - checks the local time daemon is synchronised, chrony, ntpd, or timesyncd
VERSION
Version 0.0.1
SYNOPSIS
time_sync|perl:time_sync
time_sync_tight|perl:time_sync -w 0.01 -c 0.1 --since-warning 7200
time_sync_ntpd|perl:time_sync -d ntpd
DESCRIPTION
Asks the local time daemon if it is synchronised, how far off it is, and when it last updated the clock. Unlike Monitoring::Sneck::Checks::ntp, which asks a NTP server, this is about the daemon keeping this host's clock.
- chrony :: Through chronyc -n -c tracking.
- ntpd :: Through ntpq -n -c rv, for the reference ntpd and NTPsec.
- timesyncd :: Through timedatectl show, which only says if the kernel's clock is synchronised, not the offset.
Without --daemon, the first of chronyc, ntpq, and timedatectl that is there is used.
- CRITICAL :: Not synchronised. The daemon not answering. The offset or time since the last update over their critical.
- WARNING :: Synchronised only to the local clock, as with chrony's local stratum or ntpd's LOCAL(0). The offset or time since the last update over their warning.
- UNKNOWN :: None of the tools being there.
OPTIONS
- -d, --daemon :: chrony, ntpd, or timesyncd, instead of looking for them.
- -w, --warning :: Range for the offset, in seconds, either way. Default :: 0.1
- -c, --critical :: Range for the offset, in seconds, either way. Default :: 1
- --since-warning :: Range for the seconds since the last update.
- --since-critical :: Range for the seconds since the last update.
METHODS
check
Does the check.
chrony_state
Asks chrony through chronyc -n -c tracking.
- chronyc :: The path to chronyc.
Returns a hash ref of answering, 1 or 0, and if not, says, what went wrong, else synced, 1 or 0, local, 1 if synchronised to the local clock, reference, the server's address, stratum, offset, in seconds, and updated, the epoch of the last update, or undef.
my $state = $check->chrony_state('/usr/bin/chronyc');
# { answering => 1, synced => 1, local => 0, reference => '192.0.2.123', stratum => 2,
# offset => -0.000156213, updated => 1794200902.841540871 }
ntpd_state
Asks ntpd through ntpq -n -c rv. Returns the same as "chrony_state", the offset turned from milliseconds to seconds.
- ntpq :: The path to ntpq.
my $state = $check->ntpd_state('/usr/bin/ntpq');
timesyncd_state
Asks systemd through timedatectl show. Returns the same as "chrony_state", but with only answering, says, and synced, plus ntp_off, 1 if NTP is turned off.
- timedatectl :: The path to timedatectl.
my $state = $check->timesyncd_state('/usr/bin/timedatectl');
# { answering => 1, synced => 1, ntp_off => 0 }