This is being written for a client who has an OpenBSD router using 2 Internet connections, both of which have monthly usage limits.
This is a nagios style plugin. The purpose is to monitor aggregate bandwidth for Internet users who have restrictions in place from their ISP. This does use a state file in the /tmp directory of the monitoring server so if you clear that directory on reboot you may need to make some adjustments.
I expect when done it will do the following:
Another nice feature of this simple plugin is that the perfdata provides realtime usage from the last check iteration. This can be used as a drop in replacement for check_rrdtraf or check_mrtgtraf + MRTG.
1) count the total usage of Internet on an interface since it was last reset
Today the plugin uses net-snmp command line tools and only v1/v2c is supported. I may add in v3 and/or pySNMP if anyone asks.
2) do a simple math calculation to see if the interface is currently over or under its usage alloted for the month. If over as a function of time, warn, if over absolutely - critical
3) reset the counter as needed
The underlying command used to get the data is `pfctl -vvsI -i <interface>`
Arguments:
There will no doubt need to be a sudoers rule so that the nagios user can run the check
-H host
There will have to be a /tmp file where the data is stored
-i interface
If ommitted the plugin will just return a list of available interfaces
Arguments:
-b bytes limit
This is the limitation imposed by your ISP. It is possible to append
a multiplier such as 10g to represent 10 gigabytes. Accepted multipliers
are as follows:
b or B for bytes
k or K for kilobytes
m or M for megabytes
g or G for gigabytes
t or T for terabytes
-c community string
-d enable debug
This really doesn't do much at this time
-p billing period
The billing period can be defined in 2 ways, daily or monthly. If you
specify a daily period it is assumed that you will also include an
hour in which that period begins/ends. Similarly if you specify a
monthly period it is assumed that you will provide a day on which the
billing period begins/ends. For example:
time interval to reset the counter... daily and monthly are the only options I need however it could maybe be done in cron format? or maybe something simplyer like m010000 for the first of the month at midnight and/or d1300 for daily at 1:00PM?
If you have a daily billing cycle that resets at 8:00PM you would use
the argument '-p d20'
interface
If you have a daily billing cycle that resets at midnight you would use
the argument '-p d0'
number of bytes alloted per usage period (from above)
If you have a monthly billing cycle that resets on the 15th of each
month you would use the argument '-p m15'
That should do it for me
If you don't specify this argument it is assumed that your usage period
is monthly and resets at the beginning of each month