生产中,我们需要Nginx访问日志,查一些需要的数据,这里作一些收集。
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $request_length $request_time $bytes_sent ' '"$upstream_cache_status"';
cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -r
awk '($9 ~ /504/)' access.log | awk '{print $7}' | sort | uniq -c | sort -r
awk '{print $7}' access.log | grep "/pay_success.html" | wc -l
awk '{print $7}' access.log | sort | uniq -c |sort -n -k 1 -r | more
sudo yum -y install geoip-devel ncurses ncurses-devel glib2-devel wget http://tar.goaccess.io/goaccess-0.9.2.tar.gz tar -xzvf goaccess-0.9.2.tar.gz cd goaccess-0.9.2/ ./configure --enable-geoip --enable-utf8 make && make install
vim /usr/local/etc/goaccess.conf
goaccess -f access.log
goaccess -f access.log -a > report.html