bandwhich Bandwidth by process

Version 0.23.1 · source

Start here

sudo bandwhich
Live bandwidth by process
Tab
Switch table layout
Space
Pause / resume
q
Quit
bandwhich -i <if>
Watch one interface
bandwhich -n
Skip DNS lookups
bandwhich -p
Processes table only
bandwhich -t
Show running totals

Concepts

  1. Packets sniffed on interface
  2. Socket port in /proc or lsof
  3. Process name, PID, remote host
How traffic gets a name

In the TUI

Tab
Rotate which table comes first
Three tables: processes, connections, remote addresses. Small terminals show fewer.
Space
Pause or resume the display
Use it to read a busy screen; totals stop while paused.
q
Quit
Ctrl+C
Quit (interrupt)

Run

sudo bandwhich
Start monitoring all interfaces
sudo env "PATH=$PATH" bandwhich
Keep your PATH under sudo
Needed when installed under ~/.cargo/bin and sudo says command not found.
bandwhich -i <if>
Listen on one interface
bandwhich -n
Do not resolve IPs to hostnames
bandwhich -s
Show DNS queries
bandwhich -d <ip>
Use this DNS server for lookups
bandwhich -r
Machine-friendlier text output
bandwhich -V
Print version
bandwhich -h
Short help (--help for detail)

Views and units

bandwhich -p
Show processes table only
bandwhich -c
Show connections table only
bandwhich -a
Show remote addresses table only
bandwhich -t
Show cumulative totals
bandwhich -u bin-bytes
Bytes, powers of 1024 (default)
bandwhich -u bin-bits
Bits, powers of 1024
bandwhich -u si-bytes
Bytes, powers of 1000
bandwhich -u si-bits
Bits, powers of 1000 (like ISP speeds)
bandwhich -p -t
Combine view and totals

Permissions

sudo bandwhich
Simplest: run as root
sudo setcap cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep $(command -v bandwhich)
Grant capabilities once (Linux)
Then run bandwhich as a normal user. Any user who can run it can see everyone's traffic, so avoid on shared machines.
getcap $(command -v bandwhich)
Check granted capabilities
sudo setcap -r $(command -v bandwhich)
Remove capabilities

Logging and debug

bandwhich -v
More log output (repeat for more)
bandwhich -q
Less log output (repeat for less)
bandwhich --log-to <file>
Write debug log to a file
bandwhich -vv --log-to <file>
Verbose debug log to a file

Recipes

Which program is eating my uplink
sudo bandwhich -i eth0 -p -n
Allow without sudo (Linux)
sudo setcap cap_sys_ptrace,cap_dac_read_search,cap_net_raw,cap_net_admin+ep $(command -v bandwhich)bandwhich
Watch DNS chatter
sudo bandwhich -s -c
Debug a failing start
sudo bandwhich -vv --log-to /tmp/bw.log# read /tmp/bw.log afterwards