bmon – Bandwidth Monitor and Rate Estimator
In the world of networking, having a clear understanding of bandwidth usage is crucial. Whether you are a network administrator managing a large-scale infrastructure, a developer troubleshooting network-related issues, or an individual interested in monitoring your home network traffic, a reliable bandwidth monitoring tool is essential. bmon (bandwidth monitor) is one such tool that serves as a real-time bandwidth monitor and rate estimator, providing detailed information about network traffic on Unix-like systems.
This blog will explore bmon in depth, covering its installation, basic concepts, common and best practices, and example usages to help you make the most out of this powerful network monitoring tool.
Table of Contents#
Installation#
bmon is available in the default repositories of most Linux distributions and on macOS via Homebrew. The package managers below install the latest version available for each distro (currently v4.0).
On Ubuntu/Debian#
You can use the apt package manager to install bmon. Open your terminal and execute the following commands:
sudo apt update
sudo apt install bmonOn Fedora#
On Fedora, install bmon with dnf:
sudo dnf install bmonOn RHEL/CentOS Stream/AlmaLinux/Rocky Linux#
For modern RHEL-based distributions (RHEL 9, CentOS Stream 9, AlmaLinux 9, Rocky Linux 9), use dnf. On RHEL-compatible systems, enable the EPEL repository first if the package is not available:
sudo dnf install epel-release
sudo dnf install bmonNote: CentOS Linux 8 reached end of life in December 2021. If you are still running CentOS 8, consider migrating to CentOS Stream, AlmaLinux, or Rocky Linux.
On Arch Linux#
sudo pacman -S bmonOn macOS#
If you are using macOS, you can install bmon via Homebrew. First, make sure Homebrew is installed, then run:
brew install bmonBuilding from Source#
To install the latest version from the GitHub repository, clone the source and build it:
git clone https://github.com/tgraf/bmon.git
cd bmon
./autogen.sh
./configure
make
sudo make installOn Debian/Ubuntu, install build dependencies first:
sudo apt install build-essential make libconfuse-dev libnl-3-dev libnl-route-3-dev libncurses-dev pkg-config dh-autoreconfOn Fedora/RHEL-based systems:
sudo dnf install make libconfuse-devel libnl3-devel libnl-route3-devel ncurses-develBasic Concepts#
Interface Monitoring#
bmon allows you to monitor network interfaces individually. Each network interface on your system, such as Ethernet (eth0), Wi-Fi (wlan0), or virtual interfaces, can be tracked separately. It provides real-time data on the amount of data being sent and received through these interfaces.
Rate Estimation#
One of the key features of bmon is its ability to estimate network traffic rates. It calculates the rate at which data is being transferred (e.g., in bits per second or bytes per second) both for incoming (receive, RX) and outgoing (transmit, TX) traffic. By default, rates are displayed in bytes per second; use the -b flag to switch to bits per second.
Statistics Display#
The tool presents various statistics about network traffic, including the current rate, average rate over a certain period, peak rate, and the total amount of data transferred since the monitoring started. Press d in the interactive interface to toggle detailed statistics such as errors and dropped packets.
Input Modules#
bmon collects data through input modules:
- netlink — Uses the Netlink protocol to collect interface and traffic control statistics from the kernel. This is the default module on Linux.
- proc — Reads statistics from
/proc/net/dev. This is a legacy fallback if Netlink is unavailable.
Output Modules#
bmon supports multiple output modes:
- curses — An interactive text-based user interface with real-time graphs. This is the default output mode.
- ascii — A simple text output for human consumption, useful when curses is not available.
- format — A fully scriptable output mode for piping to other programs or files.
Common Practices#
Simple Monitoring#
To start monitoring all available network interfaces, simply run the bmon command in your terminal:
bmonThis will open an interactive interface showing real-time traffic statistics for each interface. Use the arrow keys to select an interface and view its detailed graph. Press ? to display the quick reference guide, and q to quit.
Specific Interface Monitoring#
If you want to monitor only a specific network interface, say eth0, you can use the following command:
bmon -p eth0You can also use wildcard patterns to match multiple interfaces:
bmon -p 'eth*'Display Rates in Bits Per Second#
By default, bmon displays rates in bytes per second. To show rates in bits per second (common for network bandwidth comparisons), use the -b flag:
bmon -b -p eth0ASCII Text Output#
If you are running bmon over SSH or in a non-interactive terminal, use the ASCII output mode:
bmon -p eth0 -o asciiOutput to a File#
If you want to save the monitoring data for later analysis, you can use the format output module to generate CSV-like output:
bmon -o 'format:fmt=$(element:name);$(attr:rx:rate);$(attr:tx:rate)\n' > network_stats.csvThis will generate a file with network traffic statistics.
Best Practices#
Regular Sampling#
To get accurate rate estimates, it's advisable to adjust the sampling interval. You can set the sampling interval using the -r (or --read-interval) option. For example, to set the sampling interval to 1 second, use:
bmon -r 1Filtering Unnecessary Interfaces#
If you have multiple network interfaces on your system, some of which you are not interested in monitoring, you can use the -p option to specify only the relevant interfaces. This helps in reducing clutter and focusing on the important data.
Automating Monitoring#
For long-term monitoring, you can create a shell script that runs bmon at regular intervals and appends the data to a file. This can be useful for generating historical reports.
#!/bin/bash
while true; do
bmon -o 'format:fmt=$(element:name);$(attr:rx:rate);$(attr:tx:rate)\n' >> network_stats.csv
sleep 3600 # Run every hour
doneTip: For persistent historical tracking, consider using
vnstat, which runs as a background service and records traffic data automatically.
Example Usage#
Monitoring Home Network Usage#
Suppose you want to monitor your home Wi-Fi network usage. First, find out the name of your Wi-Fi interface (usually wlp2s0 or wlan0). Then, start monitoring with a 2-second sampling interval:
bmon -p wlan0 -r 2This will show you real-time traffic statistics for your Wi-Fi network, including incoming and outgoing data rates. Press d to view detailed statistics such as errors and dropped packets.
Troubleshooting High Network Traffic#
If you suspect that a particular application or device on your network is causing high network traffic, you can start bmon to identify the interface with abnormal traffic. Then, by combining bmon with other network analysis tools (such as tcpdump), you can pinpoint the source of the traffic.
# First, monitor all interfaces
bmon
# Then, if you notice high traffic on eth0, use tcpdump to capture packets
sudo tcpdump -i eth0Scripting with Format Output#
For automated monitoring scripts, use the format output module to produce machine-readable output:
bmon -p eth0 -r 5 -o 'format:fmt=$(element:name)\t$(attr:rx:rate)\t$(attr:tx:rate)\n'This prints the interface name, RX rate, and TX rate every 5 seconds, which can be piped to other tools for processing.
Conclusion#
bmon is a versatile and powerful bandwidth monitoring tool for Unix-like systems. It provides a simple yet effective way to keep track of network traffic in real time, whether you are dealing with a small home network or a large-scale enterprise infrastructure. Its interactive curses interface, wildcard-based interface selection, and scriptable format output make it suitable for both interactive troubleshooting and automated monitoring workflows. By following the common and best practices outlined in this blog, you can make the most out of bmon and gain valuable insights into your network traffic.
Reference#
- The official
bmonproject page: https://github.com/tgraf/bmon - bmon man page: https://man.archlinux.org/man/bmon.8.en
- Ubuntu official documentation for package management: https://ubuntu.com/server/docs/package-management
- Homebrew official documentation: https://brew.sh/