my access_log file has several of such lines... 10.10.11.69 [13/Sep/2011:09:52:48 +0530] "GET /icons/blank.gif HTTP/1.1" 304 - "http://10.10.10.14/production-logs/no2-pg-wallet/" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15"
I am trying to save the data in redis database. I can create an auto-incremented id and save the IP, timestamp, page r开发者_如何转开发esponse etc as shown below.
redis-cli incr next.news.id
set news:2:IP "10.10.11.69"
set news:2:timestamp "[13/Sep/2011:09:52:48 +0530]"
set news:2:request "GET /icons/blank.gif HTTP/1.1"
set news:2:response "304"
set news:2:page "http://10.10.10.14/production-logs/"
set news:2:browser "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15"
I have 2 questions:
1) How do I automate the process of storing access_log to redis?
2) How do I know how many hits I have received to page "production_logs"?
How do I automate the process of storing access_log to redis?
You would probably have to create some script/program which would do your set of commands each time the new log entry is created or do this in batch after some time (scheduled job for example).
How do I know how many hits I have received to page "production_logs"?
You can create a key which will consist of some prefix and page url (or hash of the url), for example url:{url or hash here}
, and use INCRBY
command on this key. In case you want to hash page url, you can store this stuff in redis hash data structure where one field would indicate name of the url and second would be used for storing hits count using HINCRBY
command.
精彩评论