Traffic accounting on interfaces

Hello,

I'm looking for some easy way how to get some traffic not IP based statistics, but traffic on every interface.
I can see accounted traffic with command:
/interface print stats
but results aren't scripting friendly. Of course there is possibility to use linux tools like cut, awk, etc, but maybe there is some more efficient way? :slight_smile:

My goal is to make some sql (mysql) database with hourly traffic on interfaces. Idea is to make some simple shell script to get data from router via ssh or in other way and feed it to db.

Thanks and Cheers!

Use as-value which outputs a semi-colon separated list of variables:

:put [/interface print as-value stats]

You could do something like this:

# Send commands to routerboard, save stats to file
ssh admin@10.10.10.10 "/file print file=stats;:delay 2s;/file set stats.txt contents=[/interface print as-value stats];"
# Download file from routerboard
sftp admin@10.10.10.10:stats.txt

Then use other command line tools to extract desired variables from stats.txt

If you’re going to be contacting external sources like MySQL, you might as well use the the API protocol, and one of the clients in particular.

If PHP is your programming language of choice, I’d reccomend my own client (see my signature), but obviously, I’m biased :wink: .

I’ve already described in another post in another topic how to continiously collect stats to be visualized later. Reworking that to collect summary hourly data instead should be easy.

Thanks guys!
At this moment I was looking for something similar as written by skot.
Only for me will be enough with:

ssh <ip> ":put [/interface print as-value stats]" > myfile

didn’t know trick with “:put … as-value”

But yes I can try to learn a little bit about API, only need to find time for education. :wink:

Cheers! :slight_smile: