[ntp:questions] Close stats files

Unruh unruh-spam at physics.ubc.ca
Sun Jan 11 17:52:05 UTC 2009


"alkopedia at googlemail.com" <alkopedia at googlemail.com> writes:

>On Jan 10, 8:23=A0pm, 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 =A0/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.

Yes, but that means that the cryptostats file contains almost nothing. It
does not matter if it sticks around an extra day. You script will clean it
up tomorrow anyway.

And alter your script so that it does not try to write any file on today or
earlier. Or test to see if peerstats and peerstats.20090201 are the same
file (same inode with ls -li)

For example (not tested)


for i in peerstats cryptostats 
do
for j in $i.????????
do
if ["`ls -li $i|awk '{print $1}'`" != "`ls -li $j|awk '{print $1}'`" ]
;then
  Move and compress the file
done
done



>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=3D"/mnt/stats"
># which ntpd stats should be copied?
>STATS=3D"cryptostats loopstats peerstats rawstats sysstats"
># where is my config file?
>CONFIG=3D"/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=3D/usr/bin/logger
>else # output to stdout/stderr:
>	LOGGER=3D/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 [ $? =3D 0 ]; then
>	for FILENAME in *.????????; do
>		# set the part after . as FILEDATE
>		FILEDATE=3D`echo "$filename" | gawk 'BEGIN {FS =3D "."} {print $2}'`
>		# set DATE to the current date
>		DATE=3D`date +%Y%m%d`
>		# skip the statistic files for the current day
>		if [ "$FILEDATE" =3D "$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=3D`echo $filename | gawk 'BEGIN {FS =3D "."} {print $2}'`
>		# set DATE to the current date
>		DATE=3D`date +%Y%m%d`
>		# skip the statistic files for the current day
>		if [ "$FILEDATE" =3D "$DATE" ]; then
>			continue
>		fi
>		# gzip the statistic files
>		gzip $FILENAME > /dev/null 2>&1
>	done
>fi




More information about the questions mailing list