Page 1 of 1
avg-rtt from ping command
Posted: Tue Mar 11, 2014 2:51 pm
by abcklocki
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.
Re: avg-rtt from ping command
Posted: Wed Mar 12, 2014 12:37 am
by rextended
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");
Re: avg-rtt from ping command
Posted: Wed Mar 12, 2014 11:45 am
by abcklocki
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.
Re: avg-rtt from ping command
Posted: Wed Mar 12, 2014 3:52 pm
by rextended
... 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.
Re: avg-rtt from ping command
Posted: Wed Mar 12, 2014 4:35 pm
by abcklocki
Is there any chance to run ping command with these parameters via Mikrotik API and read avg-rtt value without creation ssh connection ?
Re: avg-rtt from ping command
Posted: Wed Mar 12, 2014 5:10 pm
by boen_robot
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.
Re: avg-rtt from ping command
Posted: Fri Mar 14, 2014 2:39 pm
by abcklocki
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.
Re: avg-rtt from ping command
Posted: Sat Mar 15, 2014 12:30 am
by boen_robot
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.
Re: avg-rtt from ping command
Posted: Wed Mar 26, 2014 2:47 pm
by abcklocki
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.
Re: avg-rtt from ping command
Posted: Wed Nov 26, 2014 7:33 am
by technicarl
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")
Re: avg-rtt from ping command
Posted: Sun May 14, 2017 8:39 pm
by n21roadie
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,
Re: avg-rtt from ping command
Posted: Mon Aug 30, 2021 4:41 pm
by tnrclkr
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.
Re: avg-rtt from ping command
Posted: Mon Aug 30, 2021 8:11 pm
by rextended
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")
}
Re: avg-rtt from ping command
Posted: Wed Sep 01, 2021 12:53 pm
by kirac
Hi,
Not working for mac ping, how can I get avg-rtt value for mac ping?
Thank you.
Re: avg-rtt from ping command
Posted: Sat Sep 04, 2021 2:00 am
by rextended
now mac ping avg-rtt can be put inside a variable:
viewtopic.php?f=2&t=69773&p=876970#p876970