I've installed vnstat
on my M1 MacBook Pro with Homebrew to monitor my network usage over time.
# Install vnstat on macOS with Homebrew.
brew install vnstat
Make sure you start the vnstat
service with brew for vnstat to monitor your network usage.
brew services start vnstat
vnstat
will be running in the background, and you'll have to wait days for it to gather statistics and be able to show you, for instance, the average monthly usage.
› vnstat -m
# gif0: Not enough data available yet.
After a few minutes, you'll see stats on vnstat
.
› vnstat -5
# en0 / 5 minute
#
# time rx | tx | total | avg. rate
# ------------------------+-------------+-------------+---------------
# 2023-03-19
# 12:45 839.44 MiB | 2.60 MiB | 842.04 MiB | 23.55 Mbit/s
# 12:50 226.26 MiB | 306.00 KiB | 226.56 MiB | 46.35 Mbit/s
# ------------------------+-------------+-------------+---------------
› vnstat -h
# en0 / hourly
#
# hour rx | tx | total | avg. rate
# ------------------------+-------------+-------------+---------------
# 2023-03-19
# 12:00 1.04 GiB | 2.90 MiB | 1.04 GiB | 28.10 Mbit/s
# ------------------------+-------------+-------------+---------------
› vnstat -m
# en0 / monthly
#
# month rx | tx | total | avg. rate
# ------------------------+-------------+-------------+---------------
# 2023-03 1.04 GiB | 2.90 MiB | 1.04 GiB | 28.10 Mbit/s
# ------------------------+-------------+-------------+---------------
# estimated 3.43 TiB | 9.56 GiB | 3.44 TiB |
I run the following command to clean up unneeded old Homebrew kegs on macOS.
brew cleanup --prune=all
But often get this error.
Error: Could not cleanup old kegs! Fix your permissions on:
Here's the tail of what the command returns when there are permissions issues.
==> This operation has freed approximately 395MB of disk space.
Error: Could not cleanup old kegs! Fix your permissions on:
/opt/homebrew/Cellar/dnsmasq/2.85
/opt/homebrew/Cellar/php/8.1.1
/opt/homebrew/Cellar/php/8.1.1.reinstall
/opt/homebrew/Cellar/php/8.1.3_1
/opt/homebrew/Cellar/php/8.1.4.reinstall
/opt/homebrew/Cellar/php@7.4/7.4.21_1
/opt/homebrew/Cellar/php@7.4/7.4.27.reinstall
/opt/homebrew/Cellar/php@7.4/7.4.28_1.reinstall
/opt/homebrew/Cellar/php@8.0/8.0.14
brew
won't use root
permissions for any operations.
This is what you'll see if you try to cleanup
with root.
sudo brew cleanup --prune=all
# Error: Running Homebrew as root is extremely dangerous and no longer supported.
# As Homebrew does not drop privileges on installation you would be giving all
# build scripts full access to your system.
What you have to do is to change the ownership of the problematic directories to your username instead of root
.
You can do that with sudo chown -R "$USER":admin /conflicting/dir
.
To solve the issues shown in my error above, I ran the following commands.
sudo chown -R "$USER":admin /opt/homebrew/Cellar/dnsmasq/2.85
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php/8.1.1
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php/8.1.1.reinstall
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php/8.1.3_1
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php/8.1.4.reinstall
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php@7.4/7.4.21_1
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php@7.4/7.4.27.reinstall
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php@7.4/7.4.28_1.reinstall
sudo chown -R "$USER":admin /opt/homebrew/Cellar/php@8.0/8.0.14
Then run brew cleanup --prune=all
again and everything should work.