nginx 日志分析
时间:2010-08-24 来源:wizardzj
系统运行中,需要了解用户访问哪个页面比较多,耗时比较长。给优化提供参考
运行比较慢的往往是动态文件,本次我们集中在action页面,考虑到action 的url后面有不同的id值(前面都是一样的),我们需要做个url截断。
下面是分析代码的shell文件,前10位访问最多的
#!/bin/sh
>action.tmp
cat access.log|awk '{print $7}'|grep action| while read Line
do
svn_path=${Line%%\?*}
echo $svn_path>>action.tmp
done cat action.tmp|sort|uniq -c|sort -nr|head -n 10 line=${line%%\?*}截断line字符串,去掉?号后面的字符串(包括?),并把结果赋值给变量line 另外响应时间也是要关注的 需要在nginx里做配置,增加request_time项 http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
#!/bin/sh
>action.tmp
cat access.log|awk '{print $7}'|grep action| while read Line
do
svn_path=${Line%%\?*}
echo $svn_path>>action.tmp
done cat action.tmp|sort|uniq -c|sort -nr|head -n 10 line=${line%%\?*}截断line字符串,去掉?号后面的字符串(包括?),并把结果赋值给变量line 另外响应时间也是要关注的 需要在nginx里做配置,增加request_time项 http {
include mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
相关阅读 更多 +