Feature: Add support for JSON output in chronyc
Current formats
- Text => Standard Ouput
- CSV => No key/value output, no header only value delimited by comma
Problematic description
A lot of critical systems need to use timesync protocol to ensure the date is correctly set. Chronyd has been vastly adopted as a replacement of NTPd from what I saw.
I had to monitor Chrony sync/behavior with time sources (sync status, etc). However, the current output from commandline print_report does allow easy parsing.
- I tried the CSV format => Column ID changed based on server config / sources
- We can use Regex extraction format but not very clean nor optimal
Feature Proposal
I would love to have an arg "-j" for a JSON output... ex:
{
"Remote address": "10.1.5.1 (0DC84B01)",
"Remote port": "123",
"Local address": "110.1.5.2 (0DC9A0184)",
"Leap status": "Normal",
"Version": "4",
"Mode": "Server",
"Stratum": "3",
"Poll interval": "9 (512 seconds)",
"Precision": "-19 (0.000001907 seconds)",
"Root delay": "0.015106 seconds",
"Root dispersion": "0.044510 seconds",
"Reference ID": "0DC84B01 ()",
"Reference time": "Tue May 14 10:01:22 2024",
"Offset": "-0.004186390 seconds",
"Peer delay": "0.013871309 seconds",
"Peer dispersion": "0.000001983 seconds",
"Response time": "0.000146284 seconds",
"Jitter asymmetry": "+0.00",
"NTP tests": "111 111 1111",
"Interleaved": "No",
"Authenticated": "No",
"TX timestamping": "Kernel",
"RX timestamping": "Kernel",
"Total TX": "31",
"Total RX": "31",
"Total valid RX": "31",
"Total good RX": "31",
"Total kernel TX": "31",
"Total kernel RX": "31",
"Total HW TX": "0",
"Total HW RX": "0"
}
(Can use the current "CVS format" to also remove the human readable units).
It would mean review the print_report function to allow a pseudo JSON output key/value based on data provided (or create a new function like "print_stats" ?) in client.c
Current overview
I looked how the current print_report is implemented to try to see if I could propose a merge...
But it's kinda difficult with current implementation :
As the char* format is provided directly as a format string and there's inline replacements based on the data type
in the function, I'm not so sure what to propose... I would either try to split the data in multiple array as arguments, like "keys" with all titles, "formats" with all formats, "values" with all values but I noticed that some call do not have titles like "%c%c %-27s %2d %2d %3o %I %+S[%+S] +/- %S\n"
so I think either it would break current formatting or drastically change the code of client.c