Calculating data usage between interim and stop packets.

Alan DeKok aland at
Sat Dec 3 19:03:24 CET 2016

On Dec 2, 2016, at 10:47 PM, Anuruddha Premalal <anuruddhapremalal at> wrote:
> I'm trying to get users actual usage between accounting updates.

  Look at the difference between what's in the packet, and what's in SQL.  Thats it.

  Except that the NAS may lie to you occasionally... because NASes are dumb.

> With the
> folowing method,
> 1. Extended the python *preacct* method and filterout only interim updates
> and accounting stop packets.

  OK... that can be done in "unlang", too.

> 2. Get the current usage recorded(inputoctets, outputoctets) from the mysql
> databse for the accounting sessionid group by date and take the latest
> value.


> 3. Take the difference between received input and output octets and the
> valus in the database
> *tx*= new_input_octets - old_input_octets
> *rx*= new_output_octets - old_output_octets

  That should be simple enough.

> 3. Send a paylod to a message queue pnly if *tx, rx* values are positive.

  I don't know what that means, but OK...

> I am trying to use this method to avoid periodic database polling to
> perform this operation.

  Except that NASes don't need to send interim update packets.  They may send them... or not.  The updates may be regularly spaced... or not.

> The issue is - at point 2 sometimes(intermittently) it returns an empty
> record set even the session has already been started (already received an
> accounting start).

  Then one of the following two situations is happening:

a) the data isn't in the database

b) the data is in the database, but isn't being returned.

> Is freeradius clearing the existing accouting record from the database as
> soon as it receives an accounting interim packet


  There is no magic here.  All of the things that the server does is visible in the configuration files, and in the debug output.

  As always, if you want to see why something is happening, read the debug output.

  Alan DeKok.

More information about the Freeradius-Users mailing list