Syed Jahanzaib Personal Blog to Share Knowledge !

August 26, 2014

Graphing FREERADIUS Online Users via MRTG

Filed under: Linux Related, Radius Manager — Tags: , — Syed Jahanzaib / Pinochio~:) @ 10:34 AM

Last Updated: 23-JUN-2016 / 11:20 am


Recently at a network where multiple NAS were implemented with single centralized billing system(radius Manager with Free radius as backend engine) , I configured MRTG to create graphs for each NAS and added Mikrotik DUDE system to monitor various instances of the target systems, but there was no single graph to monitor overall ONLINE users of all NASES.

MRTG was configured on main Billing system, to sort this I used the following bash script and tag it with the mrtg cfg script.


First create the script

mkdir /temp
touch /temp/

chmod +x /temp/
nano /temp/

Now paste the following code, [make sure to change the IP, ID and Password]

Note: I used this script for Radius Manager base freeradius billing system.

# Script to query online connected users in freeradius
# Syed Jahanzaib / aacable at hotmail dot com
# http://aacable . wordpress . com
# acquire online users whose accnt-stop time is null so consider it online : )
SESSIONS=`​mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use radius; SELECT username FROM $SQL_ACCOUNTING_TABLE WHERE acctstoptime IS NULL;" |wc -l`

Save & Exit.


Now create a MRTG cfg file and tag it with your master mrtg config file or run it as individual , its up to you and your local design.

# Total Radius Users
Target[Radius.users]: `/temp/`
Title[Radius.users]: Central Billing System Logged in Users by ZAIB (Total)
<H1> Central Billing System  Logged in Users (Total)</H1>
MaxBytes[Radius.users]: 1000
Colours[Radius.users]: B#8888ff,B#8888ff,B#5398ff,B#5398ff
Options[Radius.users]: gauge,nopercent,noo,integer,growright
LegendI[Radius.users]: Radius Logged in Users
YLegend[Radius.users]: Radius Logged in Users (Total)
Legend1[Radius.users]: Radius Logged in Users (Total)
Unscaled[Radius.users]: ymwd

Another Script to find online users, ALL, specific user. made customized for GT @ 20-DEC2017

# Script to query online conencted users in freeradius
# Syed Jahanzaib / aacable at hotmail dot com
# http://aacable . wordpress . com
#set -x
if [ -z "$USR" ]; then
echo "Please use following ...
./ all
./ username"
exit 1

mysql -u$SQLUSER -p$SQLPASS --skip-column-names -e "use $SQL_DB; SELECT username FROM $SQL_ACCOUNTING_TABLE WHERE acctstoptime IS NULL;" > $TMP
TOT=`cat $TMP | wc -l`

if [ "$USR" == "all" ]; then
echo "TOTAL Number of online users are - $TOT"
cat $TMP | sort | more
exit 1

if [ "$USR" != "all" ]; then
CHK=`cat $TMP |grep "$USR" | more`
if [ -z "$CHK" ]; then
echo "No User found in the SESSION list with this name ... Exiting"
echo " User Found ..."
cat $TMP |grep "$USR" | more

Syed Jahanzaib


  1. Syed. I have been following yopur blog a long time and use some scripts of yours. I had in the past a Ubuntu 12 with squid3, last week I had to format my linux and put Ubuntu 14 with squi3.3.8, after that, my proxy never worked like was working before. Do you have some tutorial or blog that shows a good step-by-step of a clean install of these two ? cheers mate.


    Comment by Patrick — August 26, 2014 @ 4:14 PM

  2. Hi, Any option to graph Hotspot or pppoe users from Mikrotik connected to radius?


    Comment by Sankar S — September 1, 2014 @ 10:36 AM

  3. Syed, I don’t have a good way to reach you, so I am posting here, a question. I cannot find a good example for what I want. I have mikrotik routers, behind firewalls, and some NOT behind firewalls. I want to have them check into a monitoring box such as The Dude or Nagios. If Dude or Nagios doesn’t have a checkin from the mikrotik for x amount of minutes, then it can send an alert. I see you have done some monitoring using netwatch, but if the internet is down, then a message will not be sent from the mikrotik until the network comes back up. This way, my cloud monitoring boxes can send an alert “internet at X is having issues because mikrotik X didnt check in”. I cannot actively monitor them from a server/client perspective. So I want them to be monitored based on their url fetch to my monitoring server, or some other method.

    What are your thoughts on an option like that? I would like to use The Dude if possible. Thank you in advance. And thank you for sharing your knowledge on this blog.


    Comment by Jon — September 24, 2014 @ 2:20 AM

  4. Hi guys, I case you need a radius manager billing system, you can try radius manager billing system, they have free trial. I hope you will enjoy it.


    Comment by rachelrubio — January 29, 2015 @ 6:30 AM

  5. Hello – I wrote a similar script but have not implemented it yet, how often does your script run? if someone logs on and off in-between the scripts run times they would not be included in the graph?

    Also – how intensive on the hardware is the script? I have over 2000 active users at a time and I worry about hardware issues.



    Comment by JimmyC — January 14, 2016 @ 9:10 AM

    • its a very simple script which only checks for online users in freeradius system, and make its graphs. Default MRTG polls data in 5 minute interval and shows average value (within the data of 5 minutes). It does not put any load , no matter how much thousands of users you have online. it only takes the ONLINE numbers and graph it.
      if you use RRD you can reduce the 5 minutes interval to 1 minute also.


      Comment by Syed Jahanzaib / Pinochio~:) — January 14, 2016 @ 11:05 AM

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: