# How do you get realtime visitor stats in RoR?

**URL:** <https://www.ruby-forum.com/t/how-do-you-get-realtime-visitor-stats-in-ror/195613>\
**Category:** Rails\
**Created:** [September 26, 2010, 10:38pm UTC](https://www.ruby-forum.com/t/how-do-you-get-realtime-visitor-stats-in-ror/195613 "2010-09-26T22:38:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [September 26, 2010, 10:38pm UTC](https://www.ruby-forum.com/t/how-do-you-get-realtime-visitor-stats-in-ror/195613/1 "2010-09-26T22:38:58Z")

</div>

I have found some projects as [http://www.railstat.com/](http://www.railstat.com/) but seem not  
updated. I have used Google Analytics too, but it is not realtime and it  
do not give some important information as IP address.

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [September 27, 2010, 4:06am UTC](https://www.ruby-forum.com/t/how-do-you-get-realtime-visitor-stats-in-ror/195613/2 "2010-09-27T04:06:30Z")

</div>

Juan K. wrote:

> I have found some projects as [http://www.railstat.com/](http://www.railstat.com/) but seem not  
> updated. I have used Google Analytics too, but it is not realtime and it  
> do not give some important information as IP address.

I grab them out of the logs using a cron job which mails the results to  
me.

Norm

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [September 27, 2010, 6:15am UTC](https://www.ruby-forum.com/t/how-do-you-get-realtime-visitor-stats-in-ror/195613/3 "2010-09-27T06:15:52Z")

</div>

Can you share the script that you use to parse the logs?

Norm S. wrote:

> I grab them out of the logs using a cron job which mails the results to  
> me.

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [September 28, 2010, 12:41am UTC](https://www.ruby-forum.com/t/how-do-you-get-realtime-visitor-stats-in-ror/195613/4 "2010-09-28T00:41:42Z")

</div>

Juan K. wrote:

> Can you share the script that you use to parse the logs?
> 
> Norm S. wrote:
> 
> > I grab them out of the logs using a cron job which mails the results to  
> > me.

This is just a simple script that greps for invocation of the login  
controller and mails it out. It also picks out errors (the only the  
string .html comes up) an tells me about them. I would not call it  
realtime as I just run it once a day in the dead of night (at least for  
me if not for everyone).

#!/bin/sh

# things to do for nightly maintenance

# parse options

E\_WRONGARGS=85 # Non-numerical argument (bad argument format).  
NARGS=1  
ARGS=“customer”

if [$# -ne $NARGS]  
then  
echo “Usage: `basename $0` $ARGS”  
exit $E\_WRONG\_ARGS  
fi

CUST=$1  
DATE=`date +%Y-%m-%d`  
FILES=`grep -l ${DATE} ${CUST}/log/production*`

grep “Processing LoginController#login (for [0-9.]\* at ${DATE} [0-9:]\*)  
[POST]” ${FILES} \> /tmp/fil  
grep ‘.html’ ${FILES} \>\> /tmp/fil  
mail --subject=${CUST}\_log.${DATE} $MAIL\_ADDRESS \< /tmp/fil  
rm /tmp/fil
