views:

53

answers:

2

Is there an easy way to count the number of active users or guests (not logged in users) visiting my rails app?

Right now I have a way to count the number of logged in users in the last 15 minutes by having a last_seen_at column for the user. However I don't want to use the database to figure out the total number of active users or guests.

I am using Rails 3.

+2  A: 

In general, counting users seen in last X minutes is what you want. Ask yourself how would you like to define user who is online? They are not constantly connected to the server, they are only making some requests from time to time.

skalee
Well yeah. Last 15 minutes would be fine. I mean I guess I can have a model/table that logs every IP and touch the updated at column every time a user visits another page. But I dunno if this is the efficient.
kentor
I would just add columns last_seen_at and last_seen_from_ip to your user table and update it with raw (efficient) insert at every user's action.
skalee
+2  A: 

You can use Juggernaut (which uses Flash) to connect users web browsers to your ruby apps. Then you can iterate over all of the registered clients by using the show_clients method.

Preston Marshall
I don't know if Juggernaut even works for Rails 3. I tried it on a new app and it didn't seem to work.
kentor