On Wed, Jul 22, 2020 at 06:16:01AM -0700, Richard Cochran wrote: > On Wed, Jul 22, 2020 at 02:14:48PM +1000, Luke Howard wrote: > > [resending from correct email] > > > > > The output of the pmc tool is still unstructured text. So to feed it into > > > a script I would still need to write an output parser of some sort and I > > > would have to guess that my parser covers all of the cases that the tool > > > might generate and I would have to assume that the output format doesn’t > > > change. This is what got me thinking about structuring the output format > > > somehow in a way that any tool could consume it. > > > > Perhaps in that case a structured text option to pmc(8) would be useful and > > not too hard to add? > > In contrast to the logging, I think the pmc output is already > structured and easy to parse.
Case in point: - I wanted to add simple client monitoring to a deployment. - Running pmc every second (or so) is really easy in systemd, and the output is logged automatically, BUT - the client's records are spread across multiple lines, and that is not very convenient in the syslog. - So, what do I do? Invent a new logging interface? Nah. Something like this in python could emit json pretty easily, I would expect... ---8<--- pmc-monitor.service ------ [Unit] Description=PTP Logging Service After=network.target [Service] Type=exec ExecStart=/usr/local/bin/pmc-monitor.sh Restart=always [Install] WantedBy=multi-user.target ---8<--- pmc-monitor.sh ------ #!/bin/sh while [ 1 ]; do pmc -u 'get current' | awk -e ' function print_last_record() { if (!last) { return; } gsub("\t", " ", last); print last; } { if ($1 == "sending:") { next; } if ($4 == "RESPONSE" && $5 == "MANAGEMENT") { print_last_record(); last = $1 " " $6; next; } last = last $0; } END { print_last_record(); } ' sleep 1 done _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel