I need to access the transfer rates associated with a firewall filter rule. The properties that I am referring to can be seen in winbox in the following place: ip/firewall/filter/ … choose a filter rule … go to the Statistics tab … Under that tab there is a graph displayed, and four numerical fields. I can access the “Bytes” and “Packets” fields with scripting. But I have not found any documentation on how to access the “Rate” field and “Packet Rate” field that can both be seen in winbox. In fact, they don’t even appear in the wiki as properties. But there must be some way to access them, since winbox displays them, or to calculate them.
In brief what I am trying to do is to periodically capture the the download data rate in Mb/s that is associated with a Connection Mark. Based on that data rate, I need to make certain decisions. Any suggestions are appreciated.
Okay … So I scripted a workaround, where I run a script on a schedule every few seconds, and calculate the avg Rate in kbps over that period. See below. It’s self explanatory.
If by some chance anyone knows how to access the “Rate” property in the Filter Rules directly, please share, as it would be one less script and shedule to run. Otherwise, I this is a fairly good workaround.
########################
:log info “START TEST SCRIPT”;
:log info ("Test Script Bytes0 = " . $Bytes0) ;
:log info ("Test Script Bytes1 = " . $Bytes1) ;
:local Interval;
#Get the value of the seconds in the time field. It is assumed that the schedule will have zero minutes and hours
:set Interval ( [:pick [/system scheduler get [/system scheduler find name=“NAME_OF_SCHEDULE”] interval] 6 8 ]);
:tonum $Interval;
:log info ("Test Script Interval = " . $Interval) ;
#Rate variable set to avg rate over time period in kbps
:set Rate ( ( ( ($Bytes1 - $Bytes0) / $Interval) * 8) / 1024);
:log info ("Test Script Rate = " . $Rate) ;
:log info “END TEST SCRIPT”;
######################
Please use code tags for code. Click </> button when code is selected ; is not neded, so removed. (only needed when multiple commands on same line)
and extra not needed else removed
Tab added to better see strukture.