May 16 2009
Graph Number of Freeradius Sessions with MRTG
You can easily graph Freeradius number of active sessions with a simple shell script, if you store accounting data in a SQL database.
Use the script below for Mysql that you can easily adapt to other databases like Oracle or PostgreSQL. Check the complete list of supported databases by Freeradius.
#!/bin/bash
SQL_USERNAME=radius_username
SQL_DATABASE=radius
SQL_PASSWORD=your_password
SQL_SERVER=127.0.0.1
SQL_ACCOUNTING_TABLE=radacct
BACK_DAYS=5
SESSIONS=`mysql -BN -u$SQL_USERNAME -p$SQL_PASSWORD -h $SQL_SERVER $SQL_DATABASE -e \
"SELECT COUNT(*) FROM $SQL_ACCOUNTING_TABLE \
WHERE acctstoptime IS NULL \
AND Acctstarttime > NOW() - INTERVAL $BACK_DAYS DAY;"`
echo $SESSIONS
A certain number of sessions remain unclosed due to random packet losses, or network disconnections between the NAS and the Radius server. Sessions older than $BACK_DAYS are ignored to get the most accurate value.
The script returns the number of active sessions. It is then possible to graph this one value in MRTG that normally ask for two of them.
Offer you users upload/download graphs of their Internet network usage as well.
I need user live graph please help and contact