Community discussions

MikroTik App
 
PhotoshopPhilipp
just joined
Topic Author
Posts: 5
Joined: Wed Feb 10, 2021 10:32 am

7.1beta4 monitor-traffic restApi

Wed Feb 10, 2021 10:42 am

Is it possible to get the following information through the rest api?:

tx-bits-per-second
rx-bits-per-second


The command would be: /interface/monitor-traffic wlan1 once but I could not get to run in through the api. I think id have to do it through the POST methode as it is descriped in the documentation https://help.mikrotik.com/docs/display/ROS/REST+API

I think: ip/rest/interface/monitor-traffic?interface=wlan1 is the way to do it but it needs somehow the once param...

Does someone know how to do that?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7018
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: 7.1beta4 monitor-traffic restApi

Wed Feb 10, 2021 11:11 am

Check "Timeout" section in that manual. It has an example on how to use similar commands to "monitor-traffic"
 
PhotoshopPhilipp
just joined
Topic Author
Posts: 5
Joined: Wed Feb 10, 2021 10:32 am

Re: 7.1beta4 monitor-traffic restApi

Wed Feb 10, 2021 11:53 am

Check "Timeout" section in that manual. It has an example on how to use similar commands to "monitor-traffic"
Mmm thats a thing but not exactly what im trying to do. I can messure the bandwith between 2 tiks but i want to know the traffic of the interface wlan1 for exampe...

Is there another solution to that?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7018
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: 7.1beta4 monitor-traffic restApi

Wed Feb 10, 2021 1:53 pm

It is not clear what you are not able to do.

Have you tried to run
POST 'https://x.x.x.x/rest/tool/traffic-monitor' -data '{"interface":"wlan1","duration":"2s"}'
 
PhotoshopPhilipp
just joined
Topic Author
Posts: 5
Joined: Wed Feb 10, 2021 10:32 am

Re: 7.1beta4 monitor-traffic restApi

Wed Feb 10, 2021 4:06 pm

Yes i already tried that on multiple tiks but it didnt work :(
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7018
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: 7.1beta4 monitor-traffic restApi  [SOLVED]

Wed Feb 10, 2021 4:19 pm

Be more specific what exaclty is not working what errors you get and so on.

Here is an example of traffic monitor, it works as expected:
$ curl -k -u admin: -X POST 'https://10.155.101.214/rest/interface/monitor-traffic'   --data '{"interface":"sfp12","duration":"2s"}' -H "content-type: application/json"

[{".section":"0","fp-rx-bits-per-second":"45176","fp-rx-packets-per-second":"49","fp-tx-bits-per-second":"222160","fp-tx-packets-per-second":"30","name":"sfp12","rx-bits-per-second":"45176","rx-drops-per-second":"0","rx-errors-per-second":"0","rx-packets-per-second":"49","tx-bits-per-second":"222160","tx-drops-per-second":"0","tx-errors-per-second":"0","tx-packets-per-second":"30","tx-queue-drops-per-second":"0"},{".section":"1","fp-rx-bits-per-second":"24184","fp-rx-packets-per-second":"27","fp-tx-bits-per-second":"214616","fp-tx-packets-per-second":"31","name":"sfp12","rx-bits-per-second":"24184","rx-drops-per-second":"0","rx-errors-per-second":"0","rx-packets-per-second":"27","tx-bits-per-second":"214616","tx-drops-per-second":"0","tx-errors-per-second":"0","tx-packets-per-second":"31","tx-queue-drops-per-second":"0"}]

 
PhotoshopPhilipp
just joined
Topic Author
Posts: 5
Joined: Wed Feb 10, 2021 10:32 am

Re: 7.1beta4 monitor-traffic restApi

Wed Feb 10, 2021 4:25 pm

I tried it with curl and it worked right away. Well I guess I have to look at my not properly working tools.

Thank you for your answeres!
 
User avatar
bitcanon
just joined
Posts: 1
Joined: Sun May 14, 2023 9:49 am
Contact:

Re: 7.1beta4 monitor-traffic restApi

Sun May 14, 2023 10:23 am

I was also looking for an answer to the OPs exact question and I found a few additional things that I thought could be good to know.

1. Using "duration": "2s" will perform two one second measurements and return them in a list (indexed by the .section key). So, if we only want one measurement we set "duration": "1s".
2. We can use the .proplist property to filter out the exact information we want: rx-bits-per-second and tx-bits-per-second.

curl -k -u admin:password123 -X POST https://10.0.0.1/rest/interface/monitor-traffic \
  --data '{"interface": "ether1", "duration": "1s", ".proplist": ["name","rx-bits-per-second","tx-bits-per-second"]}'\
  -H "content-type: application/json"

# Result:
[{".section":"0","name":"ether1","rx-bits-per-second":"1486248","tx-bits-per-second":"4241672"}]
 
nullinger
just joined
Posts: 1
Joined: Sat Feb 10, 2024 11:58 pm

Re: 7.1beta4 monitor-traffic restApi

Sun Feb 11, 2024 12:21 am

@bitcanon: I think you could also use "once": true instead of "duration", which also removes the ".section" value in the result (ROS 7.13.4 here):
--data '{"interface": "ether1","once": true,".proplist": ["name","rx-bits-per-second","tx-bits-per-second"]}'

Who is online

Users browsing this forum: Bing [Bot], hzdrro and 4 guests