7 parse Chrony Tracking output for timeserver status information
9 =head1 APPLICABLE SYSTEMS
11 Any system with a local chronyd service.
20 #%# capabilities=autoconf
24 Revision 0.1 2008/08/23 13:06:00 joti
26 First version only chronyc tracking, autodetection included.
28 Revision 0.2 2008/10/11 16:09:00 joti
30 Added scaling of other values to match with frequency, added more description to fields
32 Revision 0.3 2014/02/16 zjttoefs
34 reduce forking by using awk
35 do not limit output precision
36 add stratum monitoring
37 detect slow/fast time or freqency and adjust sign of value accordingly
38 remove commented out code
40 Revision 0.4 2016/11/10 Lars Kruse
42 rewrite field handling
43 use "which" for "chronyc" location
44 switch from "bash" to "sh"
45 fix exit code of failing "autoconf"
51 Lars Kruse <devel@sumpfralle.de>
55 CHRONYC="$(which chronyc | head -1)"
57 # Frequency has extremely higher values than other. Therefore they are fitted by scaling via suitable factors.
60 # - factor for graph visualization (all values are supposed to reach a similar dimension)
61 # - regular expression of the chrony output line (may not contain whitespace, case insensitive)
62 # - label (may include "%d" for including the factor; may contain whitespace)
63 fields="stratum 1 ^Stratum Stratum
64 systime 1000 ^System.time System Time (x%d)
65 frequency 1 ^Frequency Frequency (ppm)
66 residualfreq 100 ^Residual.freq Residual Freq (ppm, x%d)
67 skew 100 ^Skew Skew (ppm, x%d)
68 rootdelay 1000 ^Root.delay Root delay (seconds, x%d)
69 rootdispersion 1000 ^Root.dispersion Root dispersion (seconds, x%d)"
71 # chrony example output (v2.4.1):
72 # Reference ID : 131.188.3.221 (ntp1.rrze.uni-erlangen.de)
74 # Ref time (UTC) : Thu Nov 10 22:39:50 2016
75 # System time : 0.000503798 seconds slow of NTP time
76 # Last offset : +0.000254355 seconds
77 # RMS offset : 0.002186779 seconds
78 # Frequency : 17.716 ppm slow
79 # Residual freq : +0.066 ppm
81 # Root delay : 0.042980 seconds
82 # Root dispersion : 0.005391 seconds
83 # Update interval : 258.4 seconds
84 # Leap status : Normal
87 if [ "$1" = "autoconf" ]; then
88 if [ -n "$CHRONYC" ] && [ -x "$CHRONYC" ]; then
91 echo "no (missing 'chronyc' executable)"
96 if [ "$1" = "config" ]; then
97 echo 'graph_title Chrony Tracking Stats'
98 echo 'graph_args --base 1000 -l 0'
99 echo 'graph_vlabel (seconds,ppm)'
100 echo 'graph_category time'
101 echo "$fields" | while read fieldname factor regex label; do
102 # insert the factor, if "%d" is part of the label
103 printf "${fieldname}.label $label\n" "$factor"
104 echo "${fieldname}.type GAUGE"
109 chrony_status="$("$CHRONYC" tracking)"
110 echo "$fields" | while read fieldname factor regex label; do
111 status_line="$(echo "$chrony_status" | grep -i -- "$regex " | cut -d ":" -f 2-)"
112 if [ -z "$status_line" ]; then
115 # the keyword "slow" indicates negative values
116 value="$(echo "$status_line" | awk '{ /slow/ ? SIGN=-1 : SIGN=1; print $1 * SIGN * '"$factor"' }')"
118 echo "${fieldname}.value $value"