# Bandwidth in real time



## Seeker (Sep 19, 2009)

The same way, as command 
	
	



```
top
```
 shows live cpu usage, I would like same type of command, that shows live bandwith usage


----------



## ale (Sep 19, 2009)

`$ systat -ifstat`


----------



## Seeker (Sep 19, 2009)

Thanks a lot!


----------



## Alt (Sep 19, 2009)

:scale mbit after it =)


----------



## DutchDaemon (Sep 19, 2009)

Or `netstat -I <interface> 1`, e.g. `netstat -I fxp0 1`


----------



## dennylin93 (Sep 20, 2009)

Some other options: net/nload and net-mgmt/iftop.


----------



## Seeker (Sep 20, 2009)

Thanks a lot guys!


----------



## HJess (Sep 21, 2009)

I use showtraf .. - http://www.freebsdsoftware.org/net/trafshow.html


----------



## Beastie (Sep 21, 2009)

ale said:
			
		

> `$ systat -ifstat`


This one's my favorite, but I usually add a number at the end (`% systat -ifstat x`) to get updates every x seconds.


----------



## ale (Sep 21, 2009)

Beastie said:
			
		

> This one's my favorite, but I usually add a number at the end (`% systat -ifstat x`) to get updates every x seconds.


I do this too. And almost always x=1.


----------



## jrm@ (Nov 29, 2012)

Does anyone know of a way to get the current up/down rate for an interface without the curses interface? I would like the current rates reported once, so I can grab these values in a script.


----------



## wesbl (Aug 12, 2018)

jrm@ said:


> Does anyone know of a way to get the current up/down rate for an interface without the curses interface? I would like the current rates reported once, so I can grab these values in a script.


Sorry If I bump, but I need too something that I can grab in a script, any advice?


----------



## Bobi B. (Aug 12, 2018)

net/bmon is pretty nice.


----------



## VladiBG (Aug 12, 2018)

net/vnstat

https://humdi.net/vnstat/


----------



## SirDice (Aug 13, 2018)

wesbl said:


> Sorry If I bump, but I need too something that I can grab in a script, any advice?


`netstat -I <iface>`


----------



## wesbl (Aug 13, 2018)

SirDice said:


> `netstat -I <iface>`


How can I grep and awk download/upload speed? I need it for a status bar


----------



## chrbr (Aug 13, 2018)

Dear wesbl,
you could use net/ifstat and run

```
ifstart -b 1 1 | tail -n 1
```
It reports the speed in kbit/s once in the last line which is taken by tail. I use it like that.


----------



## wesbl (Aug 13, 2018)

chrbr said:


> Dear wesbl,
> you could use net/ifstat and run
> 
> ```
> ...


And If I want to visualize download or upload only?


----------



## jrm@ (Aug 14, 2018)

wesbl said:


> And If I want to visualize download or upload only?


For just the download rate, you can use `ifstat -i wlan0 -b 1 1 | awk 'NR%3==0 {print $1}'`.  For upload only, replace $1 with $2.  Replace wlan0 with your interface.

EDIT: So the above works in that it extracts what you want from the ifstat output, but what ifstat reports does not seem very accurate, at least with a count of 1.  Maybe it takes a few updates before it reports something accurate?


----------



## wesbl (Aug 14, 2018)

jrm@ said:


> For just the download rate, you can use `ifstat -i wlan0 -b 1 1 | awk 'NR%3==0 {print $1}'`.  For upload only, replace $1 with $2.  Replace wlan0 with your interface.
> 
> EDIT: So the above works in that it extracts what you want from the ifstat output, but what ifstat reports does not seem very accurate, at least with a count of 1.  Maybe it takes a few updates before it reports something accurate?



Oh really thanks!
What about if I want to visualize the value in KiloBytes or maybe MegaBytes?

EDIT
Looks like the value it shows with your command are not the download/upload speed. I state that I've changed wlan0 with mine (re0).


----------



## jrm@ (Aug 14, 2018)

According to ifstat(1), the rates are reported in kbytes/sec by default and with the -b flag, kbits/sec.  If you wanted MB/s, you could use something like `ifstat -i wlan0 1 1 | awk 'NR%3==0 {print $1/1024}'`, but a quick test shows inaccurate rates.  You might play around with a larger count.  Maybe something like this untested command: `ifstat -i wlan0 1 3 | awk 'NR%5==0 {print $1}'`.


----------



## wesbl (Aug 15, 2018)

jrm@ said:


> According to ifstat(1), the rates are reported in kbytes/sec by default and with the -b flag, kbits/sec.  If you wanted MB/s, you could use something like `ifstat -i wlan0 1 1 | awk 'NR%3==0 {print $1/1024}'`, but a quick test shows inaccurate rates.  You might play around with a larger count.  Maybe something like this untested command: `ifstat -i wlan0 1 3 | awk 'NR%5==0 {print $1}'`.



Thanks a lot, I've tried to put your commands inside my bar bash script but with  ifstat it takes seconds before it shows all values. Is it possible to show all the other values without waiting for "download" and "upload"? Here my script:


```
#!/bin/bash

while true; do
»···date="$(date "+%a %d-%m-%Y %H:%M:::%Z")"
»···volume="$(mixer | grep 'pcm' | awk '{print $7}')"
»···cputemp="$(sysctl -a | grep 'dev.cpu.5.temperature' | awk '{print $2}')"
»···memusage="$(freecolor -m -o | grep 'Mem' | awk '{print $4}')"
»···memtotal="$(freecolor -m -o | grep 'Mem' | awk '{print $2}')"
»···ipaddress="$(ifconfig re0 | grep 'inet' | awk '{print $2}')"
»···download="$(ifstat -i re0 1 3 | awk 'NR%5==0 {print $1}')"
»···upload="$(ifstat -i re0 1 3 | awk 'NR%5==0 {print $2}')"

»···xsetroot -name " ${download}KB/s ${upload}KB/s ${memusage}MB/${memtotal}MB ${cputemp} $ipaddress $volume $date "
»···sleep 1
done
```


----------

