cfspeedtest
cfspeedtest copied to clipboard
Add latency measurements to json outputs
Add latency measurements to json outputs
Hi! First of all, thank you for creating this project. I was looking for an official CLI for the cloudflare speedtest website but couldn't find anything. This is a lifesaver.
I'd love to include your project as a data source for Cloudflare in my project MySpeed, if that would be okay with you. I couldn't find any way to contact you here on GitHub so I thought I'd mention it in this PR here.
Motivation
I was looking for a way to parse the essential data for a speedtest (Download, Upload, Ping). I found that there is both a json and json-pretty output type but that didn't include the latency measurements I was hoping for.
To actually retrieve everything I need, I would have to parse the latency out of the text with a regex, which is not an ideal solution for me.
Changes
This PR adds latency measurements to the json and json-pretty output. This also means that there will be a breaking change for the json output since I couldn't match the datatype of the latency onto the StatMeasurement, so I created a new one.
Outputs of the speed measurements will go in the speed_measurements array and latency will go in the latency_measurements array.
Example
$ ./cfspeedtest -o json-pretty
{
"latency_measurement": {
"avg_latency_ms": 24.010808615384615,
"latency_measurements": [
24.005308,
[...]
24.447156999999997
],
"max_latency_ms": 24.852537999999996,
"min_latency_ms": 23.013303999999998
},
"speed_measurements": [
{
"avg": 86.7819943848012,
"max": 104.99732125584147,
"median": 104.22935012163725,
"min": 31.085312201641717,
"payload_size": 100000,
"q1": 87.72995666578791,
"q3": 104.72137634257713,
"test_type": "Download"
},
[...]
]
}
I've never worked with Rust before so if there are any improvements regarding the code quality or naming, please let me know and I will fix it asap.