[ntp:questions] Close stats files

alkopedia at googlemail.com alkopedia at googlemail.com
Sun Jan 11 15:44:16 UTC 2009


On Jan 10, 8:23 pm, Unruh <unruh-s... at physics.ubc.ca> wrote:
> What version of ntp are you running? I have 4.2.4p4 and it creates a new
> set of statistics files every day, saving the old ones in the form
> /var/log/ntp/peerstats.20090101  /var/log/ntp/peerstats.20090106

As far as I can tell ntp creates peerstats and peerstats.20090111 at
the same time. Both filenames are just hard links to the same file on
the disk. If you remove peerstats.20090111 ntp will continue to write
it's stats to peerstats. At the beginning of a new day ntp recognizes
that peerstats.20090111 is not present and then renames peerstats to a
backup file called peerstats.1281C0. So far so good, but the problem
seems to be that ntp doesn't this exactly at 00:00 but at first file
access after 00:00. The cryptostats file only gets one or two entries
every day, so the first access to it could be much later than 00:40
when my script moves the stats files of the last day to a fileserver.

PS: I have to to this because my ntp servers run on 1 GB SD cards and
there is not much space for stats files ;-)

And here is my script:

#!/bin/sh
# this script syncs ntp stats to a nfs directory
# Author: Thorsten Muehlfelder <thenktor at gmx.de>
# Version: 0.7
#
################################################################################

# where are the ntpd stats?
STATS_DIR="/mnt/stats"
# which ntpd stats should be copied?
STATS="cryptostats loopstats peerstats rawstats sysstats"
# where is my config file?
CONFIG="/etc/nfs-sync.conf"

################################################################################

# If possible, log events in /var/log/messages:
if [ -f /var/run/syslogd.pid -a -x /usr/bin/logger ]; then
	LOGGER=/usr/bin/logger
else # output to stdout/stderr:
	LOGGER=/bin/cat
fi

# get the configuration information from /etc/nfs-sync.conf
if [ -r $CONFIG ]; then
	. $CONFIG
else
	echo "nfs-sync.sh: config file does not exist or is not readable" |
$LOGGER
	exit 1
fi

# cd into ntpd stats dir
if [ -d $STATS_DIR ]; then
	cd $STATS_DIR
else
	echo "nfs-sync.sh: stats dir does not exist" | $LOGGER
	exit 1
fi

# mount the nfs directory and check the exit status
mount -t nfs ${NFSSERVER}:${EXPORT} $IMPORT > /dev/null 2>&1
if [ $? = 0 ]; then
	for FILENAME in *.????????; do
		# set the part after . as FILEDATE
		FILEDATE=`echo "$filename" | gawk 'BEGIN {FS = "."} {print $2}'`
		# set DATE to the current date
		DATE=`date +%Y%m%d`
		# skip the statistic files for the current day
		if [ "$FILEDATE" = "$DATE" ]; then
			continue
		fi
		# move statistic files to the nfs directory
		mv $FILENAME $IMPORT > /dev/null 2>&1
	done
	# move gzipped statistic files to the nfs directory
	mv *.????????.gz $IMPORT > /dev/null 2>&1
	# copy the actual day statistic files to the nfs directory
	for STAT in ${STATS}; do
		cp -f $STAT $IMPORT > /dev/null 2>&1
	done

	# make sure to write everything to disk
	sync
	# umount the nfs directory
	umount $IMPORT
else
	echo "nfs-sync.sh: mount.nfs system call failed" | $LOGGER
	for FILENAME in *.????????; do
		# set the part after . as FILEDATE
		FILEDATE=`echo $filename | gawk 'BEGIN {FS = "."} {print $2}'`
		# set DATE to the current date
		DATE=`date +%Y%m%d`
		# skip the statistic files for the current day
		if [ "$FILEDATE" = "$DATE" ]; then
			continue
		fi
		# gzip the statistic files
		gzip $FILENAME > /dev/null 2>&1
	done
fi




More information about the questions mailing list