My ADSB Receiver Box – Monitoring clock performance – Upgrade 4

In upgrade 1 I described how to add a GPS to the ADSB receiver for a precise clock in the Raspberry Pi. Here is another description how to add a graph in the the ADSB receiver portal for monitoring clock performance.

Clock Statistics

The performance data is provided by ntpq -crv with an output like this:

associd=0 status=0115 leap_none, sync_pps, 1 event, clock_sync,
version="ntpd 4.2.8p9@1.3265-o Wed Dec 21 16:56:19 UTC 2016 (1)",
processor="armv7l", system="Linux/4.4.38-v7+", leap=00, stratum=1,
precision=-19, rootdelay=0.000, rootdisp=1.045, refid=PPS,
reftime=dc35eef5.c2b266ef  Fri, Jan 27 2017 17:08:21.760,
clock=dc35eef9.2158cb33  Fri, Jan 27 2017 17:08:25.130, peer=36091, tc=4,
mintc=3, offset=-0.009059, frequency=-5.853, sys_jitter=0.001907,
clk_jitter=0.002, clk_wander=0.002

Details about meaning of all these values can be found here http://doc.ntp.org/4.2.6/ntpq.html. I have chosen offset, sys_jitter and clk_jitter for my monitoring. That is the time offset, combined system jitter and clock jitter. Values are given in milliseconds.

A shell script will be used to extract the wanted values from the ntpq output. This script is executed by the collectd daemon using the exec plugin. Let’s start with the script:

#!/bin/sh

hostname="${COLLECTD_HOSTNAME:-localhost}"
interval="${COLLECTD_INTERVAL:-60}"

while true; do
   offset=U
   sys_jitter=U
   clk_jitter=U

   eval "$(
      ntpq -crv | awk -F, '/offset|sys_jitter/ {print $2"\n" $4};/clk_jitter/ {print $1}'
   )"

   if [ "$offset" = U ] && [ "$sys_jitter" = U ] && [ "$clk_jitter" = U ]; then
      break
   fi

   echo "PUTVAL \"$hostname/ntpq/gauge-offset\" interval=$interval N:$offset"
   echo "PUTVAL \"$hostname/ntpq/gauge-sys_jitter\" interval=$interval N:$sys_jitter"
   echo "PUTVAL \"$hostname/ntpq/gauge-clk_jitter\" interval=$interval N:$clk_jitter"
   sleep "$interval"
done

Save this scipt to /etc/collectd/read_ntpq.sh, any other location will be fine too. Don’t forget to set permission to make it executable, so 0755.

Next edit /etc/collectd/collectd.conf and add the following lines:

LoadPlugin exec
<Plugin exec>
   Exec "nobody:root" "/etc/collectd/read_ntpq.sh"
</Plugin>

Save the collectd.conf file and restart the collectd daemon with sudo service collectd restart. Check that the a new folder ntpq with three files exists now where collectd stores its data. For me in /var/lib/collectd/rrd/localhost/ntpq/. Now the collectd daemon is monitoring the clock performance as required.

Read Ntpq
Read Ntpq
read_ntpq.sh
644.0 B
31 Downloads
Details
Collectd
Collectd
collectd.conf
4.9 KB
31 Downloads
Details
Make-collectd-graphs
Make-collectd-graphs
make-collectd-graphs.sh
23.1 KB
31 Downloads
Details
Graphs
Graphs
graphs.tpl
11.9 KB
35 Downloads
Details
Graphs
Graphs
graphs.js
8.2 KB
35 Downloads
Details

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments will be moderated! Spam deleted immediately!
Before you submit form:
Human test by Not Captcha