#!/bin/ksh # # $Source: /usr/local/scripts/ntp/RCS/do-ntp-rrdstats,v $ # $Revision: 1.4 $ $Date: 2010/04/29 15:24:29 $ # $Author: root $ # # $Log: do-ntp-rrdstats,v $ # Revision 1.4 2010/04/29 15:24:29 root # fixed hex conversions # # Revision 1.3 2010/01/29 20:01:07 root # version3 ckpnt # # Revision 1.2 2010/01/28 20:58:07 root # checkpoint for version 3 update # # Revision 1.22 2010/01/18 19:42:32 root # added version 3 variables and -u switch to update (create new) dataset # fixed JDATE/TOD bug when client is not responding # # Revision 1.21 2010/01/13 02:39:14 root # added logfile tag for different operation modes. # # Revision 1.20 2010/01/11 18:18:27 root # seperated ntp mode6 stats from file downloads.... # # Revision 1.20 2010/01/11 18:18:27 root # seperated ntp mode6 stats from file downloads.... # # Revision 1.19 2010/01/11 18:15:46 root # checkpoint.... # # Revision 1.18 2008/04/22 20:04:29 root # fixed local tmp names to /tmp # # Revision 1.17 2008/04/22 20:02:41 root # fixed IO redirection for logfile and initial config search # added error checking for SCP of ntp stats files # # Revision 1.16 2008/04/19 04:49:19 root # fixed error output for _CAT # # Revision 1.15 2008/04/16 22:00:23 root # added directory creation for 1st run # # Revision 1.14 2008/04/16 03:22:27 root # added log level 2 - no truncation # # Revision 1.13 2008/04/11 08:30:00 root # added handler to copy the ntp statistics files and compute the # last TOD stamp for future GNUplot use # # Revision 1.12 2008/03/20 02:41:34 root # moved logfile to different directory # # Revision 1.11 2008/03/19 23:23:37 root # added fixed revision print... don't forget to update this thing... # # Revision 1.10 2008/03/19 23:21:42 root # futzing with rcs keywords in print statements # # Revision 1.9 2008/03/19 23:16:30 root # added cmd and configuration files # fixed debug mode for pre-conf file read # added norun flag # added date preamble to logfile # # Revision 1.8 2008/03/19 06:17:47 root # added more version info in debug output # # Revision 1.7 2008/03/19 06:08:04 root # added RRDDSVER=current in create clause (BUG!) # # Revision 1.6 2008/03/19 05:54:39 root # fixed ntpq call to HOST (not SYSMANE) # # Revision 1.5 2008/03/19 05:40:10 root # added io redirection for debug and logfile # added cmdline args for debug/logginf and new version 2 rrd data sets # added rrd data set version checking - don't sote new values in old version # # Revision 1.4 2008/03/18 03:27:22 root # added prec,delay,disp,stratum,peer values # # Revision 1.3 2008/03/17 23:13:08 root # more motech merges - moved to ksh # # # Revision History: MGO 18-Mar-2008 Added command line args for # debug level # MGO 11-Jan-2010 Added -n flag to seperate ntp # file gets from mode6 queries # MGO 17-Jan-2010 Added P3 data: assID, status, # poll, tai, state, leap # MGO 18-Jan-2010 Fixed JDATE/TOD calls for non- # responding clients # MGO 29-Nov-2010 Patch for change in 'ntpq rv' # output. (4.2.6p2) # # grab ntp stats using ntpq for rrdtool # 28 mar 2006 gnu@wraith.sf.ca.us # public domain # grrr.... # the peer value cuased me a lot of grief, until I noticed that # there is an event comment 'event_peer' that was getting pulled # out of the file via the 'grep peer'... changed to # 'grep peer=' and things now work.... What was happening is that # the grep put a blank field THEN the perr ID, so rrdupdate saw a blank # field and crashed.... # hardcoded config file paths - typically in same dir as exec (myself) execFile="cmds.inc" # command locations confFile="ntpstats.conf" # system configurations confDir="" # debug level (normally 0, but could be 4-6 for extreme output) # NOTE: normally command output > /dev/null, unless debug>=5 debug=5 # operational stuff # if you run from cron - you MUST set this to a non zero value! # or you'll be seeing email every 5 minutes!) # (Note: -1=>/dev/null, 0=>stdout, 1=>trucateLog, 2=>append to log) log=1 # send to log new=0 # do RRD DS version upgrade (add new variables) norun=0 # set for testing - does NO collection doall=0 # set.... do BOTH stats and mode6 getstats=0 # get ntpstat files - or do mode 6 queries? ntpmode6=1 # Default is to do mode 6 query #deftimeout=5000 # Default timeout for ntpq (mSec) #ntpqtimeout=${deftimeout} # ntpq net timeout mSec (x2) #ntpqvars="-c rv" # Readvars of host #ntpqparams="" # NTPQ Query string ################################################################################ ################################################################################ ## ## NO USER SERVICABLE PART BELOW ## # # THE help function.... # usage() { print "usage: ${myname} [-alnru] [-d] [-t]" print " -a collect ALL data" print " -l enable logging (at level 1)" print " -n collect NTP mode 6 data (via 'ntpq -c rv HOST')" print " -r no run" print " -u update rrd to latest version" print " -d<1-5> sets debug level (w/o argument disables debug)" print " -t sets NTPQ query timeout in mSec" exit 0 } myname=${0##*/} mydir=${0%/*} # dirname [[ ${mydir} == ${myname} ]] && mydir="." # dirname puts . for no dir mypid=$$ myargs="$0 $1 $2 $3 $4 $5 $6 $7 ..." # capture SOME args... #------------------------------------------------------------------------------- # get options and set params... OPTIONS="ahlnrud:t:" while getopts ${OPTIONS} FLAGS do case ${FLAGS} in 'a') doall=1 ;; 'h') usage ;; 'l') log=1 ;; 'd') debug=${OPTARG} ;; # 't') ntpqtimeout=${OPTARG} # [[ ${ntpqtimeout} -lt 250 ]] && ntpqtimeout=${deftimeout} # ;; 'n') getstats=1 ntpmode6=0 ;; 'r') norun=1 ;; 'u') new=1 ;; '?') if [[ "X${OPTARG}" == "X" ]] ; then print "${myname} -d needs a value 0-5" exit 2 fi ;; '*') ;; esac done shfcnt=$(( OPTIND - 1 )) shift ${shfcnt} if [[ ${doall} -ne 0 ]] ; then getstats=1 ntpmode6=1 fi #------------------------------------------------------------------------------- # get the configuration stuff # temp stdio redirect on debug level (=0 > /dev/null) - no logging # availible, coz we've NOT yet read the configurations. if [[ ${debug} -ge 2 && ${log} -eq 0 ]] ; then exec 3>&1 else exec 3>/dev/null fi if [[ "${mydir}" != "." ]] ; then if [[ ! -f /${mydir}/${myname} ]] ; then execpath=${PWD} # shell pwd execpath="${execpath}/${mydir}" [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: searching ${execpath} (for ${myname})" >&3 if [[ -f "${execpath}/${myname}" ]] ; then confDir=${execpath} [[ ${debug} -ge 3 ]] && print \ "${myname} DBG: Set confDir to ${execPath} (via cmdline/cwd)" >&3 else [[ ${debug} -ge 0 ]] && print \ "${myname} ERR: Something is pathalogic - can't find myself" exit 2 fi else execPath=${mydir} [[ ${debug} -ge 2 ]] && print \ "${myname} DBG: Set execPath to ${execPath} (via cmdline)" >&3 fi else [[ ${debug} -ge 2 ]] && print "Searching for exec dir" >&3 if [[ -f ${myname} ]] ; then execPath=${PWD} # shell pwd [[ ${debug} -ge 2 ]] && print \ "Set execPath to current dir ${execPath} (via pwd)" >&3 else execpath=$( which ${myname} ) #${_ECHO} ${execpath} | ${_GREP} "no ${myname} in" if [[ ${execPath%*no ${myname} in*} == ${execPath} ]] ; then # which found something in the path [[ ${execPath} == ${execPath%%/*} ]] && execPath="." execPath=${execPath%/*} # dirname [[ ${debug} -ge 2 ]] && print \ "${myname} DBG: Setting execPath from search path ${execPath}" >&3 else [[ ${debug} -ge 0 ]] && print \ "${myname} ERR: Unable to determine execPath - exiting" exit 2 fi fi fi # now we have execPath - look for includes. They be here or ../data if [[ ! -f ${execPath}/${execFile} ]] ; then if [[ ! -f ${confDir}/${execFile} ]] ; then [[ ${debug} -ge 0 ]] && print \ "${myname} ERR: Unable to find ${execFile} - exiting" >&3 exit 2 else [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: Reading ${execFile} from ../confDir" >&3 . ${confDir}/${execFile} fi else [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: Reading ${execFile} from execPath" >&3 . ${execPath}/${execFile} fi # now look for configuration file - they be in the confDir if [[ ! -f ${execPath}/${confFile} ]] ; then if [[ ! -f ${confDir}/${confFile} ]] ; then [[ ${debug} -ge 0 ]] && print \ "${myname} ERR: Unable to find ${confFile} - exiting" exit 2 else [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: Reading ${confFile} from ../confDir" >&3 . ${confDir}/${confFile} fi else [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: Reading ${confFile} from execPath" >&3 . ${execPath}/${confFile} fi # make some operational dirs - just in case [[ ! -d ${DBDIR} ]] && ${_MKDIR} -p ${DBDIR} [[ ! -d ${STATDIR} ]] && ${_MKDIR} -p ${STATDIR} # setup loging to file (or stdout) depending on -l # NOTE: all output uses FD4.... we just set FD4 as needed # NOTE on file truncation: the exec redirection truncates the file (and no # amount of gt magic stops it), BUT, using 'set -C' before the exec # does prevent file truncation. (the wonders of ksh...) _LOGEXT="_m6" [[ ${ntpmode6} -ne 1 ]] && _LOGEXT="_stats" if [[ ${log} -ge 1 ]] ; then LOGFILE=${DATADIR}/${myname}${_LOGEXT}.log [[ ! -f ${LOGFILE} ]] && ${_TOUCH} ${LOGFILE} >/dev/null 2>&1 if [[ ${log} -ge 2 ]] ; then exec 4>>${LOGFILE} else exec 4>${LOGFILE} fi else if [[ ${log} -lt 0 ]] ; then exec 4>/dev/null else exec 4>&1 fi fi # setup stdio redirect on debug level (<5 > /dev/null) # NOTE: all command output uses FD5... set according to need if [[ ${debug} -ge 5 ]] ; then exec 5>&4 else exec 5>/dev/null fi if [[ ${debug} -ge 1 && ${log} -ge 1 ]] ; then print "" >&4 print \ "=====================================================================" >&4 ${_DATE} '+%D %T' >&4 fi [[ ${debug} -ge 2 ]] && print "From command line: ${myname} ${mydir}" >&4 [[ ${debug} -ge 3 ]] && print "\targs: ${myargs} (shift ${shfcnt})" >&4 # # Start of processing # if [[ ${debug} -ge 1 ]] ; then print "${myname} DBG: Revision: 1.20" >&4 print "${myname} DBG: RRDSCUR version = ${RRDDSCUR}" >&4 fi [[ ${debug} -ge 3 ]] && print "${myname} DBG: DBDIR = ${DBDIR}" >&4 case "$1" in "") print "Missing system name."; exit 1 esac HOST=$1 IPADDR=${HOST} [[ "X$2" != "X" && "$2" != "-" ]] && IPADDR=$2 RRDDSVER=1 TNAME=${TMPDIR}/ntp-rrdstats.${HOST} TDIR=${TMPDIR}/${HOST} [[ ${norun} -eq 1 ]] && exit 0 #if [[ ! -f ${SystemStats} ]] ; then # ${_RRDTOOL} create ${SystemStats} \ # DS:user:ABSOLUTE:1200:0:65536 \ # DS:system:ABSOLUTE:1200:0:U \ # DS:readerrs:GAUGE:1200:0:U \ # DS:rrderr:GAUGE:1200:0:U \ # DS:rrdwd:GAUGE:1200:0:U \ # DS:gnuperr:GAUGE:1200:0:U \ # DS:gnupwd:GAUGE:1200:0:U \ # RRA:AVERAGE:0.5:1:312 \ # >&5 2>&5 #fi # zero some runtime stat counters sysuser=$(( 1 << DO_NTP_RRDSTATS_M6 )) sysid=0 sysrerr=0 rrderr=0 rrdwdto=0 gnuerr=0 gnuwdto=0 # set NTPQ query params #if [[ ${ntpqtimeout} -ne ${deftimeout} ]] ; then # : #else # ntpqparams=${ntpqvars} # Must get readvars... #fi if [[ ${ntpmode6} -eq 1 ]] ; then ${_NTPQ} -4 -c rv ${IPADDR} | \ ${_NAWK} 'BEGIN{ RS=","}{ print }' > ${TNAME} 2>&5 NOFFSET=`${_GREP} offset ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` NFREQ=`${_GREP} frequency ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` NJITTER=`${_GREP} jitter ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` NNOISE=`${_GREP} noise ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` NSTABILITY=`${_GREP} stability ${TNAME} | \ ${_NAWK} 'BEGIN{FS="="}{print $2}'` # PHASE2 values added 15-Mar-2008 (not yet in RRD sets) TPREC=`${_GREP} precision= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TDELAY=`${_GREP} rootdelay= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TDISP=`${_GREP} rootdispersion= ${TNAME} | \ ${_NAWK} 'BEGIN{FS="="}{print $2}'` TSTRAT=`${_GREP} stratum= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TPEER=`${_GREP} peer= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` # PHASE3 values added 12-Jan-2010 (not yet in RRD sets) # the assID and status values are embedded into this string: # assID=0 status=06f4 leap_none typeset -i10 TASSOCIDdec # association (remove spaces) typeset -i10 TSTATdec # status flags conversion typeset -i16 TSTAThex typeset -i10 TREFIDdec # refid conversion typeset -i16 TREFIDhex typeset -i10 TRTIMEWdec # Ref time whole number typeset -i10 TRTIMEFdec # Ref time Decimal fraction typeset -i16 TRTIMEWhex typeset -i16 TRTIMEFhex typeset -i10 TCTIMEWdec # clock time whole number typeset -i10 TCTIMEFdec # clock time Decimal fraction typeset -i16 TCTIMEWhex typeset -i16 TCTIMEFhex typeset TIMEStr # workspace TASSOCID=`${_GREP} assID= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` # patch for ntpq 4.2.6p2 change in field name was assID is associd # MGO 29-Nov-2010 [[ $? -ne 0 ]] && \ TASSOCID=`${_GREP} associd= ${TNAME} | \ ${_NAWK} 'BEGIN{FS="="}{print $2}'` TASSOCID=${TASSOCID%%status*} TSTAT=`${_GREP} status= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $3}'` TSTAT=${TSTAT%% *} # was leap_none (but sync_alarm...) TPOLL=`${_GREP} poll= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TTAI=`${_GREP} tai= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TSTATE=`${_GREP} state= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TLEAP=`${_GREP} leap= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TREFID=`${_GREP} refid= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` #TREFID=$(( (${TREFID%%.*.*.*} << 23) + (${TREFID##*.*.*.}) )) TRTIME=`${_GREP} reftime= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TRTIME=${TRTIME%% *} TCTIME=`${_GREP} clock= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TCTIME=${TCTIME%% *} # fix values for bad lookups [[ "X${NOFFSET}" == "X" ]] && NOFFSET=0 [[ "X${NFREQ}" == "X" ]] && NFREQ=0 [[ "X${NJITTER}" == "X" ]] && NJITTER=0 [[ "X${NNOISE}" == "X" ]] && NNOISE=0 [[ "X${NSTABILITY}" == "X" ]] && NSTABILITY=0 [[ "X${TPREC}" == "X" ]] && TPREC=U [[ "X${TDELAY}" == "X" ]] && TDELAY=U [[ "X${TDISP}" == "X" ]] && TDISP=U [[ "X${TSTRAT}" == "X" ]] && TSTRAT=U [[ "X${TPEER}" == "X" ]] && TPEER=U if [[ "X${TASSOCID}" == "X" ]] ; then TASSOCIDdec=0 else TASSOCIDdec=${TASSOCID} fi if [[ "X${TSTAT}" == "X" ]] ; then TSTATdec=0 else TSTAThex="16#${TSTAT#0x}" TSTATdec=${TSTAThex} fi [[ "X${TPOLL}" == "X" ]] && TPOLL=0 [[ "X${TTAI}" == "X" ]] && TTAI=0 [[ "X${TSTATE}" == "X" ]] && TSTATE=0 [[ "X${TLEAP}" == "X" ]] && TLEAP=0 #[[ "X${TREFID}" == "X" ]] && TREFID=0 if [[ "X${TRTIME}" == "X" ]] ; then TRTIMEWdec=0 TRTIMEFdec=0 else TIMEStr="${TRTIME%.*}" TRTIMEWhex="16#${TIMEStr#0x}" TIMEStr="${TRTIME#*.}" TRTIMEFhex="16#${TIMEStr#0x}" TRTIMEWdec=${TRTIMEWhex} TRTIMEFdec=${TRTIMEFhex} #TRTIMEWdec=0 #TRTIMEFdec=0 fi if [[ "X${TCTIME}" == "X" ]] ; then TCTIMEWdec=0 TCTIMEFdec=0 else TIMEStr="${TCTIME%.*}" TCTIMEWhex="16#${TIMEStr#0x}" TIMEStr="${TCTIME#*.}" TCTIMEFhex="16#${TIMEStr#0x}" TCTIMEWdec=${TCTIMEWhex} TCTIMEFdec=${TCTIMEFhex} #TCTIMEWdec=0 #TCTIMEFdec=0 fi # PHASE4 values added 29-Nov-2010 (not yet in RRD sets) # Capture crypto and flag values. typeset -i10 TFLAGSdec # flag values (store decimal) typeset -i16 TFLAGShex # flag values typeset -i10 TUPDATEdec # update time typeset -i10 TEXPIREdec # cert expiry time TSIGNATURE=`${_GREP} signature= ${TNAME} | \ ${_NAWK} 'BEGIN{FS="="}{print $2}'` TFLAGS=`${_GREP} flags= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TUPDATE=`${_GREP} update= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TCERT=`${_GREP} cert= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` TEXPIRE=`${_GREP} expire= ${TNAME} | ${_NAWK} 'BEGIN{FS="="}{print $2}'` [[ "X${TSIGNATURE} == "X" ]] && TSIGNATURE="NONE" [[ "X${TCERT} == "X" ]] && TCERT="NONE" if [[ "X${TFLAGS}" == "X" ]] ;then TFLAGShex=0 TFLAGSdec=0 else TFLAGShex="16#${TFLAGS#0x}" TFLAGSdec=${TFLAGShex} fi if [[ "X${TUPDATE}" == "X" ]] ; then TUPDATEdec=0 else TUPDATEdec=${TUPDATE} fi if [[ "X${TEXPIRE}" == "X" ]] ; then TEXPIREdec=0 else TEXPIREdec=${TEXPIRE} fi if [[ ${debug} -ge 2 ]] ; then print "${myname} DBG: V1=>${NOFFSET} ${NJITTER} ${NNOISE} ${NSTABILITY} ${NFREQ}" >&4 print "${myname} DBG: V2=>${TPREC} ${TDELAY} ${TDISP} ${TSTRAT} ${TPEER}" >&4 print "${myname} DBG: V3=>${TASSOCIDdec}(${TASSOCID}) ${TSTATdec}(${TSTAThex}) ${TPOLL} ${TTAI} ${TSTATE} ${TLEAP} ${TREFID} ${TRTIMEWdec}(${TRTIMEWhex})/[${TRTIME}] ${TCTIMEWdec}(${TCTIMEWhex})/[${TCTIME}]" >&4 print "${myname} DBG: V4=>${TSIGNATURE} ${TFLAGSdec}(${TFLAGShex}) ${TUPDATEdec} ${TEXPIREdec}" >&4 fi # determine RRD DS version (phase1/2) and possibly do upgrade if [[ -f ${DBDIR}/${HOST}.rrd ]] ; then ${_RRDTOOL} info ${DBDIR}/${HOST}.rrd | \ ${_GREP} "precision" >&5 2>&5 err=$? [[ $err -eq 0 ]] && RRDDSVER=2 ${_RRDTOOL} info ${DBDIR}/${HOST}.rrd | \ ${_GREP} "associd" >&5 2>&5 err=$? [[ $err -eq 0 ]] && RRDDSVER=3 ${_RRDTOOL} info ${DBDIR}/${HOST}.rrd | \ ${_GREP} "flags" >&5 2>&5 err=$? [[ $err -eq 0 ]] && RRDDSVER=4 [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: RRD DS Version = ${RRDDSVER}" >&4 if [[ ${RRDDSVER} -lt ${RRDDSCUR} && ${new} -eq 1 ]]; then ${_MV} ${DBDIR}/${HOST}.rrd \ ${DBDIR}/${HOST}.ph${RRDDSVER}.rrd >&5 2>&5 fi fi if [[ ! -f ${DBDIR}/${HOST}.rrd ]] ; then RRDDSVER=${RRDDSCUR} # always create current version dataset [[ ${debug} -ge 3 ]] && print \ "Creating ${HOST} RRD V${RRDDSVER}" >&4 # create database with the attribute names of: # offset,jitter,noise,stability,frequency # Added following 18-Mar-2008: # precision,rootdelay,rootdispersion # stratum,peer (in that order!) # Added the 'rest' of the ntpq -c rv vars.... 20-Jan-2010 mgo # Added crypto values... 29-Nov-2010 MGO ${_RRDTOOL} create ${DBDIR}/${HOST}.rrd \ ${RRDVARS[*]} \ RRA:AVERAGE:0.5:1:312 \ RRA:AVERAGE:0.5:12:2304 \ >&5 2>&5 fi [[ ${debug} -ge 1 ]] && print \ "${myname} DBG: Updating ${HOST} RRD V${RRDDSVER}" >&4 # update new row (use exact order as when created!) RRDDSN="N:${NOFFSET}:${NJITTER}:${NNOISE}:${NSTABILITY}:${NFREQ}" [[ ${RRDDSVER} -ge 2 ]] && \ RRDDSN="${RRDDSN}:${TPREC}:${TDELAY}:${TDISP}:${TSTRAT}:${TPEER}" [[ ${RRDDSVER} -ge 3 ]] && \ RRDDSN="${RRDDSN}:${TASSOCIDdec}:${TSTATdec}:${TPOLL}:${TTAI}:${TSTATE}:${TLEAP}:0:${TRTIMEWdec}:${TCTIMEWdec}" [[ ${RRDDSVER} -ge 4 ]] && \ RRDDSN="${RRDDSN}:${TFLAGSdec}:${TUPDATEdec}:${TEXPIREdec}" [[ ${debug} -ge 3 ]] && print \ "${myname} DBG: rrd update V${RRDDSVER}=> ${RRDDSN}" >&4 ${_RRDTOOL} update \ ${DBDIR}/${HOST}.rrd \ ${RRDDSN} \ >&5 2>&5 ${_RM} ${TNAME} >&5 2>&5 fi # # retrieve various NTP stat files - defined in ntpstats.conf # NOTE: we copy ALL of the specified stat files, loopstats.*, because # this allows us to combined them into 1 continuous stream # without worrying about month rollovers (and such).... The # downside is that the host MUST trim the files to keep 1 week # at most - or we end up copying a LOT of useless data! # This section is run under a seperate process at a MUCH lower rate! # because the scp process may take MINUTES.... which means that the mode6 # query data will get fudged up.... # if [[ ${getstats} -eq 1 ]] ; then #[[ ! -d ${STATDIR}/${HOST} ]] && ${_MKDIR} ${STATDIR}/${HOST} >&5 2>&5 [[ ! -d ${TDIR} ]] && ${_MKDIR} -p ${TDIR} >&5 2>&5 ${_TOUCH} ${STATDIR}/${HOST}.ntpfiles >&5 2>&5 # lockfile.... fCount=${#NTPSFILE[*]} fCnt=0 if [[ ${fCount} -gt 0 ]] ; then while (( fCnt < fCount )) # option base 0 do fFile=${NTPSFILE[$fCnt]} # loopstats => loopTOD [[ "${fFile}" != "${fFile%%stats}" ]] && oFile=${fFile%%stats}TOD [[ ${debug} -ge 3 ]] && print \ "${myname} DBG: retrieve ${IPADDR}:${NTPLOG} ${fFile}.* file(s)" >&4 ${_RM} ${STATDIR}/${oFile}.${HOST} >&5 2>&5 JDATE=0 TOD=0 ${_SCP} -pq "${NTPOWN}@${IPADDR}:${NTPLOG}/${fFile}.*" \ ${TDIR} >&5 2>&5 err=$? if [[ ${err} -ne 0 ]] ; then [[ ${debug} -ge 2 ]] && print \ "${myname} DBG: ${HOST} ${fFile} not copied" >&4 print 0 > ${STATDIR}/${oFile}.${HOST} else ${_CAT} ${TDIR}/${fFile}.* > ${STATDIR}/${fFile}.${HOST} 2>&5 if [[ -f ${STATDIR}/${fFile}.${HOST} ]] ; then JDATE=`${_TAIL} -1 ${STATDIR}/${fFile}.${HOST} | \ ${_CUT} -d' ' -f1 ` 2>&5 TOD=`${_TAIL} -1 ${STATDIR}/${fFile}.${HOST} | \ ${_CUT} -d' ' -f2 ` 2>&5 else [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: ${STATDIR}/${fFile}.${HOST} not found" >&4 fi [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: ${HOST} ${fFile} time ${JDATE} ${TOD}" >&4 if [[ ${JDATE} -gt 0 && ${TOD} -gt 0 ]] ; then (( LTOD = (JDATE * 86400) + TOD )) [[ ${debug} -ge 4 ]] && print \ "${myname} DBG: ${HOST} ${fFile} computed time ${LTOD}" >&4 print ${LTOD} > ${STATDIR}/${oFile}.${HOST} else print 0 > ${STATDIR}/${oFile}.${HOST} fi fi (( fCnt += 1 )) done fi ${_RM} ${STATDIR}/${HOST}.ntpfiles >&5 2>&5 ${_RM} -rf ${TDIR} >&5 2>&5 fi