This is a good idea, but there is no flag or something like this for logged in or not logged in users in the wordpress user database.
A possibility other CMS often use is to say users that where active in the last X (for example 20) minutes are shown as online. The problem is that the last active date is stored in the user metadata table as string value and is not of type datetime or something like this. So if you have a huge user database (in one of my cases > 10.000 users) this will slow down your system extremely because the sql query with >= operation at a string field is quite ineffective. Using this solution wordpress would have to store last active date in the correct type.
So there is not really a reliable, quick solution possible, I’m sorry.