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. ...
随机推荐
- Swing 添加Esc快捷键退出程序
JFrame demo = new JFrame(); demo.addKeyListener( new KeyListener(){ public void keyReleased(KeyEvent ...
- [hiho第92周]Miller-Rabin素性测试的c++实现
证明: 如果n是素数,整数$a$ 与$n$ 互素,即$n$ 不整除$a$ ,则${a^{n - 1}} \equiv 1(\bmod n)$ ,如果能找到一个与$n$ 互素的整数$a$ ,是的上式不成 ...
- zkw线段树专题
题目来自大神博客的线段树专题 http://www.notonlysuccess.com/index.php/segment-tree-complete/ hdu1166 敌兵布阵题意:O(-1)思路 ...
- socket网络编程实践要点
1.创建udp的socket句柄 // 当host_port为0时,则表示让操作系统自动分配 bool createUdpSocket(string host_ip,unsigned short ho ...
- ASP.NET Core MVC 视图
ASP.NET Core MVC中视图的知识和ASP.NET MVC有很多相似之处,学习难度较低.以下内容主要体现了编程中模块化的思想,模块化才应是我们关注的重点. Layout 布局用于提供各个页面 ...
- The King’s Ups and Downs
有n个高矮不同的士兵,现在要将他们按高,矮依次排列,问有多少种情况. 化简为 n个人,求出可以形成波浪形状的方法数 #include <iostream> #include <cma ...
- ue4 模拟tween
timeline的设置,注意timeLine可以使用外部的曲线,这个比较方便做各种曲线,timeline内部只适合打单个点
- IT兄弟连 Java语法教程 变量2
变量的作用域和生命周期 到目前为止,使用的所有变量都是在main()方法开始时声明的,然而,Java允许在任何代码块(代码块以开花括号开始,以闭花括号结束)中声明变量,代码块定义了作用域.因此,每当开 ...
- IT兄弟连 JavaWeb教程 监听器2
4 监听HttpSession域对象的创建和销毁 HttpSessionListener接口用于监听HttpSession对象的创建和销毁. 创建一个Session时,激发sessionCreate ...
- 基础篇-密码文件.pgpass
密码文件包含字段 host:port:dbname:user:password port和dbname可以使用*号作通配符 在*nix系统中 ~/.pgpass 在windows系统中 %APPDAT ...