From 3b1736534d951961e637428cce5ca8ba6ccca650 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Wed, 29 Apr 2026 20:26:05 +0300 Subject: [PATCH] GoAccess: combine host and path in reports --- files/goaccess/Dockerfile | 8 +++++++ files/goaccess/docker-compose.template.yml | 27 +++++++++++----------- files/goaccess/entrypoint.sh | 22 ++++++++++++++++++ playbook-goaccess.yml | 12 ++++++++++ 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 files/goaccess/Dockerfile create mode 100644 files/goaccess/entrypoint.sh diff --git a/files/goaccess/Dockerfile b/files/goaccess/Dockerfile new file mode 100644 index 0000000..8a48541 --- /dev/null +++ b/files/goaccess/Dockerfile @@ -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"] diff --git a/files/goaccess/docker-compose.template.yml b/files/goaccess/docker-compose.template.yml index 6080281..6515a17 100644 --- a/files/goaccess/docker-compose.template.yml +++ b/files/goaccess/docker-compose.template.yml @@ -1,22 +1,23 @@ services: goaccess_processor: - image: allinurl/goaccess:1.10.2 + build: . + image: local/goaccess-jq:1.10.2 container_name: goaccess_processor restart: unless-stopped + init: true user: "{{ app_owner_uid }}:{{ app_owner_gid }}" - command: > - --log-format=CADDY - --enable-panel=VIRTUAL_HOSTS - --real-time-html - --port=7890 - --ws-url=wss://goaccess.vakhrushev.me:443 - --output=/srv/report/index.html - --persist - --restore - --db-path=/srv/db - --no-global-config - /srv/logs/access.log + command: + - --log-format=COMBINED + - --enable-panel=VIRTUAL_HOSTS + - --real-time-html + - --port=7890 + - --ws-url=wss://goaccess.vakhrushev.me:443 + - --output=/srv/report/index.html + - --persist + - --restore + - --db-path=/srv/db + - --no-global-config volumes: - "{{ caddy_logs_dir }}:/srv/logs:ro" - "{{ db_dir }}:/srv/db" diff --git a/files/goaccess/entrypoint.sh b/files/goaccess/entrypoint.sh new file mode 100644 index 0000000..771519e --- /dev/null +++ b/files/goaccess/entrypoint.sh @@ -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 - "$@" diff --git a/playbook-goaccess.yml b/playbook-goaccess.yml index dc6d661..2bb83bf 100644 --- a/playbook-goaccess.yml +++ b/playbook-goaccess.yml @@ -69,10 +69,22 @@ group: "{{ app_user }}" 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" community.docker.docker_compose_v2: project_src: "{{ base_dir }}" state: "present" + build: "always" remove_orphans: true tags: - run-app