Real-time JSON export
Hi!
Would it be possible to obtain a real-time JSON export? I am using a Prometheus for monitoring and I would like to pull JSON, that GoAccess already makes, convert it into Prometheus metrics and store within it to use for alerting and Grafana charts.
Now, there is option to export data into JSON format, and I've seen an example linked in Readme that provides JSON output, but I am unsure how to get it on my instance. I am currently running GoAccess like this:
goaccess access.log --log-format=COMBINED --real-time-html -o /var/www/userdata/web/public/public_html/report.html
Thank you!
Great question! A few options come to mind: you could try reading from the named pipe under /tmp, though I’m not entirely sure if that would work. An easier method might be to use something like websocat to read directly from the WebSocket, for example, with websocat ws://your_goaccess_server:7890. You might even be able to do it with curl. It’s also possible to handle this with JavaScript if needed.
For a more direct approach, we’d need to tweak the real-time HTML output format and possibly add something like --real-time-json. However, I'm not sure where the output should be directed.
Having --real-time-json would be great even if it is redirected to a file. Alternatively, maybe you could register URL endpoints that would provide JSON/HTML/CSV output without a need to write to a file on disk?
Hi everybody.
Well, I see ... I think it's very weird write something like JSON at real-time into file on disk.
How to you read this? -- I.E. -- What is moment (in time) that JSON is complete and valid?
Remembering that, at time in time, it is rewrite from scratch !
So, I agree with @allinurl that be use websocket entry, or (in future) create specific entry-point (or API) for that.
Proposal: Real-Time JSON Output for GoAccess
To contribute to this discussion: I’m currently implementing something very similar using Python, and I fully support the idea of native real-time JSON output directly from GoAccess.
Why This Makes Sense
- NDJSON format (newline-delimited JSON) is perfect for real-time data streaming and processing.
- Writing to a
tmpfspath ensures fast access and avoids disk writes — great for embedded devices or systems with limited I/O. - Since GoAccess works with cumulative data, each new update could be simply appended as a new NDJSON line.
Suggested Features
-
Streamed output
- Output updates as NDJSON (
.ndjsonfile). - Append one new JSON object per update/interval.
- Output updates as NDJSON (
-
Retention / Prevalence limit
- Option to limit total lines in the NDJSON file (e.g. 1000 lines).
- Automatically delete oldest lines once limit is reached.
- This would effectively implement a sliding time window for real-time analysis.
-
Delivery options (to be implemented externally)
- Serve the NDJSON data through:
- Server-Sent Events (SSE)
- WebSocket (binary or text)
- REST API for on-demand queries
- Serve the NDJSON data through:
Example Use Case
- A device running GoAccess appends traffic stats every few seconds to
/mnt/goaccess.ndjson - A Node.js or Python service reads it and sends it live to the frontend dashboard
- The frontend handles display and filtering — without ever touching GoAccess internals
Why It’s Useful
- Decouples GoAccess from the delivery layer
- Enables modern real-time frontends without modifying the core
- Keeps things fast, clean, and extensible
If helpful, I can share a simple reference implementation in Python.