jboss7访问日志功能及使用goaccess工具分析

      网络上虽然很多文章分别讲到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/

一. 开启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_log

      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)

 

二. 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)

 

三. 使用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.html

  贴几张分析结果的截图,基本上常用的维度它都有包含,具体看官网介绍:

转载于:https://www.cnblogs.com/surprizeFuture/p/5711881.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
deploy/jbossweb-tomcat55.sar/server.xml <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve" prefix="access_log." suffix=".log" pattern="%h %t %r %s %D" directory="${jboss.server.home.dir}/../output/logs" resolveHosts="false" /> http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html pattern配置: %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 resolveHosts is 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) There is also support to write information from the cookie, incoming header, outgoing response headers, the Session or something else in the ServletRequest. It is modeled after the apache syntax: %{xxx}i for incoming request headers %{xxx}o for outgoing response headers %{xxx}c for a specific request cookie %{xxx}r xxx is an attribute in the ServletRequest %{xxx}s xxx is an attribute in the HttpSession The shorthand pattern name common (which is also the default) corresponds to '%h %l %u %t "%r" %s %b'.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值