Community discussions

MikroTik App
 
AlohaSpark
newbie
Topic Author
Posts: 45
Joined: Wed Jun 16, 2021 10:39 pm

Is there a way to get /tool/fetch response time?

Tue Dec 06, 2022 8:11 am

I would like to know how long it takes to fetch a URL. Is there a way to do so within a script?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Is there a way to get /tool/fetch response time?

Tue Dec 06, 2022 11:30 am

unless you do it at the turn of midnight, if you memorize the time before the download and compare it with the time after the download...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3250
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Is there a way to get /tool/fetch response time?

Tue Dec 06, 2022 7:49 pm

How about using :timestamp? While Mikrotik doesn't support dates or floats, they do have "time" and "time difference" type... Super useful here.
{ 
  :local start [:timestamp]
  /tool/fetch url="https://wttr.in/Riga+LV?T&format=2" output=user
  :local stop [:timestamp]
  :put ($stop-$start)
}
Which takes 3.1 seconds (or "00:00:03.103317400"), and we knows it's -2C & breezy in Riga, Latvia.
  status: finished
  downloaded: 0K
        data:               -2  C           20km/h


00:00:03.103317400
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3250
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Is there a way to get /tool/fetch response time?

Tue Dec 06, 2022 7:57 pm

Note: In theory, you might not want to use "output=user", and use "output=none" to time it. The output to display a relatively large amount of some time. In fact almost 2 second to write to terminal. And if you normally write to disk, timing it it that way be most accurate (output=file).
 { :local start [:timestamp]; /tool/fetch url="https://wttr.in/Riga+LV?T&format=2" output=none; :local stop [:timestamp]; :put ($stop-$start)}

      status: finished
  downloaded: 0KiBC-z pause]
       total: 0KiB
    duration: 0s

00:00:01.099018660

Who is online

Users browsing this forum: No registered users and 23 guests