How to count authenticated and anonymous users currently online?

I would like to know how many anonymous users are online .

This would be more than enough to me, to know how many sessions are
still available.
If I could have the list of the ids of every active session, I could
easily build the list I need (by the getSessionDataByKey() method)...
I tried with something like :

<dtml-in "temp_folder.session_data.keys()">
A session.

but not even "manager" is allowed to execute that.

Even trying an External Method :

def activesessionlist( self):
return self.temp_folder.keys()

does not have any effect, instead :

def sessionperiod( self):
return self.temp_folder.getPeriodSeconds()

works right.

Could you please help me find out the list of active sessions? this is
driving me crazy...

Thank you guys,
Bingo! i did it. here i am putting the code snippet so that everybody can refer if they required.

Here is things is :-
If you want to get the count of total active user so you have to forcefully create a a session of anonymous user and then get the count of total stroed session which is present in session data manager object in zope.

sdm = self.context.session_data_manager

Create a new Session if it's not created

session = sdm.getSessionData(create=True)
sdm = self.context.session_data_manager
container = sdm._getSessionDataContainer()
container
<TransientObjectContainer at /temp_folder/session_data>
len(container.keys())

Regards,
Jitesh Agrawal

That will make a lot of writes to the database and could potentially bloat your database.

You might want to look into using something else for session storage.

You can look into something like https://pypi.python.org/pypi/collective.beaker/ so you're not writing to the ZODB for sessions.

Or some sort of redis integration.

Otherwise, OOTB, plone does not do any tracking like this for you as you've discovered.

Thanks for your recommendation, But I am obliged to use default Z2 Session functionality instead of other session storage.pridcut. Hence In my application the session time out in 5 minute so i think we could manage the session for anonymous user too.

Once again thanks for your recommendation i will definitely look into it.