initial checkin
This commit is contained in:
commit
b2ad482e8f
|
@ -0,0 +1,12 @@
|
|||
# mkwebstats repo
|
||||
|
||||
## Introduction
|
||||
|
||||
This repo contains mkwebstats.sh, a simple shell script that will use goaccess
|
||||
to generate web log analytics from nginx-proxy-manager proxy host logs. The
|
||||
resultant html report files will be written into the html directory of another
|
||||
nginx web host.
|
||||
|
||||
This instance of goaccess has IP geolocation enabled, and requires the presence
|
||||
of a GeoLite2 geo ip database from MaxMind (https://www.maxmind.com).
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
#!/bin/bash
|
||||
#####################################################################
|
||||
#
|
||||
# This is a simple shell script that will use goaccess to generate web
|
||||
# log analytics from nginx-proxy-manager proxy host logs. The resultant
|
||||
# html report files will be written into the html directory of another
|
||||
# nginx web host.
|
||||
#
|
||||
# This instance of goaccess has IP geolocation enabled, and requires
|
||||
# the presence of a GeoLite2 geo ip database from MaxMind
|
||||
# (https://www.maxmind.com).
|
||||
#
|
||||
#####################################################################
|
||||
|
||||
#####################################################################
|
||||
# variable definitions
|
||||
|
||||
# today's date, in logfile format
|
||||
dateToday=$(date +"%0d/%b/%Y")
|
||||
|
||||
# log dir
|
||||
logDir="${HOME}/docker/docker_nginx-proxy-manager/data/logs"
|
||||
|
||||
# goaccess binary
|
||||
goBin="/usr/local/bin/goaccess"
|
||||
|
||||
# destination dir
|
||||
dstDir="${HOME}/docker/docker_nginx-go.delfax.net/go.delfax.net/html"
|
||||
|
||||
# set up our array of 'hostname:logfile'
|
||||
declare logfiles
|
||||
|
||||
# array entries for hostname:logfile
|
||||
logfiles=("delfax.net:proxy-host-1_access.log" \
|
||||
"www.delfax.net:proxy-host-9_access.log" \
|
||||
"radar231.com:proxy-host-4_access.log" \
|
||||
"www.radar231.com:proxy-host-10_access.log" \
|
||||
"git.radar231.com:proxy-host-5_access.log" \
|
||||
"go.delfax.net:proxy-host-14_access.log" \
|
||||
"npm.delfax.net:proxy-host-6_access.log" \
|
||||
"jmc.delfax.net:proxy-host-7_access.log" \
|
||||
)
|
||||
|
||||
# goaccess args
|
||||
geoipArg="${HOME}/bin/GeoLite2-City/GeoLite2-City.mmdb"
|
||||
timeArg='%H:%M:%S'
|
||||
dateArg='%d/%b/%Y'
|
||||
# a format string structured for nginx-proxy-manager proxy host logs
|
||||
formatArg='[%d:%t %^] %^ %^ %s - %m %^ %v %U [Client %h] [Length %b] [Gzip %^] [Sent-to %^] %u %R'
|
||||
|
||||
#####################################################################
|
||||
# We'll create an index.html file that contains links to all of our
|
||||
# generated report files
|
||||
|
||||
# create the header for our index.html
|
||||
cat >${dstDir}/index.html <<HEADEOM
|
||||
<!doctype html>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>goaccess index</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<P>
|
||||
<CENTER>
|
||||
<H2>NPM Proxy Host Web Analytic Reports</H2>
|
||||
</CENTER>
|
||||
<P>
|
||||
<HR WIDTH="100%">
|
||||
<P>
|
||||
<UL>
|
||||
HEADEOM
|
||||
|
||||
#####################################################################
|
||||
# Generate a web analytics report file for each proxy host logfile
|
||||
#
|
||||
# We'll generate two reports for each proxy host;
|
||||
# - one for all of the existing logfiles
|
||||
# - one for just today's log entries
|
||||
|
||||
for i in ${logfiles[*]}
|
||||
do
|
||||
host=$(echo $i | cut -d':' -f1)
|
||||
logfile=$(echo $i | cut -d':' -f2)
|
||||
|
||||
###################################
|
||||
# Analyze all log entries
|
||||
zcat -f ${logDir}/${logfile}* | ${goBin} >/dev/null 2>&1 - --geoip-database=${geoipArg} --time-format=${timeArg} --date-format=${dateArg} --log-format="${formatArg}" --output=${dstDir}/${host}_all.html --html-report-title="${host} - All"
|
||||
|
||||
# put a link to the report in our index.html
|
||||
echo " <LI> <A HREF="${host}_all.html">${host} - All</A></LI>" >>${dstDir}/index.html
|
||||
|
||||
###################################
|
||||
# Analyze only today's log entries
|
||||
zcat -f ${logDir}/${logfile}* | grep "^\[${dateToday}:" | ${goBin} >/dev/null 2>&1 - --geoip-database=${geoipArg} --time-format=${timeArg} --date-format=${dateArg} --log-format="${formatArg}" --output=${dstDir}/${host}_today.html --html-report-title="${host} - Today"
|
||||
|
||||
# put a link to the report in our index.html
|
||||
echo " <LI> <A HREF="${host}_today.html">${host} - Today</A></LI>" >>${dstDir}/index.html
|
||||
done
|
||||
|
||||
#####################################################################
|
||||
# finish off our index.html
|
||||
|
||||
# set a variable with current date/time
|
||||
runDateTime=$(date +"%Y-%0m-%0d %H:%M:%S")
|
||||
|
||||
# complete the index.html file
|
||||
cat >>${dstDir}/index.html <<FOOTEOM
|
||||
</UL>
|
||||
<P>
|
||||
<HR WIDTH="100%">
|
||||
<P>
|
||||
Last updated: ${runDateTime}
|
||||
<P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
FOOTEOM
|
||||
|
||||
# EOF
|
Loading…
Reference in New Issue