On 23/01/2017 11:35, Haviaras Kostas wrote:
Hello, I would like somehow to count the online users inside the freeradius!
If this is a busy server, then I suggest you should look at rlm_redis as the backend. You can create a new redis "hash" for each username, with a hash key of <session-id> and the value of <timestamp> which is the time of the most recent Start or Interim-Update record. * On receiving Start or Interium-Update, update the key: HSET acct:<username> <unique-session-id> <timenow> * On receiving Stop, delete the key: HDEL acct:<username> <unique-session-id> * At login time, use a HLEN query to see how many sessions are currently active HLEN acct:<username> All the above can be done in unlang, without writing any new modules. Plus you probably want to deal with stale sessions, where for some reason the Stop record hasn't arrived, or a Stop and Interim-Update arrived in the wrong order. Either: * Periodically scan the acct:* keyspace to look for stale sessions (where timenow is more than say 3x the accounting interim update interval from your NAS), and delete them; and/or * after every HSET/HDEL also send "EXPIRE acct:<username> numsecs". But this will only clean up stale sessions if the user doesn't have any sessions open at all. HTH, Brian.