Re: [chrony-users] Python code to read chronyc sources

[ Thread Index | Date Index | More Archives ]

On Thu, Apr 07, 2016 at 08:58:40AM -0700, Deven Hickingbotham wrote:
> Does anyone have a Python 3 example of how to read chronyc sources?  I want
> to read the estimated error of the synced server.

If you can use chronyc compiled from git, there is a new CSV mode
suitable for parsing. To print the last column (in seconds) of the
source that has the '*' state using a python3 one-liner:

$ chronyc -c sources | python3 -c 'import csv,sys; print("".join([s[9]
if s[1] == "*" else "" for s in csv.reader(sys.stdin)]))'

If you need the maximum assumed error of the local clock, it's
better to calculate the root distance from the tracking report:

$ chronyc -c tracking | python3 -c 'import csv,sys; t = list(csv.reader(sys.stdin)); print(float(t[0][10]) / 2 + float(t[0][11]))'

Parsing the normal sources output with conversion of the units is
painful. I don't know if anyone did that in python. The tracking
output should be easier to parse.

Miroslav Lichvar

To unsubscribe email chrony-users-request@xxxxxxxxxxxxxxxxxxxx 
with "unsubscribe" in the subject.
For help email chrony-users-request@xxxxxxxxxxxxxxxxxxxx 
with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.

Mail converted by MHonArc 2.6.19+