日志格式:
127.0.0.1 127.0.0.1 127.0.0.1 - "01/Aug/2016:11:10:10 +0800" 200 64513 3.045 "-" "GET /media01/9b890f3678b54c0da14a4749aa4073e6_dat-full.dat HTTP/1.1" "python-requests/2.2.1 CPython/2.7.6 Linux/3.16.0-30-generic" 30860
goaccess配置格式:
%d date field matching the date_format variable.【日期】
%h host (the client IP address, either IPv4 or IPv6)【请求客户端ip】
%r The request line from the client.【请求】
%s The status code that the server sends back to the client.【响应码】
%b The size of the object returned to the client.【返回数据大小】
%R The "Referer" HTTP request header.【头部信息,referer】
%u The User-Agent HTTP request header.【用户agent】
%D The time taken to serve the request, in microseconds.【响应时间,ms】
%T The time taken to serve the request, in seconds. Note: %D will take priority over %T if both are used.
【响应时间,秒为单位】
%^ Ignore this field.【忽略】
生成/root/.goaccessrc文件内容为:
color_scheme 0
date_format %d/%b/%Y
log_format %^ %^ %h - "%d:%^" %s %b %T "-" "%r" "%u" %^
定时脚本:
#!/bin/bash
dateformat=`date +"%Y%m%d"`
logfile="/usr/local/nginx/logs/access.log-$dateformat"
lochost=`hostname`
anafile="/home/$lochost/nginx_analysis/access-analysis.html"
emlfile="/home/$lochost/nginx_analysis/nginx_mail.py"
if [[ -f $logfile ]]
then
goaccess -f $logfile -a > $anafile
python $emlfile
fi