Bandwidth Statistics
Monitoring how much bandwidth is being used is a common feature of many routers. The same thing can be done on an OpenBSD box quite easily. We'll install the "vnstat" daemon and tell it to monitor each interface.
# pkg_add vnstat
# vnstat -u -i em0
# vnstat -u -i em1
# vnstat -u -i em2
# vnstat -u -i em3
# chown _vnstat /var/db/vnstat/*
If you only care about WAN traffic statistics, just enable it for the egress interface, which is em0 in my case. Next, make any changes you want to the configuration file:
# vi /etc/vnstat.conf
I like to make things a bit more human-readable:
--- vnstat.conf Sat May 2 21:15:35 2015
+++ vnstat.conf Sat May 2 21:13:32 2015
@@ -28,7 +28,7 @@
# how units are prefixed when traffic is shown
# 0 = IEC standard prefixes (KiB/MiB/GiB/TiB)
# 1 = old style binary prefixes (KB/MB/GB/TB)
-UnitMode 0
+UnitMode 1
# output style
# 0 = minimal & narrow, 1 = bar column visible
@@ -37,11 +37,11 @@
OutputStyle 3
# used rate unit (0 = bytes, 1 = bits)
-RateUnit 1
+RateUnit 0
# maximum bandwidth (Mbit) for all interfaces, 0 = disable feature
# (unless interface specific limit is given)
-MaxBandwidth 100
+MaxBandwidth 0
# interface specific limits
# example 8Mbit limit for 'ethnone':
Be sure to add the rc.d script to your startup items, alongside dnscrypt-proxy.
# grep scripts /etc/rc.conf.local
pkg_scripts="dnscrypt_proxy vnstatd"
Finally, start the daemon.
# /etc/rc.d/vnstatd start
Wait a few minutes and it should start collecting data.
# vnstat -i em0
Database updated: Tue Jun 9 15:41:10 2015
em0 since 05/02/15
rx: 334.15 GB tx: 110.72 GB total: 444.88 GB
monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
May '15 265.71 GB | 53.94 GB | 319.66 GB | 125.14 KB/s
Jun '15 68.44 GB | 56.78 GB | 125.22 GB | 175.62 KB/s
------------------------+-------------+-------------+---------------
estimated 237.26 GB | 196.85 GB | 434.11 GB |
daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
yesterday 3.03 GB | 1.43 GB | 4.46 GB | 54.09 KB/s
today 2.68 GB | 134.89 MB | 2.82 GB | 52.28 KB/s
------------------------+-------------+-------------+---------------
estimated 4.11 GB | 205 MB | 4.31 GB |
That's all there is to it.