统计web 访问日志的请求数据

  tomcat日志格式  在配置文件 server.xml 中,具体参照官方文档 https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve

  

pattern

A formatting layout identifying the various information fields from the request and response to be logged, or the word common or combined to select a standard format. See below for more information on configuring this attribute.

  • %a - Remote IP address 远端IP
  • %A - Local IP address 本地IP
  • %b - Bytes sent, excluding HTTP headers, or '-' if zero 发送字节数
  • %B - Bytes sent, excluding HTTP headers 发送字节数
  • %h - Remote host name (or IP address if enableLookups for the connector 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. See also %{xxx}p below. 请求端口
  • %q - Query string (prepended with a '?' if it exists) 查询字符串
  • %r - First line of the request (method and request URI)  请求字符串(方法 & 请求URL)
  • %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
  • %F - Time taken to commit the response, in millis
  • %I - Current request thread name (can compare later with stacktraces)

根据日志格式,统计请求 返回码(200, 500,404 等)

提取返回码命令  :

grep ${TODAY} ${LogAccess} | grep -v "GET / HTTP/1.1" | awk '{print $11}' | wc -l

192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:17 +0800] "GET /CloudNetMonitor/src/app/business/netMonitor/theme/custom/img/mask-loading.gif HTTP/1.1" 200 5093 6
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:17 +0800] "POST /CloudNetMonitor/rest/v1/netmonitor/web/smallFlow HTTP/1.1" 200 403 42
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:17 +0800] "POST /CloudNetMonitor/rest/v1/netmonitor/web/probe/heartBeat/query HTTP/1.1" 200 2055 59
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:18 +0800] "GET /CloudNetMonitor/src/app/business/netMonitor/src/overview/views/currentAlarm.html HTTP/1.1" 200 14350 5
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:18 +0800] "GET /CloudNetMonitor/src/app/business/netMonitor/src/overview/controllers/currentAlarmCtrl.js HTTP/1.1" 200 12739 7
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:18 +0800] "GET /CloudNetMonitor/src/app/business/netMonitor/src/overview/services/alarmService.js HTTP/1.1" 200 5005 4
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:18 +0800] "GET /CloudNetMonitor/src/app/business/netMonitor/src/overview/controllers/ruleHideCtrl.js HTTP/1.1" 200 2890 4
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:18 +0800] "POST /CloudNetMonitor/rest/v1/netmonitor/web/syslogAlarmSend/query/activity HTTP/1.1" 200 3337 46
192.145.17.126 10.177.68.157 10.177.68.157 - - [24/Aug/2018:16:48:18 +0800] "GET /CloudNetMonitor/src/app/business/netMonitor/theme/image/major.png HTTP/1.1" 200 1325 4

 

用定时脚本 每天23:59分 即可统计请求数量

 

posted @ 2019-01-14 22:00  A.ArmStrong  阅读(691)  评论(0编辑  收藏  举报