traviscross / mtr

Official repository for mtr, a network diagnostic tool
http://www.bitwizard.nl/mtr/
GNU General Public License v2.0
2.64k stars 337 forks source link

Fix header line generation for CSV data export #451

Open elfring opened 1 year ago

elfring commented 1 year ago

I built the evolving network analysis tool according to the development revision “v0.95-17-g826ffa9”. I tried the program out then accordingly.

Sonne:/home/altes_Heim2/elfring/Projekte/Bau/mtr/console # ./mtr --report-cycles 5 --report --csv download.opensuse.org
Mtr_Version,Start_Time,Status,Host,Hop,Ip,Loss%,Snt, ,Last,Avg,Best,Wrst,StDev,
…

:thought_balloon: Such a header line should not contain two empty field names (in the middle and at the end).

elfring commented 1 year ago

💭

rewolff commented 1 year ago

I think the default "field list" contains "spacer" so it prints that field in the results. And it puts a header on top. It takes a lot of code to fix that and it is currently "ok" in that an empty field prints with an empty header.

elfring commented 1 year ago

… it is currently "ok" in that an empty field prints with an empty header.

I disagree with this detail because I observed that the column numbers would be different between the header and subsequent record sets.

rewolff commented 1 year ago

Make it easy for me to verify that. Paste output here.

elfring commented 1 year ago

Do you find a test command (like the following) helpful for further clarification of involved issues? :thinking:

Sonne:…/Bau/mtr/console # my_file=/tmp/mtr-test-20220914.csv && ./mtr --report-cycles 2 --csv localhost > ${my_file} && head -n 1 ${my_file} | tr ',' '\n' | wc -l && tail -n 1 ${my_file} | tr ',' '\n' | wc -l
…
mroe1234 commented 1 year ago

I'm going to agree that it is /not/ ok to have empty fields. the CSV output is useful for programmatic uses and having a literal space as a header 1. doesn't even really make sense to begin with, and 2. can cause weirdness with tools farther down the pipeline.

rewolff commented 1 year ago

mtr-csv

Stuff seems to align correctly. There is just a , at the end of the header line.

If you provide a patch to remove that , I'll accept it. If you provide a patch to remove the empty header and "0" column below it, I'll accept it.