halmurray at sonic.net
Sun Nov 28 07:57:01 UTC 2021
> Does ntpsec have a (python-)API of some sort that google didn't show me? I'd
> like to visualize the ntp statistics in a web-interface and parsing ntpmon
> output is a bit cumbersome.
Gary's suggestion of ntpvz is interesting, but it displays historical data
from log files rather than a current snapshot.
Since you mentioned ntpmon, I assume you want current status.
ntpq is written in python, so there is an internal api that can be used to get
current status. Even though I'm reasonably familiar with that code, I find it
very hard to work with. Maybe I'm just not a true Python programmer. There
is no documentation but the code is all there.
Gary's suggestion of parsing the log files is worth considering. They are
In case you decide to dive in, here is what's going on.
The top half of ntpmon is the ntpq peers output. There is one call/packet to
get the list of server IDs then a call/packet to get the data from each server.
The bottom half of ntpmon is the ntpq mrulist output. Each call gets the data
for as many slots as will fit in a handful of return packets. The catch is
that the sort order of the list may change while you are retrieving it. If a
packet arrives from an address that you have already retrieved, that slot will
get moved to the end of the list where you will eventually retrieve it again.
So you have to be prepared for duplicates.
The request for more slots includes the IP Address and time stamp of the last
few slots returned. ntpd hashes on the IP Address from the first one to find
the slot. If the time stamp matches that's where to start. If the time stamp
doesn't match, that slot has moved, so it tries the previous IP Address and
These are my opinions. I hate spam.
More information about the users