Last active
March 2, 2020 15:47
-
-
Save madeindjs/bb56776947c84ff993eab86e32ceadb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/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 '.visit_time.data | 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 '.requests.data | max_by(.hits.count) | .data' | sed 's/"//g') | |
REFERRING_SITES=$(cat /tmp/daily_goaccess_report.json | jq '.referring_sites.data | 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: | |
${REFERRING_SITES} | |
A demain. | |
EOF | |
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