Hello guys,
I am sorry for this stupid question but I tried for some hours and do not get it.
I wrote script, which should get the “avg-rtt” of a ping but it does not work.
This is my Code:
If I run this in the terminal I get nothing as output, but if I ping in the terminal I can clearly see that there is an avg-rtt output.
What am I doing wrong?
I appreciate every advice
The first method provide more human readable values (50), the second not so easy:
00:00:00.050994
Trimming the string, can be extracted only the interested part:
That is exactly what I searched for. Thank you very much.
It is also very usefull to know how to trimm it.
If I wanted to get packet-loss, should I do it in a similar way or is there something smarter?
Just that you know if it does matter, I would need the routing-table element in the ping, so flood-ping is not an option, if I understood it correctly.
Everytime the “status” filed is one string, is one failed ping (because containing the error code:
{
:local test [:ping [:resolve “www.mikrotik.com”] count=3 as-value]
:local avg 0
:local fails 0
:local min 00:00:10
:local max 00:00:00
:foreach try in=$test do={
:set avg ($avg + ($try->“time”))
:if ([:typeof ($try->“status”)] = “str”) do={
:set fails ($fails + 1)
} else={
:if (($try->“time”) < $min) do={:set min ($try->“time”)}
:if (($try->“time”) > $max) do={:set max ($try->“time”)}
}
}
:set avg ($avg / [:len $test])
:set avg [:pick $avg 0 15]
:put “sent=$[:len $test] received=$([:len $test]-$fails) packet-loss=$(($fails*100)/[:len $test])% min-rtt=$min avg-rtt=$avg max-rtt=$max”
}
Percentage is hard to calc precisely because MikroTik scripting do not support decimals.
Adding decimals multiply the number by 100 and splitting with :put is possible, but on this case is excessive…