[HELP] Decimal value in tool netwatch script

i have this netwatchv7 script to monitor ip so it gives log for rtt avg every time its up or down

/tool netwatch add disabled=no down-script=": log warning \"RTT Avg \$\"rtt-avg\" Loss Percent \$\"loss-percent\" \"" host=8.8.8.8 http-codes="" interval=8s packet-count=4 test-script="" thr-avg=50ms thr-loss-count=2 thr-loss-percent=10% type=icmp up-script=": log warning \"RTT Avg \$\"rtt-avg\" Loss Percent \$\"loss-percent\"\""

but everytime its logs. its give value of decimal without the dot/comma,

 09-14 01:55:36 script,warning RTT Avg 25534 Loss Percent 0

my question is. how to remove the last 3 digit of this rtt-avg value, so i can read it easily?

on routeros 23456 / 1000 = 23 so…

There are no floating point numbers. There is time.

The RTT is in nanoseconds.
So @rextended is correct that “/1000” would get you milliseconds…

/tool netwatch add disabled=no down-script=": log warning \"RTT Avg \$\"rtt-avg\" Loss Percent \$\"loss-percent\" \"" host=8.8.8.8 http-codes="" interval=8s packet-count=4 test-script="" thr-avg=50ms thr-loss-count=2 thr-loss-percent=10% type=icmp up-script=": log warning \"RTT Avg \$(\$\"rtt-avg\"/1000)ms Loss Percent \$\"loss-percent\"\""

While there is the new :tonsec to go from time to nanoseconds… there is NOT a reciprocal to get nanoseconds to a “time” object :frowning:

If values are less then 1sec, this get the right result:

{
:local ns 25543
:put [:totime "$($ns/1000000).$($ns/1000)$($ns%1000)"]
}
# 00:00:00.255340

If greater than 1 seconds, the milliseconds will be wrong, so ~500ms off — but RTT 1second would already be a problem… This could be fixed with more code/workarounds.

I might be missing something…but even with the new :tonsec… there isn’t a reverse since [:totime] expect either string or num in seconds — that solve this problem better…



thanks rextended and Amm0 for now its solved my problem script. the result is great maybe some upgraded script will perfect.
here is my script it will stay logging every 1 minute if its get down.

/tool netwatch add disabled=no down-script=": log warning \"RTT Avg \$(\$\"rtt-avg\"/1000)ms Loss Percent \$\"loss-percent\" \"\r\
    \n:delay 60s\r\
    \n/tool netwatch enable [find where disabled=no and host=8.8.8.8]" host=8.8.8.8 http-codes="" interval=8s packet-count=4 test-script="" thr-avg=50ms thr-loss-count=2 thr-loss-percent=10% type=icmp up-script=": log warning \"RTT Avg \$(\$\"rtt-avg\"/1000)ms Loss Percent \$\"loss-percent\"\""

result

 09-14 04:35:13 script,warning RTT Avg 4294967ms Loss Percent 1000 
 09-14 04:36:13 system,info Netwatch config changed
 09-14 04:36:17 script,warning RTT Avg 4294967ms Loss Percent 1000 
 09-14 04:37:17 system,info Netwatch config changed
 09-14 04:37:21 script,warning RTT Avg 4294967ms Loss Percent 1000 
 09-14 04:37:28 system,info filter rule changed by admin
 09-14 04:37:28 script,warning RTT Avg 26ms Loss Percent 0

its give RTT Avg 4294967ms when ping 8.8.8.8 is time out. its ok for now. but will perfect if its gives some value to "request time out" in the log. but thanks anyway :smiley:

I was wrong the units — you get microseconds, “us”.
And I forgot you can use [:totime “$($“rtt-avg”)us”] syntax…
Not going to help make it prettier, but that does the math right. Essentially the “time” type has has “decimals” – just not where you want them :wink:.
The $“rtt-avg”/1000 approach seems simpler/clearer.