From 1a0b016723b3f8f24974c46d113b9d04ee488ebe Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Sun, 16 Feb 2014 16:55:42 +0000 Subject: [PATCH] new feature, better performance * add stratum monitoring * reduce forking by using awk * do not limit output precision * detect slow/fast time or freqency and adjust sign of value accordingly * remove commented out code --- plugins/time/chrony | 58 ++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/plugins/time/chrony b/plugins/time/chrony index 2a1e7582..44a678a1 100755 --- a/plugins/time/chrony +++ b/plugins/time/chrony @@ -14,8 +14,14 @@ # Revision 0.2 2008/10/11 16:09:00 joti # Added scaling of other values to match with frequency, added more description to fields # -# Magic markers (optional - used by munin-config and installation -# scripts): +# Revision 0.3 2014/02/16 zjttoefs +# reduce forking by using awk +# do not limit output precision +# add stratum monitoring +# detect slow/fast time or freqency and adjust sign of value accordingly +# remove commented out code +# +# Magic markers (optional - used by munin-config and installation scripts): # #%# family=auto #%# capabilities=autoconf @@ -23,14 +29,11 @@ #Modify this to fit other chronyc path CHRONYC=/usr/bin/chronyc -#Frequency has extremely higher values than other. Therefore they are fitted by scaling. Adjust the factor here -FACTOR=1000 -#fieldfactors="1000 1 1000 100 1000 1000" -fieldfactors="1000 1 100 100 1000 1000" -#Fields to catch and graph, second line is friendly name -fields="systime frequency residualfreq skew rootdelay rootdispersion" -fieldnames="System Time (seconds,x=Frequency (seconds,x=Residual Freq (ppm,x=Skew (ppm,x=Root delay(seconds,x=Root dispersion (seconds,x" - +#Frequency has extremely higher values than other. Therefore they are fitted by scaling. Adjust the factors here +fieldfactors="1 1000 1 100 100 1000 1000" +#fieldfactors="1 1000000 0.1 100 10 10 10" +fields="stratum systime frequency residualfreq skew rootdelay rootdispersion" +fieldnames="Stratum (=System Time (seconds,x=Frequency (ppm,x=Residual Freq (ppm,x=Skew (ppm,x=Root delay(seconds,x=Root dispersion (seconds,x" if [ "$1" = "autoconf" ]; then if [ -f "$CHRONYC" ]; then @@ -43,17 +46,13 @@ if [ "$1" = "autoconf" ]; then fi if [ "$1" = "config" ]; then - echo 'graph_title Chrony Tracking Stats' echo 'graph_args --base 1000 -l 0' - #echo 'graph_vlabel seconds / ${graph_period}' echo 'units (seconds,ppm)' - #echo 'graph_total total' echo 'graph_category NTP' i=0 for a in $fields ; do i=$(expr $i + 1); - #echo "i=$i" word=`echo $fieldnames | cut -f $i -d '='`; factor=`echo $fieldfactors | cut -f $i -d ' '`; echo "$a.label $word$factor)"; @@ -62,29 +61,8 @@ if [ "$1" = "config" ]; then exit 0 fi - -#Remove superflous whitespace (hinders cut), remove non-needed output lines, remove more space,cut out final result value, scale values to factor if needed, output values in munin-required format -j=0 -chronyc tracking | \ - sed "s/ */ /g" | \ - sed "1,3d" | \ -# grep -v "Frequency" | \ - sed "s/ : /:/g" | \ - cut -f 2 -d ':' | \ - cut -f 1 -d ' ' | \ - while read LINE; do - j=$(expr $j + 1); - measure=`echo $fields | cut -f $j -d ' '`; - factor=`echo $fieldfactors | cut -f $j -d ' '`; - echo -en "$measure.value "; -# if [ "$measure" = "frequency" ]; then - #measure is frequency do not enlarge numbers -# echo $LINE | xargs printf "%1.2f"; -# else - #measure is not frequency, enlarge numbers to make them showable together with frequency - echo $LINE*$factor | bc | xargs printf "%1.2f"; -# fi - #echo $LINE*100 | bc | xargs printf "%1.2f"; - echo; - done - +# remove non-needed output lines, remove labels, rescale and label values while detecting slow/fast keywords +chronyc tracking | sed -e 1d -e 3d -e "s/.*://" | \ + awk -v FAC="$fieldfactors" -v NAM="$fields" \ + 'BEGIN { split(FAC,factors," "); split(NAM,names," "); } + { /slow/ ? SIGN=-1 : SIGN=1 ; print names[NR]".value ",SIGN*$1*factors[NR]}'