Community discussions

MikroTik App
 
abcklocki
just joined
Topic Author
Posts: 8
Joined: Tue Mar 14, 2006 2:56 pm

avg-rtt from ping command

Tue Mar 11, 2014 2:51 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: avg-rtt from ping command

Wed Mar 12, 2014 12:37 am

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

ros code

/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.2
when 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:

ros code

: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");
Last edited by rextended on Mon Mar 20, 2023 6:27 pm, edited 1 time in total.
 
abcklocki
just joined
Topic Author
Posts: 8
Joined: Tue Mar 14, 2006 2:56 pm

Re: avg-rtt from ping command

Wed Mar 12, 2014 11:45 am

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: avg-rtt from ping command

Wed Mar 12, 2014 3:52 pm

... 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=<self> address=<self_address> port=<port number> command="/ping address=<voip_operator> routing-table=m1 count=1"
/system ssh output-to-file=tmp-ping-result-m2 user=<self> address=<self_address> port=<port number> command="/ping address=<voip_operator> routing-table=m2 count=1"
/system ssh output-to-file=tmp-ping-result-wan1 user=<self> address=<self_address> port=<port number> command="/ping address=<voip_operator> src-address=<IP_WAN1> count=1"
/system ssh output-to-file=tmp-ping-result-wan2 user=<self> address=<self_address> port=<port number> command="/ping address=<voip_operator> src-address=<IP_WAN1> count=1"

And read by script the output inside the 4 files.
Last edited by rextended on Mon Mar 20, 2023 6:27 pm, edited 1 time in total.
 
abcklocki
just joined
Topic Author
Posts: 8
Joined: Tue Mar 14, 2006 2:56 pm

Re: avg-rtt from ping command

Wed Mar 12, 2014 4:35 pm

Is there any chance to run ping command with these parameters via Mikrotik API and read avg-rtt value without creation ssh connection ?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: avg-rtt from ping command

Wed Mar 12, 2014 5:10 pm

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.
 
abcklocki
just joined
Topic Author
Posts: 8
Joined: Tue Mar 14, 2006 2:56 pm

Re: avg-rtt from ping command

Fri Mar 14, 2014 2:39 pm

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.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: avg-rtt from ping command

Sat Mar 15, 2014 12:30 am

Is it possible to run script locally and log whole output of ping command to file ???
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.
 
abcklocki
just joined
Topic Author
Posts: 8
Joined: Tue Mar 14, 2006 2:56 pm

Re: avg-rtt from ping command

Wed Mar 26, 2014 2:47 pm

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

bash code

* * * * * /usr/bin/ssh -i /home/nagios/.ssh/id_dsa -l monitor_user <address> "system script run monitor_voip" < /dev/random > /tmp/voip_ping.log
API Ping don't have routing-mark parameter available.
Many thanks for discussion about possible solutions.
 
technicarl
just joined
Posts: 13
Joined: Wed Nov 26, 2014 7:07 am

Re: avg-rtt from ping command

Wed Nov 26, 2014 7:33 am

Thank you rextended :)

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")
 
n21roadie
Forum Guru
Forum Guru
Posts: 1949
Joined: Fri Aug 07, 2009 10:36 pm
Location: Limerick,Ireland

Re: avg-rtt from ping command

Sun May 14, 2017 8:39 pm

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,
 
tnrclkr
newbie
Posts: 27
Joined: Tue Aug 25, 2015 8:36 am

Re: avg-rtt from ping command

Mon Aug 30, 2021 4:41 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: avg-rtt from ping command

Mon Aug 30, 2021 8:11 pm

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")
}
Last edited by rextended on Sat Sep 04, 2021 2:01 am, edited 1 time in total.
 
kirac
just joined
Posts: 3
Joined: Wed Sep 01, 2021 12:48 pm

Re: avg-rtt from ping command

Wed Sep 01, 2021 12:53 pm

Hi,

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

Thank you.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: avg-rtt from ping command

Sat Sep 04, 2021 2:00 am

now mac ping avg-rtt can be put inside a variable:
viewtopic.php?f=2&t=69773&p=876970#p876970

Who is online

Users browsing this forum: A9691 and 18 guests