1. Install vnstat via mac ports
sudo port install vnstat2. Assuming the default interface to be monitored is en0, open the vnstat.conf file under /opt/local/etc/vnstat.conf and update the parts
# default interface3. Run the below command which will start monitoring en0
Interface "en0"
# location of the database directory
DatabaseDir "/opt/local/var/db/vnstat"
sudo vnstat -u -i en04. Now to run this as a service so that it starts up automatically at boot we can create a user daemon. In case of GNU/Linux, such scripts are present in /etc/init.d where as in OS X it's in /Library/LaunchDaemons.
sudo vim /Library/LaunchDaemons/local.vnstat.plistUse the file content for local.vnstat.plist file as given below
<?xml version="1.0" encoding="UTF-8"?>5. Change owner and group to root and wheel respectively.
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.vnstat</string>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/vnstat</string>
<string>-u</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
</dict>
</plist>
sudo chown root:wheel /Library/LaunchDaemons/local.vnstat.plist6. Use lauchctl to start the daemon
sudo launchctl load /Library/LaunchDaemons/local.vnstat.plistTo stop the daemon use unload.
sudo launchctl unload /Library/LaunchDaemons/local.vnstat.plistCheck the usage with
vnstat #lists complete usageThe 'estimated' data given is a prediction that vnstat calculates in realtime looking at the usage, hours etc.
vnstat -d #lists daily usage
To check whether the daemon is running use
sudo launchctl list | grep vnstat