New Widget Proposal - ISP Quota / Failover
-
Most ISPs mandate a monthly quota cap on their lines, and though vnstat includes a single monthly rotation for tracking, it's crude and not very informative. I currently use one primary with a hard cap of 1280GB/mo and a secondary with throttling after 300GB/mo as my failover. I've already made a widget to illustrate this. My only problem is outside of editing, I can't setup a configure option so I can choose which interfaces to include, their corresponding limits (Cycle Total, optional infinite) and what day of the month is their monthly rotation (default 1st). Maybe even include a refresh interval setting too.

I'm also including the .php and .inc files freely and w/o reservation so others may benefit and/or edit to their liking, or Netgate may decide to pursue inclusion on their own. I also have failover shell scripts for this scenario if people are interested, though I caution that with editing, you use at your own risk. The files posted are stable as-is, but you must edit to change the interfaces to match your own setup (mine are bxe1 and re0), and the array for interfaces is expandable if you know your php.
-
@djgans said in New Widget Proposal - ISP Quota / Failover:
Most ISPs mandate a monthly quota cap on their lines
Are we talking US of A? I didn't think ISP quota is still thing (in Europa).
But good work and seems helpful, even worth including in pfSense itself. Maybe open an issue/feature on redmine.pfsense.org?
-
@patient0 Let me preface that by hard cap, I mean the ISP (Cox in my case) won't cut me off, but they start adding 50GB chucks automatically at $10 a piece for the overage, whereas my failover (TMO) is unlimited, but throttles at their service limit. Yes, this is US of A. This is convenient for me as Cox is $90+/mo and TMO's "Backup Internet" option is $15/mo. Yes, I have tried load-balancing, but w/o going into specifics, I found it impractical to implement it the way I want, so failover works.
-
Newly updated widget file. This has some corrections involving infinite limits, logic and functions. As before, it is stable, but must be edited for your setup; I have not included any AJAX code to allow for Dashboard configuration due to conflicts in how the widget pulls traffic stats (they'll just zero out). Same .inc file can still be used.
-
I like it, thank you.
First off my fixed line ISP, has a quota and no quota option, although I currently use the no quota option.
In addition sometimes if I need to, I will attach my phone as a fall back internet, like many sim packages I have a quota, so this will especially be useful for that.
-
Disregard previous file - found bad logic error generated by vnstat.
Fixed file below. -
Updated php file to fix a memory leak problem caused by overprocessing for loops on the whole vnstat database, which would lead to a widget crash.
vnstat_usage.widget.php.txt
-
@djgans Have you considered submitting this?
-
Slight mod for those that might want a little more flare, so this updated file has progress bars added along with the matching color behavior changes.
As an FYI, I don't recommend running this with more than just edge-facing interfaces. The more you add, the more bogged down the latency of the code gets. This unfortunately is a consequence of vnstat and the use of AJAX in the php code. There's also latency to having a traffic reading, which is as fast as I can poll it due to kernel timing issues.
Lastly, if I hadn't mentioned it, if you want an infinite limit for an interface, then set "cap_gb" => 0 for just that interface in the beginning array. The code will add an infinity symbol and treat the interface accordingly.
As for submitting this project, I have no vested interest in this project, it was for personal use reason and anyone may use it as they see fit.
I may still post my bash/php files for automatic quota failovers if anyone has an interest, but as before, use at you're own risk.
-
@djgans said in New Widget Proposal - ISP Quota / Failover:
As for submitting this project, I have no vested interest in this project, it was for personal use reason and anyone may use it as they see fit.
You've obviously put a lot of work into this, and I think the result is valuable. I only raise the contribution question because I think there are many people that could benefit from your work, but won't install it because it isn't included in the distribution. Or because they have to hand edit a file.

-
@djgans Also, having found the widget to be very useful, I've started making some minor tweaks to it. Would you like to have changes back?
-
@dennypage --- As before you're are welcome to make whatever changes you want since I've provided the widget code "as-is". If you wish to post your own contributions, again you're welcome to and I even encourage it.
As a background to this, the code is mostly "vibe-coding", however, I do have some programming skills, just not full support for PHP. I can debug most languages, so I reasonable worked through and trust the results I've gotten, since I've iterated it more than a few dozen times. The problem I've run into is getting the widget to a "configurable" state, which has proven difficult given the need for AJAX code.
-
@djgans said in New Widget Proposal - ISP Quota / Failover:
As before you're are welcome to make whatever changes you want since I've provided the widget code "as-is". If you wish to post your own contributions, again you're welcome to and I even encourage it.
Okay. I'll add it to my list and have a go when I can.
