We've seen people extend the Session DB driver, to include the current user_id as a column in the session table, or 0 if no user logged in. You can then run a query with user_id <> 0 and timestamp < time() + 60, for users active in the last 60 seconds. You can change the number depending on what you consider "logged in".
For other session backends, it is either a lot more complicated, or impossible (in case of cookie based sessions).
Alternatively, extend your users table with a "last_active" column, and extend the perform_check() method of your auth class to update this column after a successful check. You can then run the query against the users table.
Something like:
protected function perform_check() { if ($result = parent::perform_check()) { // update the db here }