網絡上雖然不少文章分別講到jboss7的訪問日誌如何配置,goaccess工具怎麼分析nginx/tomcat等日誌。
但將二者放在一塊兒即「經過goaccess分析jboss訪問日誌」的卻是沒搜索到。
本文經過三節來介紹:
1. jboss開啓訪問日誌功能。
2. goacess介紹及原理(我的理解的原理)
3. 如何使用goaccess解析分析jboss的access.log
參考:
http://chandank.com/application-server/tomcat/jboss-7-access-log-configuration
https://www.goaccess.io/html
一. 開啓jboss的訪問日誌功能
首先jboss7及以後版本相較以前版本發生比較大的調整,配置方式大不相同,此處展現jboss7及以後版本如何配置,
以前版本如何配置請自行搜索。
以standalone模式配置爲例
1. 配置文件所在路徑 ${jbossHome}\standalone\configuration
2. 打開standalone.xml ,找到 <virtual-server>節點
3. 在節點中加入以下內容
<access-log pattern="%a %t %U %s %D" prefix="access_log." rotate="true">
<directory path="." relative-to="jboss.server.log.dir"/>
</access-log>
4. 重啓便可看到${jbossHome}\standalone\log\目錄下生成access_loglinux
pattern即定義accessLog須要記錄哪些內容。具體參照以下
%a- Remote IP address
%A- Local IP address
%b- Bytes sent, excluding HTTP headers, or '-' if zero
%B- Bytes sent, excluding HTTP headers
%h- Remote host name (or IP address if resolveHostsis false)
%H- Request protocol
%l- Remote logical username from identd (always returns '-')
%m- Request method (GET, POST, etc.)
%p- Local port on which this request was received
%q- Query string (prepended with a '?' if it exists)
%r- First line of the request (method and request URI)
%s- HTTP status code of the response
%S- User session ID
%t- Date and time, in Common Log Format
%u- Remote user that was authenticated (if any), else '-'
%U- Requested URL path
%v- Local server name
%D- Time taken to process the request, in millis
%T- Time taken to process the request, in seconds
%I- current request thread name (can compare later with stacktraces)nginx
二. goaccess 介紹及原理
1.據稱linux下最好用的日誌分析工具
2.我見過用過的最好的日誌分析工具,簡單,快,很是靈活
3.分析結果生成的頁面很是精美,符合領導口味,本身也省事。
4.徹底免費,項目網站: https://www.goaccess.io/
訪問日誌分析原理:
要分析,首先要能提取並識別日誌中的有用信息。 而accessLog的特色就是日誌自己的格式相對固定。
好比上節我配置的jboss accessLog pattern="%a %t %U %s %D" 打印出來就以下:
10.108.67.90 [25/Jul/2016:11:56:39 +0800] /fltDynInfo/restJson/0323/20160725 200 1103
10.108.68.251 [25/Jul/2016:14:20:16 +0800] /fltDynInfo/restJson/3167/20160723 200 579
10.108.68.251 [25/Jul/2016:14:33:31 +0800] /fltDynInfo/restJson/detail/3167/20160723/CAN/TSN 200 185
10.108.68.251 [25/Jul/2016:14:33:55 +0800] /fltDynInfo/restJson/detail/3167/20160723/TSN/CAN 200 265
10.108.68.251 [25/Jul/2016:14:35:47 +0800] /fltDynInfo/restJson/detail/3167/20160723/TSN/WUH 200 12
goaccess的配置文件最主要的做用之一就是讓你能夠定義分析目標的每行日誌的格式(分割符是什麼,以該分割符劃分的字段依次表明什麼含義)。
它定義的方式和上節jboss pattern的配置是相似的。 下圖是從它官網上截取的goaccess對訪問日誌字段的定義
如上圖最後幾行所說,要使用goaccess,你必需要至少指定 %h, %t, %r(%r可由類似的定義代替,如%U)
tomcat
三. 使用goaccess分析 jboss access.log
經過上2節,應該已經明瞭要完成此項工做只需恰當配置goaccess的提取格式,使其識別並對應提取access.log的信息。
一般配置goaccess只需三步。 即配置 time-Format, date-Format ,log-Format
配置文件名稱goaccess.conf,一般在 /etc/, /usr/etc/ or /usr/local/etc/
無論什麼日誌,時間是不可或缺的, time-Format, date-Format 經過配置 時分秒 和 日期在log中的展現格式,
以使得可以正確解析。goaccess配置文件中以及預置了好幾種格式供選擇。
好比我access.log打印的時間格式是 25/Jul/2016:11:56:39,那對應 time-Format %H:%M:%S,date-format %d/%b/%Y
logFormat則根據日誌打印的內容以及上圖所示goaccess的定義符。
好比我jboss打印的日誌 pattern="%a %t %U %s %D" 含義是 「訪問ip 訪問時間 URL 響應狀態 響應時長ms」
對應按照goaccess的定義。 log-format %h [%d:%t %^] %U %s %D 含義是「clientIp [日期:時間 忽略] URL 響應狀態 響應時長ms」網絡
如此,就配置好了。 goaccess支持衆多參數支持多種分析形式·多種結果格式·多種分析條件的分析,具體請查看官網的man page
此處進行最簡單的分析,並生成html:
goaccess -f access.log -a -o report.htmlsession
貼幾張分析結果的截圖,基本上經常使用的維度它都有包含,具體看官網介紹:app