Quota-based traffic usage alerts in LibreNMS

Out of the box, LibreNMS does not readily expose traffic transfer measurements – it is geared towards network operators who buy (and sell) transit bandwidth wholesale, and not really for the home-gamer who just wants to stay under their ISP’s data cap.

As per the documentation, LibreNMS’ billing module can be enabled in config.php, and this will allow us to track and historise data usage for an interface in a nice billing page. Once billing is enabled we can add a new bill: under Ports > Bills, hit ‘add new’ and select a device and interface to measure against (you can add more than one interface per bill). Select ‘quota’ if, like me, you are interested in total transfer (not 95th percentile traffic).

But what if we also want to generate alerts when a device/interface exceeds a given threshold? Well, then we also need to add the following macro in config.php (thanks to laf on ##librenms):

More detail – including screenshots – after the break:

Librenms add bill

Now we can add an alert using the macro that we entered in config.php. In the alert ‘entity’ field, enter ‘macros.bill_over_quota’, which will now return the device’s data usage as a percentage of its defined quota:

librenms add alert

Don’t forget to click the ‘And’ button to actually add the logic to to the rule.

Data transfer is not calculated retroactively, unfortunately, which is a shame if (like me) you have some accumulated traffic data, so your billing data will be incomplete for the current billing period.

Here is what is a ‘Bill’ looks like. The ‘Quick Graphs’ page shows us a traffic overview for the metered interface for the current billing period, then the previous (rolling) 24 hours and one month. It appears to use the existing RRDs as the data goes back to before the billing module was enabled. It’s really no different to the standard interface graph, other than it shows the average transfer rate:


‘Accurate Graphs’ shows the same thing, but renders the chart using a different graphing library. It appears to be just as accurate, though the data only appears to go back to the point at which the billing feature was enabled (perhaps it exists just to verify that the billing data looks OK):


‘Transfer graphs’ is where we get to the good stuff. Finally, we see data transfer, though not quite in the same periods as the previous two pages; now the first chart shows the current billing month up to the current day, then the same 24 hour and one month rolling views:


..Finally, on the ‘Historical Graphs’ page we see monthly data transfer. Note that I changed the ‘billing day’ of this device from the 16th to the 20th, and this seems to have resulted in doubled-up totals for those months.


Previous Post

Phone casing out of hot-melt glue

I'm travelling, and was getting desperate for a case for my phone (a Moto X) - I just couldn't find one anywhere, so thought I would try a technique I saw somewhere. The ... Read more

Next Post

Send Slack messages from Mikrotik RouterOS

This is a quick RouterOS script hack which I just wanted to get up online; it's not anywhere near perfect but it might be useful to others. My objective here was to post a ... Read more

Leave a Comment