Publish: 2018-07-16 | Modify: 2019-12-23
GoAccess aims to be a fast terminal-based log analyzer. Its core idea is to analyze and view web server statistics in real-time. GoAccess can analyze web logs from Apache/Nginx and supports generating HTML, JSON, CSV, and other data reports.
GoAccess supports installation via yum
. Simply execute the command yum -y install goaccess
to install. However, for greater flexibility, it is recommended to compile and install using the following method.
# Install dependencies
yum -y install libmaxminddb-devel ncurses-libs ncurses-devel openssl openssl-devel
# Download source code
wget https://tar.goaccess.io/goaccess-1.2.tar.gz
# Extract
tar -xzvf goaccess-1.2.tar.gz
# Enter directory
cd goaccess-1.2/
# Compile and install
./configure --enable-utf8 --enable-geoip=mmdb --with-openssl --with-libmaxminddb-devel
make && make install
If everything goes well, you can see the corresponding version by entering the command goaccess -V
. For more compilation parameters, please refer to the official documentation: https://goaccess.io/download
The simplest way is to directly run goaccess log_path
and follow the prompts. If you find the terminal interface uncomfortable, you can also generate static HTML reports by running the following command:
goaccess xiaoz.me_nginx.log -a -o xxx.html --log-format=COMBINED
xiaoz.me_nginx.log
: The specific path of the log file.xxx.html
: The name of the HTML report. You can specify the site directory and directly access it to view.--log-format=
: The log file format. COMBINED
is the standard format.It's too troublesome to manually generate the report every time. Is there a simpler way? By writing a simple shell script, we can automatically generate the report. Save the following content as goaccess.sh
.
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
export PATH
goaccess xiaoz.me_nginx.log -a -o /xiaoz.me/$(date +%Y-%m-%d).html --log-format=COMBINED
xiaoz.me_nginx.log
: The path of the log file (please provide the absolute path)./xiaoz.me/
: Your site root directory. Modify it according to your own situation.Don't forget to add executable permissions: chmod u+x goaccess.sh
, and then use crontab
to generate the HTML report every hour.
# Add cron job
crontab -e
# Add the following content. /root/goaccess.sh is the absolute path of the above script.
0 * * * * /root/goaccess.sh > /dev/null
# Reload crontab
service crond reload
Congratulations! Now GoAccess will generate an HTML log report for us every hour. Wait for a while and access https://domain.com/current_date.html
(date format like 2017-07-16) to view the intuitive HTML report.
GoAccess supports more features, such as analyzing multiple log files at the same time, IP lookup, and more. For more usage help, you can use goaccess -h
to view. I also shared a good log analysis tool for Windows called "360 Xingtu" before, which provides Chinese display and is more user-friendly.
GoAccess Official Website: https://goaccess.io/ Demo: https://rt.goaccess.io/?20180613194436
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.