1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Merge pull request #454 from zjttoefs/master

chronyc: new feature, better performance
This commit is contained in:
Steve Schnepp 2014-02-18 16:01:04 +01:00
commit 7138f44167

View file

@ -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]}'