GoAccess: combine host and path in reports

This commit is contained in:
2026-04-29 20:26:05 +03:00
parent 4d92b3bd3e
commit 3b1736534d
4 changed files with 56 additions and 13 deletions
+8
View File
@@ -0,0 +1,8 @@
FROM allinurl/goaccess:1.10.2
RUN apk add --no-cache jq
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod 0755 /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
+14 -13
View File
@@ -1,22 +1,23 @@
services: services:
goaccess_processor: goaccess_processor:
image: allinurl/goaccess:1.10.2 build: .
image: local/goaccess-jq:1.10.2
container_name: goaccess_processor container_name: goaccess_processor
restart: unless-stopped restart: unless-stopped
init: true
user: "{{ app_owner_uid }}:{{ app_owner_gid }}" user: "{{ app_owner_uid }}:{{ app_owner_gid }}"
command: > command:
--log-format=CADDY - --log-format=COMBINED
--enable-panel=VIRTUAL_HOSTS - --enable-panel=VIRTUAL_HOSTS
--real-time-html - --real-time-html
--port=7890 - --port=7890
--ws-url=wss://goaccess.vakhrushev.me:443 - --ws-url=wss://goaccess.vakhrushev.me:443
--output=/srv/report/index.html - --output=/srv/report/index.html
--persist - --persist
--restore - --restore
--db-path=/srv/db - --db-path=/srv/db
--no-global-config - --no-global-config
/srv/logs/access.log
volumes: volumes:
- "{{ caddy_logs_dir }}:/srv/logs:ro" - "{{ caddy_logs_dir }}:/srv/logs:ro"
- "{{ db_dir }}:/srv/db" - "{{ db_dir }}:/srv/db"
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
# Tail Caddy's JSON access log, transform each entry into Apache CLF
# Combined with the virtual host glued to the request URI, and feed
# the stream straight into goaccess via stdin. Result: every line in
# the Requests panel renders as `host.example.com/path`.
set -eu
ACCESS_LOG="/srv/logs/access.log"
JQ_FILTER='
"\(.request.remote_ip // "-") - - " +
"[\((.ts // 0) | gmtime | strftime("%d/%b/%Y:%H:%M:%S +0000"))] " +
"\"\(.request.method) \(.request.host)\(.request.uri) \(.request.proto)\" " +
"\(.status) \(.size) " +
"\"\(.request.headers.Referer[0]? // "-")\" " +
"\"\(.request.headers["User-Agent"][0]? // "-")\""
'
tail -F -n +1 "$ACCESS_LOG" \
| jq --unbuffered -rc "$JQ_FILTER" \
| exec goaccess - "$@"
+12
View File
@@ -69,10 +69,22 @@
group: "{{ app_user }}" group: "{{ app_user }}"
mode: "0640" mode: "0640"
- name: "Copy Dockerfile and entrypoint for the local jq-enabled goaccess image"
ansible.builtin.copy:
src: "./files/{{ app_name }}/{{ item.name }}"
dest: "{{ (base_dir, item.name) | path_join }}"
owner: "{{ app_user }}"
group: "{{ app_user }}"
mode: "{{ item.mode }}"
loop:
- {name: "Dockerfile", mode: "0640"}
- {name: "entrypoint.sh", mode: "0750"}
- name: "Run application with docker compose" - name: "Run application with docker compose"
community.docker.docker_compose_v2: community.docker.docker_compose_v2:
project_src: "{{ base_dir }}" project_src: "{{ base_dir }}"
state: "present" state: "present"
build: "always"
remove_orphans: true remove_orphans: true
tags: tags:
- run-app - run-app