Skip to content

jibreil/vnstat-alert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vnStat Alert

What is it?

This is a simple python script to control data usage by shutting down the machine when a set limit is reached and sends an email alert to the admin.

Requirements

  • vnStat

vnStat Configuration

  1. Edit /etc/vnstat.conf
  • Change MonthRotate on line 10 to start date of billing period (1-28)
  1. Setup vnStat monitoring
  • sudo vnstat -u -i eth0
    • Replace eth0 with network interface to be monitored, the command vnstat --iflist will show all available network interfaces
  1. Start the vnStat daemon and set to run on boot
  • sudo vnstatd -d
  • Add vnstat -d above exit 0 line in /etc/rc.local

Script Configuration

  1. Change the number on Line 7 to the usage limit in GB (whole numbers only)
  2. Add script to crontab to run automatically
  • Add 5 * * * * /path/to/script.py to root crontab (sudo crontab -e)
    • Replace the 5 with how often you want the script to check usage in minutes
    • Replace /path/to/script.py with the actual path to the script (obviously)

Comments

  • Update and addition of conversion code is because vnStat uses GiB (gibibyte) rather than GB (gigabyte) and 1 GiB is more than 1 GB

Changelog

Version 2.0

  • Completely changed how script retrieves usage data

Version 2.1

  • Added conversion from GB to GiB within the script for more accuracy
  • Added units checking for MiB and GiB

Version 3.0

  • Cleanup and new README
  • Email capable version of script added

Licence

This software is licensed under the MIT License, you can view the license terms at https://jibreil.mit-license.org/ or, in the LICENSE.md file.

About

📈 simple python script to control data usage

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages