在CentOS 6上使用awstats分析httpd和tomcat日誌(續)

3、其實,還可以使用LoadPlugin="graphgooglechartapi" 插件,利用google chart創建圖表。

五、使tomcat的分析頁面也顯示瀏覽器和操作系統的圖標
由於tomcat的日誌格式與apache的格式設置的不同,導致tomcat日誌分析的時候出現如下情況:

1、本來以爲是圖片不對,在網上找了一天,發現並不和網上說的錯誤一致,所以還是自己想辦法。
苦苦糾結中,就想到了日誌格式這點上:輸出的日誌並沒有操作系統的版本,也沒有瀏覽器的信息,awstats當然不能分析出其所對應的圖標了。(*^__^*) 嘻嘻……
Tomcat的默認日誌格式類型與apache一樣,都是common,然而awstats分析的是combined類型的。如上所知,我的tomcat類型就是common型的,所以要改爲combined型的。
2、重新定義tomcat日誌格式:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t&quot;%r&quot; %s %b %{Referer}i %{User-Agent}i" />
輸出的日誌爲:
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
3、這下就全好了,不能高興的太早,要先測試一下:
# cd /usr/local/awstats/wwwroot/cgi-bin
# perl awstats.pl -update -config=buoqu.com
Create/Update database for config "/etc/awstats/awstats.buoqu.com.conf" by AWStats version 7.0 (build 1.976)
From data in log file "/var/log/httpd/localhost_access_log.2012-08-29.txt"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
AWStats did not find any valid log lines that match your LogFormat parameter, in the 50th first non commented lines read of your log.
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.
Your AWStats LogFormat parameter is:
1
This means each line in your web server log file need to have "combined log format" like this:
111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] "GET / HTTP/1.1" 200 1234
And this is an example of records AWStats found in your log file (the record number 50 in your log):
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)
Setup ('/etc/awstats/awstats.buoqu.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
4、細心的朋友會發現,錯誤正好跟以前的相反所以將我們以前定義的格式
LogFormat ="%host %other %logname %time1 %methodurl %code"
註釋掉或者刪掉,就用默認的格式即可。但是有一點,還必須知道:
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"
%refererquot Referer page with format: "http://from.com/from.htm"
%referer Referer page with format: http://from.com/from.htm
%uabracket User agent with format: [Mozilla/4.0 (compatible, ...)]
%uaquot User agent with format: "Mozilla/4.0 (compatible, ...)"
%ua User agent with format: Mozilla/4.0_(compatible...)
這裏有格式的區別,如%refererquot %uaquot" 需要輸出的日誌有“”,而我們的日誌是沒有的,所以還要改變LogFormat格式,使其完全一致。
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %referer %ua"
這樣之後,awstats才能完全真正的分析tomcat日誌了。
效果如圖:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章