GoAccess自动分割Nginx日志
GoAccess 是一款开源的网站日志实时分析工具。GoAccess 的工作方式很容易理解,就是读取和解析 Apache/Nginx/Lighttpd 的访问日志文件 access log,然后以更友好的方式把统计信息显示出来。统计的内容包括:访问概况、动态页面请求、静态页面请求(如图片、样式表、脚本等)、访客排名,访客使用的操作系统,访客使用的浏览器,来路域名,404 错误,搜索爬虫,搜索关键词等等。
安装组件
yum -y install glib2 glib2-devel ncurses ncurses-devel GeoIP GeoIP-devel
下载源码包安装
wget http://tar.goaccess.io/goaccess-0.8.5.tar.gz
tar zxvf goaccess-0.8.5.tar.gz -C /usr/src/
cd /usr/src/goaccess-0.8.5/
./configure --prefix=/usr/local/goaccess
make && make install
下载文件
cd /usr/local/goaccess/
wget -O goaccessrc https://raw.githubusercontent.com/allinurl/goaccess/master/config/goaccess.conf --no-check-certificate
编辑文件
vim goaccessrc
去除下面22,33行的注释,增加235行的注释
22 date-format %d/%b/%Y
33 log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
235 #ignore-panel KEYPHRASES
创建网页目录
mkdir html
生成网页报告
/usr/local/goaccess/bin/goaccess -f /usr/local/nginx/logs/access.log -d -a -p /usr/local/goaccess/goaccessrc > /usr/local/goaccess/html/access.html
Nginx发布goaccess网页
cd /usr/local/nginx/conf/vhosts/
vi goaccess.conf
server {
listen 80;
server_name goaccess.xx.com;
autoindex on;
location / {
root /usr/local/goaccess/html;
}
}
重新加载
/usr/local/nginx/sbin/nginx -s reload
访问网页
http://goaccess.xx.com/access.html
wKioL1VK-4iB_ZLQAAJI0SkVSms176.jpg
下面介绍nginx日志切割和自动生成网页报告以及汉化。
vi nginx_cut.sh
#!/bin/bash
#############日志切割###########################
time=`date -d today +%Y%m%d%H%M`
/usr/local/nginx/sbin/nginx -s stop
cd /usr/local/nginx/logs
mv access.log access_$time.log
mv error.log error_$time.log
/usr/local/nginx/sbin/nginx
#删除超过7天的日志文件
find /usr/local/nginx/logs -ctime 3 -type f -name "*.log" -exec rm {} \;
#自动生成网页报告
/usr/local/goaccess/bin/goaccess -f access_$time.log -d -a -p /usr/local/goaccess/goaccessrc > /usr/local/goaccess/html/access_$time.html
#自动汉化网页报告文件
echo access_$time.html > /tmp/time.log
/manage/hanhua.sh
#删除超过7天的报告文件
find /usr/local/goaccess/html -ctime 7 -type f -name "*.html" -exec rm {} \;
编辑汉化脚本,英文翻译参考百度翻译,可能不太准确。
vi /manage/hanhua.sh
#/bin/bash
file=`cat /tmp/time.log`
cd /usr/local/goaccess/html
sed -i 's/Overall/整体/g' $file
sed -i 's/Unique visitors/独立访客/g' $file
sed -i 's/Requested files/请求的文件/g' $file
sed -i 's/Requested static files/请求的静态文件/g' $file
sed -i 's/Not found URLs/没有找到网址/g' $file
sed -i 's/Hosts/主机/g' $file
sed -i 's/Operating Systems/操作系统/g' $file
sed -i 's/Browsers/浏览器/g' $file
sed -i 's/Referrers URLs/反向链接的url/g' $file
sed -i 's/Referring sites/参考网站/g' $file
sed -i 's/Keyphrases/关键词/g' $file
sed -i 's/Status codes/状态码/g' $file
sed -i 's/Generated by/生成的/g' $file
sed -i 's/Dashboard/仪表板/g' $file
sed -i 's/Analyzed Requests/分析请求/g' $file
sed -i 's/Total Requests/总请求/g' $file
sed -i 's/Failed Requests/请求失败/g' $file
sed -i 's/Generation Time/生成时间/g' $file
sed -i 's/Unique Visitors/独立访客/g' $file
sed -i 's/Unique Files/独特的文件/g' $file
sed -i 's/Excl. IP Hits/除外的IP点击/g' $file
sed -i 's/Referrers/反向链接/g' $file
sed -i 's/Unique 404/独特的404/g' $file
sed -i 's/Static Files/静态文件/g' $file
sed -i 's/Log Size/日志大小/g' $file
sed -i 's/Bandwidth/带宽/g' $file
sed -i 's/per day/每一天/g' $file
sed -i 's/Including spiders/包括蜘蛛/g' $file
sed -i 's/Hits having the same IP/具有相同的IP点击/g' $file
sed -i 's/date and agent are a unique visit/日期和代理是一种独特的访问/g' $file
sed -i 's/Top Requested Files sorted by hits/请求的文件按点击顶部/g' $file
sed -i 's/time served/时间送达/g' $file
sed -i 's/protocol/协议/g' $file
sed -i 's/method/方法/g' $file
sed -i 's/Hits/点击/g' $file
sed -i 's/Protocol/协议/g' $file
sed -i 's/Method/方法/g' $file
sed -i 's/Top 404 Not Found URLs sorted by hits/前404没有找到网址按点击率排序/g' $file
sed -i 's/Top/前/g' $file
sed -i 's/sorted by hits/按点击率/g' $file
sed -i 's/bandwidth/带宽/g' $file
sed -i 's/Hostname/主机名/g' $file
sed -i 's/sorted by unique visitors/通过独特的访客排序/g' $file
sed -i 's/Requested/要求/g' $file
sed -i 's/Status Codes/状态码/g' $file
sed -i 's/Code/代码/g' $file
sed -i 's/Visitors/游客/g' $file
sed -i 's/Name/名称/g' $file
sed -i 's/Not Found URLs/没有找到网址/g' $file
sed -i 's/or service not known/或服务不知道/g' $file
sed -i 's/Pages/页面/g' $file
sed -i 's/Referring Sites/参考网站/g' $file
访问网页
http://goaccess.xx.com/
wKiom1VK-lTjIw3QAACuvyMOfEc868.jpg
点击网页文件
汉化之后的页面效果如下:
wKioL1VK--uCJqyaAAHDhwfvtbU010.jpg
本文出自 “陨落星空” 博客,请务必保留此出处http://xiao987334176.blog.51cto.com/2202382/1643811
GoAccess自动分割Nginx日志的更多相关文章
- 分割nginx日志
#!/bin/bash #此脚本用于自动分割Nginx的日志,包括access.log和error.log #每天00:00执行此脚本 将前一天的access.log重命名为access-xxxx-x ...
- 【Nginx】如何按日期分割Nginx日志?看这一篇就够了!!
写在前面 Nginx是没有以日期格式作为文件名来存储的,也就是说,Nginx不像Tomcat,每天自动生成一个日志文件,所有的日志都是以一个名字来存储,时间久了日志文件会变得很大.这样非常不利于分析. ...
- shell按日期自动切割nginx日志脚本
shell按日期自动切割nginx日志脚本 参考:自学it网 http://www.zixue.it/. #nginx日志切割脚本 #author:ce #!/bin/bash #设置日志文件存放目录 ...
- 自动分割nginx服务的日志文件
nginx服务每天都会产生大量的日志信息,时间一长导致日志文件容量很大,会影响系统性能.通过以下shell代码,配合crontab定时执行可实现nginx日志定时分割的功能. #!/bin/bash ...
- linux中使用corntab和shell脚本自动备份nginx日志,按天备份
编写shell脚本,实现nginx日志每天自动备份到指定文件夹! 需要的命令mv , corntab -e(定时任务),shell脚本 这里先说一下corntab: https://www.cnblo ...
- Nginx日志管理(四)
Nginx日志对于统计.系统服务排错很有用.Nginx日志主要分为两种:access_log(访问日志)和error_log(错误日志).通过访问日志我们可以得到用户的IP地址.浏览器的信息,请求的处 ...
- logrotate 进行nginx日志分割
http://www.williamsang.com/archives/1254.html 日志分割常用方法: 自己写脚本分割 使用linux自带的logrotate 前者灵活,可以应对各种需求,自定 ...
- Nginx 日志分析及性能排查
Nginx 日志分析及性能排查 2017-03-04 Linux爱好者 (点击上方公众号,可快速关注) 作者:-外星人- my.oschina.net/362228416/blog/844713 如有 ...
- Nginx 日志自动分割
Nginx 的日志都是写在一个文件当中的,不会自动地进行切割,如果访问量很大的话,将导致日志文件容量非常大,不便于管理和造成Nginx 日志写入效率低下等问题.所以,往往需要要对access_log. ...
随机推荐
- deleteMany is not a function
问题: 同事使用了deleteMany方法用于删除数据,但是全公司只有我一个人报错deleteMany is not a function. 很自然,输出了model.deleteMany,得到的结果 ...
- ABP启动流程分析
添加服务与注册中间件 public IServiceProvider ConfigureServices(IServiceCollection services) { // Configure Abp ...
- Struts2+JQuery+Json登陆实例
Struts2+JQuery+Json登陆实例 博客分类: Struts2 在搭建之前.. 首先,需要准备struts2.0框架的5个核心包, 以及jsonplugin-0.32.jar 以及js ...
- JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String
在使用Postman测试Spring Boot项目接口时,接口返回JSON parse error: Cannot deserialize value of type `java.time.Local ...
- unity_pojie
http://www.ceeger.com/forum/read.php?tid=23396&desc=1
- 3damx平滑组注意事项
需要在Editable Poly->面级别,选中(需要平滑的)面,然后去点平滑组或自动平滑 如果出现下图的情况,说明可能是有多余点,点没缝合 max中确认,确实是点没缝合导致
- if-else判断语句中经常犯的一个错误
假设题目为:随便给定一个数,三种情况:(1)若小于0,输出为“小于0”:(2)若在0-50之间,则输出“在0-50之间”.(3)若大于50,则输出“大于50”. 解法:如果我这么写,运行一下看看. i ...
- ajax对象。同步与异步及ajax发送请求
ajax对象的属性.方法 属性 readyState: Ajax状态码 * 0:表示对象已建立,但未初始化,只是 new 成功获取了对象,但是未调用open方法 1:表示对象已初始化,但未发送,调用了 ...
- [NOI2002] 贪吃的九头蛇
考虑任意一种划给大头的方案,两端的都给了大头(bel=1)的边产生难受值,剩下n-k个果子分给m-1个头,当m-1=1时,两端都给了这个小头也产生难受值:而m-1>1的情况要好看的多,贪心的,因 ...
- os.walk详解
https://www.jianshu.com/p/bbad16822eab python中os.walk是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 1.载入 要使 ...