-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntp-tail
More file actions
41 lines (38 loc) · 1.57 KB
/
Copy pathntp-tail
File metadata and controls
41 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
"""Tail NTP tracking log and print live formatted updates."""
import json
import subprocess
import sys
FIX = {1: "none", 2: "2D", 3: "3D"}
HDR = ("%-20s %9s %9s %9s %8s %6s %7s %5s %5s %3s %4s %7s %s"
% ("TIME", "SYS_ns", "RMS_us", "PPS_ns", "JIT_ns", "TEMP", "GW_ms",
"HDOP", "TDOP", "SAT", "FIX", "SCORE", "REF"))
proc = subprocess.Popen(
["tail", "-f", "/var/log/ntp-tracking/tracking.jsonl"],
stdout=subprocess.PIPE, text=True
)
print(HDR, flush=True)
try:
for line in proc.stdout:
d = json.loads(line.strip())
so = d.get("sys_offset_ns") or 0
rms = d.get("rms_offset_us") or 0
pps = d.get("pps_offset_ns") or 0
j = d.get("pps_jitter_ns") or 0
temp = d.get("temp_c", "?")
gw = d.get("ping_gw_ms", "?")
hdop = d.get("gps_hdop")
tdop = d.get("gps_tdop")
sats = d.get("gps_sats")
fix = FIX.get(d.get("gps_fix"), "?")
ref = d.get("ref", "?")
score = d.get("ntppool_score")
hdop_s = "%5.2f" % hdop if hdop is not None else " ?"
tdop_s = "%5.1f" % tdop if tdop is not None else " ?"
sats_s = "%3d" % sats if sats is not None else " ?"
score_s = "%7.2f" % score if score is not None else " ?"
print("%-20s %+9d %9.1f %+9d %8.1f %6s %7s %s %s %s %4s %s %s"
% (d["ts"], so, rms, pps, j, temp, gw,
hdop_s, tdop_s, sats_s, fix, score_s, ref), flush=True)
except KeyboardInterrupt:
proc.terminate()