Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# !/bin/bash
# concat log
touch /tmp/complete_isignif_fr_access.log
cat /var/log/apache2/isignif_fr_access*.log >> /tmp/complete_isignif_fr_access.log
gzip -d /var/log/apache2/isignif_fr_access.log.*.gz --stdout >> /tmp/complete_isignif_fr_access.log
# generate HTML report
goaccess /tmp/complete_isignif_fr_access.log -o /tmp/goaccess_report.html
# generate daily JSON report
TODAY=$(date '+%Y-%m-%d')
goaccess "/var/log/apache2/isignif.access.${TODAY}.log" -o /tmp/daily_goaccess_report.json
VISITORS=$(cat /tmp/daily_goaccess_report.json | jq '.general.unique_visitors')
RUSH_HOUR=$(cat /tmp/daily_goaccess_report.json | jq ' | max_by(.visitors.percents) | .data' | sed 's/"//g')
PERCENTAGE_500=$(cat /tmp/daily_goaccess_report.json | jq '.status_codes[][] | select(.data == "5xx Server Error") | .hits.percent' 2> /dev/null)
MOST_VIEWED_PAGE=$(cat /tmp/daily_goaccess_report.json | jq ' | max_by(.hits.count) | .data' | sed 's/"//g')
REFERRING_SITES=$(cat /tmp/daily_goaccess_report.json | jq ' | sort_by(.hits.count) | reverse | .[] | "- \(.data) : \(.hits.count) requetes"' | sed 's/"//g')
# send email
cat <<EOF |
Bonjour la team,
Aujourd'hui il y a eu ${VISITORS} visiteurs. Ca a été le rush à ${RUSH_HOUR} heures (pensez y pour la com'). Sans surprise, la page la plus visitee a ete https://isignif${MOST_VIEWED_PAGE}. Il y a eu 0${PERCENTAGE_500}% de requetes qui ont terminees en erreur.
Les nom de domaines suivants nous ont amene du traffic:
A demain.
mail -s "Rapport d'utilisation de iSignif" contact@rousseau-alexandre.Fr -A /tmp/goaccess_report.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.