您的位置:首页 > 理论基础 > 计算机网络

在CentOS 6上使用awstats分析httpd和tomcat日志(续)

2012-08-31 17:57 761 查看
3、其实,还可以使用LoadPlugin="graphgooglechartapi" 插件,利用google chart创建图表。








五、使tomcat的分析页面也显示浏览器和操作系统的图标
[align=left]由于tomcat的日志格式与apache的格式设置的不同,导致tomcat日志分析的时候出现如下情况:[/align]




1、本来以为是图片不对,在网上找了一天,发现并不和网上说的错误一致,所以还是自己想办法。
[align=left]苦苦纠结中,就想到了日志格式这点上:输出的日志并没有操作系统的版本,也没有浏览器的信息,awstats当然不能分析出其所对应的图标了。(*^__^*) 嘻嘻……[/align]
[align=left]Tomcat的默认日志格式类型与apache一样,都是common,然而awstats分析的是combined类型的。如上所知,我的tomcat类型就是common型的,所以要改为combined型的。[/align]
2、重新定义tomcat日志格式:
[align=left]<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"[/align]
[align=left]prefix="localhost_access_log." suffix=".txt"[/align]
[align=left]pattern="%h %l %u %t"%r" %s %b %{Referer}i %{User-Agent}i" />[/align]
[align=left]输出的日志为:[/align]
[align=left]10.100.0.7 - - [31/Aug/2012:13:34:29 +0800]"GET /docs/proxy-howto.html HTTP/1.1" 200 15550 http://10.100.10.10:8080/docs/setup.html Mozilla/5.0 (Windows NT 5.2; rv:13.0) Gecko/20100101 Firefox/13.0.1[/align]
3、这下就全好了,不能高兴的太早,要先测试一下:
[align=left]# cd /usr/local/awstats/wwwroot/cgi-bin[/align]
[align=left]# perl awstats.pl -update -config=buoqu.com[/align]
[align=left]Create/Update database for config "/etc/awstats/awstats.buoqu.com.conf" by AWStats version 7.0 (build 1.976)[/align]
[align=left]From data in log file "/var/log/httpd/localhost_access_log.2012-08-29.txt"...[/align]
[align=left]Phase 1 : First bypass old records, searching new record...[/align]
[align=left]Searching new records from beginning of log file...[/align]
[align=left]AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log.[/align]
[align=left]Your log file /var/log/httpd/localhost_access_log.2012-08-29.txt must have a bad format or LogFormat parameter setup does not match this format.[/align]
[align=left]Your AWStats LogFormat parameter is:[/align]
[align=left]1[/align]
[align=left]This means each line in your web server log file need to have "combined log format" like this:[/align]
[align=left]111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234 [/align]
[align=left]And this is an example of records AWStats found in your log file (the record number 50 in your log):[/align]
[align=left]203.208.60.231 - - [29/Aug/2012:00:02:47 +0800] "GET /front/magazine/getContent.htm?contentId=52253 HTTP/1.1" 200 18419 http://10.100.10.10:8080/docs/setup.html Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)[/align]
[align=left]Setup ('/etc/awstats/awstats.buoqu.com.conf' file, web server or permissions) may be wrong.[/align]
[align=left]Check config file, permissions and AWStats documentation (in 'docs' directory).[/align]
4、细心的朋友会发现,错误正好跟以前的相反。所以将我们以前定义的格式
[align=left]LogFormat ="%host %other %logname %time1 %methodurl %code"[/align]
[align=left]注释掉或者删掉,就用默认的格式即可。但是有一点,还必须知道:[/align]
[align=left]LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"[/align]
[align=left]%refererquot Referer page with format: "http://from.com/from.htm"[/align]
[align=left]%referer Referer page with format: http://from.com/from.htm[/align] [align=left]%uabracket User agent with format: [Mozilla/4.0 (compatible, ...)][/align]
[align=left]%uaquot User agent with format: "Mozilla/4.0 (compatible, ...)"[/align]
[align=left]%ua User agent with format: Mozilla/4.0_(compatible...)[/align]
[align=left]这里有格式的区别,如%refererquot %uaquot" 需要输出的日志有“”,而我们的日志是没有的,所以还要改变LogFormat格式,使其完全一致。[/align]
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %referer %ua"
这样之后,awstats才能完全真正的分析tomcat日志了。
效果如图:



本文出自 “无辜de心碎” 博客,请务必保留此出处http://chenjiuling.blog.51cto.com/3057028/978763
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: