Realtime Bandwidth per IP/MAC from SSH access?

Discuss the technical details of Gargoyle and ongoing development

Moderator: Moderators

Post Reply
vask
Posts: 45
Joined: Tue Jul 21, 2009 4:33 pm

Realtime Bandwidth per IP/MAC from SSH access?

Post by vask »

Gargoyle has already shown it is possible to get realtime Per IP/MAC bandwidth... however, the web interface does NOT yet suit my needs... I was wondering if there is a shell command I could use to display per IP/Mac Bandwidth information... Perhaps something like below that outputs the bandwidth used every second:

I found this post on the web:
# bandwidth -i vlan0 --ip 192.168.1.6
in 6 KB/s out 14 KB/s
in 4 KB/s out 9 KB/s
in 10 KB/s out 10 KB/s
Source: https://forum.openwrt.org/viewtopic.php?id=3741

Are there some commands I can issue to get this kind of information?

Eric
Site Admin
Posts: 1443
Joined: Sat Jun 14, 2008 1:14 pm

Re: Realtime Bandwidth per IP/MAC from SSH access?

Post by Eric »

I want to make something clear: when I posted about the "new bandwidth monitor", I was referring ONLY to the back-end. The front end should still be identical to before. I am planning improvements to the front end, but I need to get the back-end (which is now capable of doing what you want, where it wasn't before) working properly, and fix all relavent bugs before proceeding. I believe I've already fixed a lot of them, but for the near future I'm going to focus on bug-fixes before implementing the new and improved front-end for the bandwidth monitor. Please be patient.

However... as you request, you CAN do this with the new back-end.

Try running these commands (note there are 3 commands below, but 2 are long, and they wrap):

Code: Select all

wan_if=$(uci -P "/var/state" get network.wan.ifname)

iptables -I FORWARD -o $wan_if -m bandwidth --id upload_traffic --reset_interval 2 --intervals_to_save 449 --type "individual_src"

iptables -I FORWARD -i $wan_if -m bandwidth --id download_traffic --reset_interval 2 --intervals_to_save 449 --type "individual_dst"
You may need to put them in an init script to run when the router boots up.

Then, after you have initialized those iptables rules you can run:

Code: Select all

bw_get -h -i upload_traffic 
to print real-time upload traffic data for the last 15 minutes (at 2 second intervals) and:

Code: Select all

bw_get -h -i download_traffic
to print download traffic data for the last 15 minutes (at 2 second intervals).

vask
Posts: 45
Joined: Tue Jul 21, 2009 4:33 pm

Re: Realtime Bandwidth per IP/MAC from SSH access?

Post by vask »

I thought I might paste some output... After I rebooted the router

Code: Select all

root@OpenWrt:~# iptables -I FORWARD -i eth0 -m bandwidth --id upload_traffic --reset_interval 2 --intervals_to_save 10 --type "individual_dst"
root@OpenWrt:~# bw_get -h -i upload_traffic
upload_traffic 192.168.4.125  
0	Thu Sep  3 23:07:38 2009	Thu Sep  3 23:07:40 2009
1088	Thu Sep  3 23:07:40 2009	Thu Sep  3 23:07:42 2009
0	Thu Sep  3 23:07:42 2009	Thu Sep  3 23:07:44 2009
0	Thu Sep  3 23:07:44 2009	Thu Sep  3 23:07:46 2009
0	Thu Sep  3 23:07:46 2009	Thu Sep  3 23:07:48 2009
0	Thu Sep  3 23:07:48 2009	Thu Sep  3 23:07:50 2009
46	Thu Sep  3 23:07:50 2009	Thu Sep  3 23:07:52 2009
0	Thu Sep  3 23:07:52 2009	Thu Sep  3 23:07:54 2009
0	Thu Sep  3 23:07:54 2009	Thu Sep  3 23:07:56 2009
0	Thu Sep  3 23:07:56 2009	Thu Sep  3 23:07:58 2009
0	Thu Sep  3 23:07:58 2009	(Now)

upload_traffic 192.168.4.144  
32556	Thu Sep  3 23:07:38 2009	Thu Sep  3 23:07:40 2009
33508	Thu Sep  3 23:07:40 2009	Thu Sep  3 23:07:42 2009
30973	Thu Sep  3 23:07:42 2009	Thu Sep  3 23:07:44 2009
33801	Thu Sep  3 23:07:44 2009	Thu Sep  3 23:07:46 2009
34381	Thu Sep  3 23:07:46 2009	Thu Sep  3 23:07:48 2009
34767	Thu Sep  3 23:07:48 2009	Thu Sep  3 23:07:50 2009
32353	Thu Sep  3 23:07:50 2009	Thu Sep  3 23:07:52 2009
32256	Thu Sep  3 23:07:52 2009	Thu Sep  3 23:07:54 2009
33799	Thu Sep  3 23:07:54 2009	Thu Sep  3 23:07:56 2009
32176	Thu Sep  3 23:07:56 2009	Thu Sep  3 23:07:58 2009
6503	Thu Sep  3 23:07:58 2009	(Now)
bw_get seems to output data on all connected ip addresses connected so you can see a nice overall view with a single command. =)

The output from the bw_get command can get really big really fast depending on:
--reset_interval
--intervals_to_save

I tried with [--reset_interval 1] but it gave me zero every other sample it took while streaming music from so I changed it to [--reset_interval 2] and the data looked more accurate (See above).

I could NOT figure out how to modify the initial command without first rebooting the router. I tried the following but I do not think my router liked it:
iptables -F

How can I reissue the iptables command safely without rebooting the router so I can change the iptables command variables?

I also made the following feature request to openwrt:
https://dev.openwrt.org/ticket/5787

Post Reply