allinurl / goaccess

GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.
https://goaccess.io
MIT License
18.51k stars 1.11k forks source link

`--real-time-html` results not updated when log is updated #1807

Open alexpreynolds opened 4 years ago

alexpreynolds commented 4 years ago

Setup

I have a cron job that updates a summary log once per hour.

The summary is made up of a concatenation of two weeks worth of nginx logs and applies grep on the results, for a key for which we are interested in tracking statistics, e.g.:

$ grep foo <(zcat access.log.*.gz | cat access.log - ) > summary.log

The goaccess binary is compiled with debug support enabled and port 7890 is opened on the host:

# make clean
# ./configure --enable-utf8 --enable-geoip=legacy --with-openssl --enable-debug
# make && make install

We start goaccess with various parameters. The debug flag writes its log messages to standard output/error:

$ sudo goaccess summary.log -o report.html --real-time-html
Parsing... [0] [0/s]
WebSocket server ready to accept new client connections
Accepted: 13 1.2.3.4
Active: 0
Accepted: 13 1.2.3.4
Active: 0
Accepted: 13 1.2.3.4
Active: 0
Accepted: 13 1.2.3.4
Accepted: 14 1.2.3.5
Active: 1
Accepted: 13 1.2.3.4
Active: 1
Active: 0
...

The goaccess process correctly renders an analysis of the report log, as it was made initially.

Observed result

The problem is that goaccess only reports statistics for the static file summary.log when that log file was first made.

My understanding of the --real-time-html is that the goaccess report page should update itself, once summary.log is updated.

I have a cron job that runs the equivalent of the following, once per hour (paths simplified for describing this issue):

$ grep foo <(zcat access.log.*.gz | cat access.log - ) > summary.log

I can verify that the summary.log file is updated once per hour with new log hits.

The only way to get goaccess to show the analysis of this updated file is by stopping and restarting the goaccess process.

Expected result

This does not jibe with my understanding of what the --real-time-html option is supposed to do.

My expectation was that goaccess will update what it presents, as the log file is updated.

Question

How do I get goaccess to render an updated summary file, when it is updated, without stopping and restarting the goaccess process?

alexpreynolds commented 4 years ago

This issue may be related: https://github.com/allinurl/goaccess/issues/1803

allinurl commented 4 years ago

Sounds like you are rewriting the summary.log each time you run grep. Could you run it as?

# tail -f -n +0 access.log | grep --line-buffered 'foo' | goaccess -o out.html --real-time-html - 
alexpreynolds commented 4 years ago

My end goal is to run a daemon at startup on a collection of log files (some gzip-ed).

If goaccess can't track the summary when it changes, that's fine.

My "solution" is to run a cron job every hour to create a summary log file from the current log file and these archives, and then re-run goaccess every five minutes after the hour (without --real-time-html) to generate a static report.

I guess the issue is still that --real-time-html isn't reporting the true, current state of the log files, but maybe this and issue #1803 might be useful for testing.

allinurl commented 4 years ago

So far, from what I understand, it seems to me that simply re-running goaccess and generating a static report may be what you are looking for. GoAccess can keep track of previous runs by utilizing --persist and --restore. Though, the --real-time-html option was designed to open the log once and use fseek(3) and track the offset upon appending new data. e.g., tail -F

alexpreynolds commented 4 years ago

The cron job is effectively appending data, or at least it must be changing file offsets when the file content is changed.

Updating this statically is fine for my use case. I would perhaps suggest qualifying what this option can do, if it is only for a certain use case, or perhaps test if it works in a scenario where the input file data actually changes, as that does not appear to be the case here.

satyapm10 commented 4 years ago

Setup

I have a cron job that updates a summary log once per hour.

The summary is made up of a concatenation of two weeks worth of nginx logs and applies grep on the results, for a key for which we are interested in tracking statistics, e.g.:

$ grep foo <(zcat access.log.*.gz | cat access.log - ) > summary.log

The goaccess binary is compiled with debug support enabled and port 7890 is opened on the host:

# make clean
# ./configure --enable-utf8 --enable-geoip=legacy --with-openssl --enable-debug
# make && make install

We start goaccess with various parameters. The debug flag writes its log messages to standard output/error:

$ sudo goaccess summary.log -o report.html --real-time-html
Parsing... [0] [0/s]
WebSocket server ready to accept new client connections
Accepted: 13 1.2.3.4
Active: 0
Accepted: 13 1.2.3.4
Active: 0
Accepted: 13 1.2.3.4
Active: 0
Accepted: 13 1.2.3.4
Accepted: 14 1.2.3.5
Active: 1
Accepted: 13 1.2.3.4
Active: 1
Active: 0
...

The goaccess process correctly renders an analysis of the report log, as it was made initially.

Observed result

The problem is that goaccess only reports statistics for the static file summary.log when that log file was first made.

My understanding of the --real-time-html is that the goaccess report page should update itself, once summary.log is updated.

I have a cron job that runs the equivalent of the following, once per hour (paths simplified for describing this issue):

$ grep foo <(zcat access.log.*.gz | cat access.log - ) > summary.log

I can verify that the summary.log file is updated once per hour with new log hits.

The only way to get goaccess to show the analysis of this updated file is by stopping and restarting the goaccess process.

Expected result

This does not jibe with my understanding of what the --real-time-html option is supposed to do.

My expectation was that goaccess will update what it presents, as the log file is updated.

Question

How do I get goaccess to render an updated summary file, when it is updated, without stopping and restarting the goaccess process?

any solutions on this?

rusk0 commented 1 year ago

I am also wondering about that as well: GoAccess - 1.7.2.

Command :

/usr/bin/goaccess /var/log/nginx/production-access.log -o /var/www/html/production/index.html --log-format='%^ %^ %v [%d:%t %^] %~ %m %U %H %^ %^ %T %^ %s %b %R "%u" "%h" %^ %^' --time-format='%H:%M:%S' --date-format='%d/%b/%Y' --real-time-html and putting it in background

(Also tried --daemonize and the tail -f -n +0 suggested here)

I am still unable to get real time stats ?

Am i missing something ?

Going to leverage cronjobs for now as well.

allinurl commented 1 year ago

Hey @rusk0, are you seeing the green dot in the HTML report? It should be located near the gears icon in the navigation bar. If you're not seeing it, please check the console in your browser's developer tools.

cppgent0 commented 10 months ago

I'm having the same problem (Ubuntu 22.04)

$ goaccess --version
GoAccess - 1.8.1.
  --enable-utf8
  --enable-geoip=mmdb
  --with-getline
  --with-openssl

Start it with:

sudo goaccess -f /var/log/nginx/access.log -o /var/www/goaccess/index.html --real-time-html --addr=localhost --port=8022
$ ss -l 2>&1 | grep 8022
tcp   LISTEN 0      4096                                    127.0.0.1:8022                     0.0.0.0:*          

The nginx conf is:

    location /goaccess/ {
        root /var/www/goaccess;

        # no cache
        expires -1;
        sendfile off;
        add_header Cache-Control no-cache;
    }

The console shows:

image

For a few days it was working. I had goaccess started up in a service no problem I did ... something ... and now it's not live updating. If I restart goaccess it works perfectly. the goaccess.conf seems to be correct (as far as I know).

BTW I have tried adding these --ws-url to the command line, no joy:

allinurl commented 10 months ago

@cppgent0, can you recall the actions you performed that led to the issue? Have you tried running it using the following command:

# goaccess /var/log/nginx/access.log -o /var/www/goaccess/index.html --real-time-html

Ensure that port 7890 is open.

cppgent0 commented 10 months ago

can you recall the actions you performed that led to the issue?

I wish! But sorry, no.

Have you tried running it using the following command:

Just tried it now, got the same warning in the Chrome console image

also tried it with the full url for --ws-url:

sudo goaccess -f /var/log/nginx/access.log -o /var/www/goaccess/index.html --real-time-html --addr=localhost --port=8022 --ws-url=arrizza.com/goaccess/

and same error.

allinurl commented 10 months ago

@cppgent0 Did you provide the proper certificate and key in goaccess? It appears that you're attempting to access via HTTPS, indicating a secure WebSocket (WSS) connection.

MathNodes commented 3 months ago

@cppgent0, can you recall the actions you performed that led to the issue? Have you tried running it using the following command:

# goaccess /var/log/nginx/access.log -o /var/www/goaccess/index.html --real-time-html

Ensure that port 7890 is open.

This was the issue for us. need to open port 7890 with ufw