分析网站日志
(1)、统计访问URL统计PV
1 | # awk '{print $7}' fresh.yilumall.com-access_log |wc -l |
1 | # awk '{print $1}' fresh.yilumall.com-access_log |sort|uniq -c|wc -l |
1 | # awk '{print $1}' fresh.yilumall.com-access_log |sort|uniq -c|sort -n -k 1 -r |more |
1 | # awk '{print $7}' fresh.yilumall.com-access_log |sort|uniq -c|sort -n -k 1 -r |more |
1 | # awk '{print $9}' fresh.yilumall.com-access_log |sort|grep 200 |wc -l |
(6)、根据时间段统计查看日志
下面以apache为例使用sed查看特定时间段的访问日志
1 | # sed -n '/24\/May\/2020:00:12:39/,/25\/May\/2020:00:[0-9][0-9]:[0-9][0-9]/p' fresh.yilumall.com-access_log |more |
需要注意的是如果起始时间在日志中不存在,则整个截取将返回0行结果。如果结束时间在日志中不存在,则会截取到日志的最后一条。所以在截取前得要找到日志中最合适的起始点和结束点,有时候为了方便可以使用[]匹配时间段。
在特定时间段中过滤相关信息
例如查看2020/5/24 0点 ~ 2020/5/25 0点网站登录页面login.html被访问的情况
1 | # sed -n '/24\/May\/2020:00:[0-9][0-9]:[0-9][0-9]/,/25\/May\/2020:00:[0-9][0-9]:[0-9][0-9]/p' fresh.yilumall.com-access_log |grep "/admin/login.html" |
查看2020/5/24 0点 ~ 2020/5/25 0点有哪些ip来访问站点,每个ip访问的次数
1 | # sed -n '/24\/May\/2020:00:[0-9][0-9]:[0-9][0-9]/,/25\/May\/2020:00:[0-9][0-9]:[0-9][0-9]/p' fresh.yilumall.com-access_log |grep "/admin/login.html" |awk '{print $1}'|sort |uniq -c |