• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# Monitor NTP drift
4
5# Copyright (C) 2003-2006 IBM
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20# 02111-1307, USA.
21
22if [ -z "$NTP_SERVER" -o "$NTP_SERVER" == "0" ]; then
23	echo "NTP server is not configured."
24	exit 255
25fi
26
27# NTP server is set in libpounder.sh
28# Check NTP server every 15 seconds.  Evil, I know.
29FREQ=15
30# Threshold at which we warn about excessive drift
31DWT=100
32# Threshold at which we fail the test because of drift
33DFT=500
34
35LOGFILE=/proc/$$/fd/1
36
37# Why do we need this?  Output is already being logged!
38cp -f $LOGFILE $POUNDER_TMPDIR/ntpdrift-$$
39
40# Do we have a python interpreter?
41PYTHON=`which python`
42if [ -n "$PYTHON" -a -x "$PYTHON" ]; then
43		$POUNDER_HOME/timed_loop 900 "$POUNDER_SRCDIR/time_tests/drift-test.py" $NTP_SERVER $FREQ
44else
45	echo "There is no python interpreter installed.  Aborting."
46	exit -1
47fi
48
49# Did drift-test.py fail to run properly?
50if [ $? -ne 0 ]; then
51	exit 1
52fi
53
54# Did we see any failures in actual drift test?
55ERRORS=0
56cp -f $LOGFILE $POUNDER_TMPDIR/ntpdrift2-$$
57diff -u $POUNDER_TMPDIR/ntpdrift-$$ $LOGFILE | while read a b c d e field drift garbage; do
58	if [ "$field" != "drift:" ]; then
59		continue;
60	fi
61	drift=`echo $drift | awk -F "." '{print $1}'`
62	if [ $drift -gt $DFT -o $drift -lt -$DFT ]; then
63		echo ERROR: drift exceeded $DFT ppm: $a $b \
64		$c $d $e $field $drift $garbage
65		ERRORS=$((ERRORS + 1))
66	elif [ $drift -gt $DWT -o $drift -lt -$DWT ]; then
67		echo WARNING: drift exceeded $DWT ppm: $a $b \
68		$c $d $e $field $drift $garbage
69	fi
70done
71
72exit $ERRORS
73