avg-rtt from ping command

Hello everyone.
I have one unresolved task in my network
I want to report reponse time of ping external address - i have 2 WAN and i want to measure response time for every path…

I found this part of code (with ping-flood command):

:local avgRtt;
:local pin
:local pout
/tool flood-ping 8.8.8.8 count=10 do={
  :if ($sent = 10) do={
    :set avgRtt $"avg-rtt"
    :set pout $sent
    :set pin $received
  }
}
:local ploss (100 - (($pin * 100) / $pout))
:local logmsg ("Ping Average for 8.8.8.8 - ".[:tostr $avgRtt]."ms - packet loss: ".[:tostr $ploss]."%")
:log info $logmsg

but i have to use ping command with routing-mark or src-address parameter because ping-flood doesn’t have this parameters.

Example
Your WAN1: 1.1.1.1
Your WAN2: 2.2.2.2

IP for Ping 8.8.8.8 by WAN1: 10.0.0.1
IP for Ping 8.8.4.4 by WAN2: 10.0.0.2

Make static route like
/ip route
add distance=1 dst-address=8.8.8.8/32 gateway=1.1.1.1 pref-src=10.0.0.1
add distance=1 dst-address=8.8.4.4/32 gateway=2.2.2.2 pref-src=10.0.0.2when you do flood-ping (can be considered DOS attack… you FLOOD the dst by ping… do 1 flood-ping size=38 ever 1 sec for “x” sec instead…)
the route are giving “automatically” src-address and you can choice wan interface.

Use this instead:
:local avgRttA value=0;
:local avgRttB value=0;
:local numPing value=4;
:local toPingIP1 value=8.8.8.8;
:local toPingIP2 value=8.8.4.4;
:for tmpA from=1 to=$numPing step=1 do={
/tool flood-ping count=1 size=38 address=$toPingIP1 do={
:set avgRttA ($“avg-rtt” + $avgRttA);
}
/tool flood-ping count=1 size=38 address=$toPingIP2 do={
:set avgRttB ($“avg-rtt” + $avgRttB);
}
/delay delay-time=1;
}
:log info ("Ping Average for 8.8.8.8 by WAN1: ".[:tostr ($avgRttA / $numPing )].“ms”);
:log info ("Ping Average for 8.8.4.4 by WAN2: ".[:tostr ($avgRttB / $numPing )].“ms”);

Thanks for fast reply.

I forgot to add some details - I have 2 WAN and configured failover with VOIP as high priority service. (WAN1 - VOIP , WAN2 - rest of traffic)
I have to check ping response time from one external IP address - (provider of my VOIP service)

So i think i cannot use static routes (because i have voip isolated from rest of traffic - and changes in routing table may corrupt VOIP connections)

I know i can use ping command:

/ping address=<voip_operator> routing-table=m1 count=1
/ping address=<voip_operator> routing-table=m2 count=1 

or

/ping address=<voip_operator> src-address=<IP_WAN1> count=1
/ping address=<voip_operator> src-address=<IP_WAN2> count=1

but i don’t know how can I get avgrtt value from ping command.

Actually the only way to save result of ping command is to implement:

/system ssh output-to-file=tmp-ping-result-m1 user= address=<self_address> port= command=“/ping address=<voip_operator> routing-table=m1 count=1”
/system ssh output-to-file=tmp-ping-result-m2 user= address=<self_address> port= command=“/ping address=<voip_operator> routing-table=m2 count=1”
/system ssh output-to-file=tmp-ping-result-wan1 user= address=<self_address> port= command=“/ping address=<voip_operator> src-address=<IP_WAN1> count=1”
/system ssh output-to-file=tmp-ping-result-wan2 user= address=<self_address> port= command=“/ping address=<voip_operator> src-address=<IP_WAN1> count=1”

And read by script the output inside the 4 files.

Is there any chance to run ping command with these parameters via Mikrotik API and read avg-rtt value without creation ssh connection ?

Is there any chance to run ping command with these parameters via Mikrotik API and read avg-rtt value without creation ssh connection ?

Yes, but this still means that you need an external device from which you’ll launch the API command, and inspect the results from. If you plan on storing the results on an external device anyway, then that shouldn’t be a problem - in fact, it would ease the process if that same device is the one launching the API command.

Yes - i have to use external linux machine to execute script
I have tested and it works but i have another idea.

Is it possible to run script locally and log whole output of ping command to file ???

/ping address=8.8.8.8 routing-table=m1 count=3
HOST                                     SIZE TTL TIME  STATUS                                                          
8.8.8.8                                    56  45 36ms 
8.8.8.8                                    56  45 27ms 
8.8.8.8                                    56  45 26ms 
    sent=3 received=3 packet-loss=0% min-rtt=26ms avg-rtt=29ms max-rtt=36ms 
HOST                                     SIZE TTL TIME  STATUS

if i run ping and redirect output only result’s of ping command is writen to file so it will be useless for me.

You could use “/system ssh” with 127.0.0.1 as an address, and use the “output-to-file” argument to write the output to a file.

But as you point out,

if i run ping and redirect output only result’s of ping command is writen to file so it will be > useless > for me.

… since parsing it is going to be very difficult locally, and (more importantly) it would be really fragile (e.g. an innocent change from one version to the next - like adding an extra column or an extra space - will screw up the whole thing). So in the end of the day, it’s much better to use the API in this scenario.

Many thanks for help
I have checked many solutions and i chose to create crontab task with ssh:

          • /usr/bin/ssh -i /home/nagios/.ssh/id_dsa -l monitor_user “system script run monitor_voip” < /dev/random > /tmp/voip_ping.logAPI Ping don’t have routing-mark parameter available.
            Many thanks for discussion about possible solutions.

Thank you rextended :slight_smile:

You made my day - I don’t know how to give karma.

:local avgRttA 0
:local avgRttB 0
:local numPing 4
:local toPingIP1 8.8.8.8
:local toPingIP2 8.8.4.4

:for tmpA from=1 to=$numPing step=1 do={
/tool flood-ping count=1 size=38 address=$toPingIP1 do={
:set avgRttA ($“avg-rtt” + $avgRttA);
}
/tool flood-ping count=1 size=38 address=$toPingIP2 do={
:set avgRttB ($“avg-rtt” + $avgRttB)
}
/delay delay-time=1
}
:put ("Ping Average for 8.8.8.8 by WAN1: ".[:tostr ($avgRttA / $numPing )].“ms”)
:put ("Ping Average for 8.8.4.4 by WAN2: ".[:tostr ($avgRttB / $numPing )].“ms”)

Just a question on average ping,how accurate is the result when ping timeouts occur ?

just did a flood ping to a unreachable destination and the avg-rtt was 0,

What if i need to get same results by pinging mac address?

ı just need to get avg-tty result but by pinging the mac address.

Flood ping do not support MAC address,
(see next post for read avg-rtt)

Refreshing the script for 2021:

{
:local avgRttA 0
:local avgRttB 0
:local numPing 4
:local toPingIP1 8.8.8.8
:local toPingIP2 8.8.4.4
:for tmpA from=1 to=$numPing step=1 do={
    /tool flood-ping count=1 size=38 address=$toPingIP1 do={
        :set avgRttA ($"avg-rtt" + $avgRttA)
    }
    /tool flood-ping count=1 size=38 address=$toPingIP2 do={
        :set avgRttB ($"avg-rtt" + $avgRttB)
    }
    /delay 1s
}
:log info ("Ping Average for 8.8.8.8: $($avgRttA / $numPing)ms")
:log info ("Ping Average for 8.8.4.4: $($avgRttB / $numPing)ms")
}

Hi,

Not working for mac ping, how can I get avg-rtt value for mac ping?

Thank you.

now mac ping avg-rtt can be put inside a variable:
http://forum.mikrotik.com/t/how-to-get-the-avg-rtt-value-of-command-ping/63496/5