awstats訪問日誌分析-haproxy,nginx後端的tomcat access日誌

使用場景:

   基於awstats的日誌訪問統計系統,用於分析統計網站頁面訪問量,爲後期擴展提供依據。

公司網站架構:

   一部分應用採用haproxy+tomcat,一部分採用nginx+tomcat(nginx通過域名分發請求都後端的非80端口)。

工作原理:

   應用部署服務器0點以後通過rsync方式把訪問日誌同步到awstats服務器,awstat根據之前定義好的配置文件進行分析統計。

日誌格式配置:

   A,haproxy + tomcat

     haproxy配置haproxy.cfg

     defaults
        .........
       option forwardfor # 從Http Header中獲得客戶端ip

        .........

     tomcat 配置server.xml(注意pattern由雙引號改爲單引號,以便awstats分析時候將包含空格的內容作爲一個字段分析)

       <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
              prefix="srv01_api.test.com_access_log." suffix=".log" pattern='%{X-Forwarded-For}i %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' resolveHosts="false"/>

    B, nginx + tomcat

       nginx配置nginx.conf

       log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';

       access_log  logs/client.test.com.access.log  main;

     tomcat無需配置。

awstats配置:

     單個分析域名配置 awstats.test.com.conf

       Include "awstats.common.conf"
       LogFile="/usr/local/awstats/tools/logresolvemerge.pl /usr/local/awstats/log/*test.com* |"
       LogType=W
       LogFormat="%host %other %logname %time1 %methodurl %code %bytesd"
       LogSeparator=" "
       SiteDomain="site.test.com"
       HostAliases="site.com"

awstats計劃任務:

      /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=site.test.com


使用經驗:

       A,日誌集中存放;有多個節點時,節點日誌文件名要不一樣。

       B,刪除重複多餘日誌。如果在haproxy前端還有代理服務器,需要刪除後端tomcat中包含代理服務器IP的重複日誌;同時刪除監控軟件訪問請求,比如nagios的check_http

       C,附件中爲awstats.common.conf



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