GoAccess实现可视化进行access监控

  • nginx的access.log来分析定位问题和分析用户运营的数据
  • 文件在/var/log/nginx/access.log
  • 难题在于实时分析,但goaccess可以。

goaccess介绍与安装步骤

安装 GoAccess 非常的容易。只需要下载、解压以及编译就好了:
$ wget http://tar.goaccess.io/goaccess-1.2.tar.gz
$ tar -xzvf goaccess-1.2.tar.gz
$ cd goaccess-1.2/
$ ./configure --enable-utf8 --enable-geoip=legacy
$ make
# make install

在执行./configure时,可能会有以下问题:
configure: error:
*** Missing development files for the GeoIP library
需执行以下步骤

$ wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.11/GeoIP-1.6.11.tar.gz
$ tar -xzvf GeoIP-1.6.11.tar.gz
$ cd GeoIP-1.6.11
$ ./configure
$ make
# make install

在执行./configure时,还可能遇到:
configure: error: *** Missing development libraries for ncursesw
要使用–enable-utf8,你需要安装ncursesw
sudo apt-get install libncursesw5-dev

产生webscoket服务观察access.log变化

  • 最后就是在存放access.log目录下,本人文件位置在
    /usr/local/openresty/nginx/logs
  • 然后执行
    sudo goaccess access.log -o ../html/report.html --real-time-html --time-format='%H:%M:%S' --date-format='%d/%b/%Y' --log-format=COMBINED
  • 运行后会显示
    WebSocket server ready to accept new client connections
 在nginx.conf中添加以下引导文件
	location /report.html{
		alias /usr/local/openresty/nginx/html/report.html;	
	}

修改goaccess.log配置文件说明(可不改)

############################
/etc/nginx/nginx.conf
log_format main   '$server_name $remote_addr - $remote_user 
				 [$time_local] "$request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" "$http_x_forwarded_for" '
                 '$upstream_addr $request_time $upstream_response_time'
############################
/usr/local/etc/goaccess.conf
log-format   %^ %h %^ %^  [%d:%t %^] “%r” 
%s %b “%R”
 “%u” “%^”
  %^ %T %^
#########################################
/usr/local/etc/goaccess.conf
$server_name         %^        忽略这一字段
$remote_addr -       %h%^    host(客户端ip地址,包括ipv4和ipv6)
$remote_user         %^    忽略这一字段
[$time_local]       [%d:%t %^]     匹配date-format格式的日期字段--
匹配time-format格式的时间字段--忽略这一字段
"$request"          “%r”      来自客户端的请求行
$status              %s     用户代理的HTTP请求报头
$body_bytes_sent     %b   服务器返回的内容大小
$http_referer       “%R”    HTTP请求头的referer字段
$http_user_agent    “%u”    用户代理的HTTP请求报头
$http_x_forwarded_for    %^    忽略这一字段
$upstream_addr     %^    忽略这一字段
 $request_time       %T    请求所花费的时间,单位秒
 $upstream_response_time    %^    忽略这一字段
 #########################################
 %t 匹配time-format格式的时间字段
 %D 请求所花费的时间,单位微秒
 %H 请求协议
 %U URL路径
 %m 请求的方法
 ####################
 ###########################
'$remote_addr - $remote_user [$time_local] "$request"' 
'$status $body_bytes_sent "$http_referer"'
 '"$http_user_agent" "$http_x_forwarded_for"'
 ###############################################
%h%^%^[%d:%t %^] "%r" %s%b "%R"  "%u"  "%^"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值