Linux
banshee/linux-collection/linux/snmp/
clock
Offset of a Linux host's clock from a time server, read by SNMP and compared by NTP.
by banshee1 installation2 versions
v2Latest
Published on October 28, 2026. One naming convention across collections; documentation completed.
// The offset of a Linux host's clock from a time server: the system time, hrSystemDate
// (HOST-RESOURCES-MIB), read by SNMP, compared with the time of the server named by "Time server"
// (pool.ntp.org when unset). Positive, the clock is ahead; negative, it is behind.
// The server's time is brought back to the middle of the SNMP read: neither the SNMP round trip, nor the
// time between the two reads, nor the error of the poller's clock counts in the offset.
// hrSystemDate is only precise to a tenth of a second. An agent that serves it without its offset from
// UTC does not say which instant it is: the collector then stops rather than guess.
need('protocol:snmp');
need('protocol:ntp');
output('offset', 'number', array('label' => 'Offset from the time server', 'unit' => 's'));
output('drift', 'number', array('label' => 'Offset, without its sign', 'unit' => 's'));
watch.above('clock-drift', 'Clock off', 'drift', array('warning' => 5, 'critical' => 60));
$asked = time.now();
$date = snmp.date('1.3.6.1.2.1.25.1.2.0');
$answered = time.now();
$server = ntp.time(errors=$err);
$now = time.now();
if ($err['code'] != '') {
fail('unreachable', 'Time server unreachable', $err['text']);
}
// The server's time in the middle of the SNMP read: its time, minus the time elapsed since, measured by
// the poller's clock.
$reference = $server - ($now - ($asked + $answered) / 2);
$offset = $date - $reference;
$drift = $offset;
if ($drift < 0) {
$drift = -$drift;
}
value('offset', number.round($offset, 1));
value('drift', number.round($drift, 1));