initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
75891c3271
129 changed files with 8046 additions and 0 deletions
7
roles/goaccess/templates/goaccess-report.service.j2
Normal file
7
roles/goaccess/templates/goaccess-report.service.j2
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[Unit]
|
||||
Description=GoAccess Report Generation
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/goaccess-report
|
||||
52
roles/goaccess/templates/goaccess-report.sh.j2
Normal file
52
roles/goaccess/templates/goaccess-report.sh.j2
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPORTS_DIR="/srv/goaccess/reports"
|
||||
DATA_DIR="/srv/goaccess/data"
|
||||
CONF="/srv/goaccess/goaccess.conf"
|
||||
|
||||
SITES=(
|
||||
{% for site in goaccess_sites %}
|
||||
"{{ site }}"
|
||||
{% endfor %}
|
||||
)
|
||||
|
||||
# Fetch logs once from journald
|
||||
LOGS=$(journalctl CONTAINER_NAME=caddy --since "2 hours ago" --output=cat 2>/dev/null || true)
|
||||
|
||||
# Skip if no logs
|
||||
if [[ -z "$LOGS" ]]; then
|
||||
echo "No Caddy logs found, skipping."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Generate per-site reports
|
||||
for site in "${SITES[@]}"; do
|
||||
db_path="${DATA_DIR}/${site}"
|
||||
mkdir -p "$db_path"
|
||||
|
||||
echo "$LOGS" \
|
||||
| jq -c "select(.request.host == \"${site}\")" 2>/dev/null \
|
||||
| goaccess \
|
||||
--log-format=CADDY \
|
||||
--persist \
|
||||
--restore \
|
||||
--db-path="$db_path" \
|
||||
-o "${REPORTS_DIR}/${site}.html" \
|
||||
- || echo "Warning: GoAccess failed for ${site}"
|
||||
done
|
||||
|
||||
# Generate combined "all sites" report
|
||||
all_db="${DATA_DIR}/all"
|
||||
mkdir -p "$all_db"
|
||||
|
||||
echo "$LOGS" \
|
||||
| goaccess \
|
||||
--log-format=CADDY \
|
||||
--persist \
|
||||
--restore \
|
||||
--db-path="$all_db" \
|
||||
-o "${REPORTS_DIR}/index.html" \
|
||||
- || echo "Warning: GoAccess failed for combined report"
|
||||
|
||||
echo "Reports generated at $(date -Iseconds)"
|
||||
9
roles/goaccess/templates/goaccess-report.timer.j2
Normal file
9
roles/goaccess/templates/goaccess-report.timer.j2
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=GoAccess Report Generation
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
7
roles/goaccess/templates/goaccess-sync.service.j2
Normal file
7
roles/goaccess/templates/goaccess-sync.service.j2
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[Unit]
|
||||
Description=GoAccess Report Sync to Storage Box
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/goaccess-sync
|
||||
7
roles/goaccess/templates/goaccess-sync.sh.j2
Normal file
7
roles/goaccess/templates/goaccess-sync.sh.j2
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
rsync -az --delete \
|
||||
-e "ssh -i {{ restic_ssh_key }} -p {{ restic_ssh_port }} -o StrictHostKeyChecking=no -o BatchMode=yes" \
|
||||
/srv/goaccess/reports/ \
|
||||
{{ restic_user }}@{{ restic_host }}:analytics/
|
||||
9
roles/goaccess/templates/goaccess-sync.timer.j2
Normal file
9
roles/goaccess/templates/goaccess-sync.timer.j2
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=GoAccess Report Sync to Storage Box
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* {{ goaccess_sync_time }}
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
9
roles/goaccess/templates/goaccess.conf.j2
Normal file
9
roles/goaccess/templates/goaccess.conf.j2
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
log-format CADDY
|
||||
date-format %s
|
||||
time-format %s
|
||||
|
||||
# Persist parsed data to disk
|
||||
db-path /srv/goaccess/data
|
||||
|
||||
# HTML report settings
|
||||
html-report-title GoAccess Analytics
|
||||
Loading…
Add table
Add a link
Reference in a new issue