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.59k stars 1.11k forks source link

Output file not created when using tail #1636

Open MosheElisha opened 4 years ago

MosheElisha commented 4 years ago

Hi,

When I use "tail", pipe and "--output" the output file is not created. Not while goaccess is running and not after I signal it to stop (Ctrl+C).

tail -F /var/log/nginx/access.log | /usr/local/bin/goaccess --output=/tmp/report.html --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %T %^ %^ %^' Output is Parsing... [10] [0/s]

I tried with "--output=/tmp/report.json" but same result. The output file wasn't created.

I saw that you have an example with tail and an output file so from that I understand it is a supported option (https://github.com/allinurl/goaccess/blame/master/README.md#L390)

Without an output file (interactive) it works properly:

tail -F /var/log/nginx/access.log | /usr/local/bin/goaccess --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %T %^ %^ %^'

With an input file (without tail) it works properly:

/usr/local/bin/goaccess /var/log/nginx/access.log --output=/var/www/html/report.html --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %T %^ %^ %^'

With tail and --real-time-html it works properly:

tail -F /var/log/nginx/access.log | /usr/local/bin/goaccess --output=/var/www/html/report.html --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %T %^ %^ %^' --fifo-in=/tmp/goaccess.in --fifo-out=/tmp/goaccess.out --real-time-html

My setup

$ goaccess --version
GoAccess - 1.3.
For more details visit: http://goaccess.io
Copyright (C) 2009-2016 by Gerardo Orellana

Build configure arguments:
  --enable-debug
  --enable-utf8
  --with-openssl
$ cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)

Thanks.

MosheElisha commented 4 years ago

I saw that if I use SIGPIPE (kill -13) on the "tail" command, the goaccess exists softly and the output file is written.

Is that the expected behavior?

allinurl commented 4 years ago

Can I ask you to try adding the additional single dash to the pipe? e.g.,

tail -F /var/log/nginx/access.log | /usr/local/bin/goaccess - --output=/tmp/report.html --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %T %^ %^ %^'
MosheElisha commented 4 years ago

Hi,

Thanks for replying. The dash did not help. I also tried tail -f instead of tail -F but same result (I did Ctrl+C after few some time)

$ tail -f /var/log/nginx/access.log | /usr/local/bin/goaccess - --output=/tmp/report.html --time-format='%T' --date-format='%d/%b/%Y' --log-format='%h - %^ [%d:%t %^] "%r" %s %b "%R" "%u" "%^" %T %^ %^ %^'
^Crsing... [10] [0/s]]
SIGINT caught!
Closing GoAccess...

$ ls /tmp/report.html
ls: cannot access /tmp/report.html: No such file or directory

I am OK with closing the stream into goaccess in order to gracefully shut it down and have the output file but if you want to pursue this, I will be happy to help if I can.

0bi-w6n-K3nobi commented 4 years ago

Try timeout command preceding tail:

timeout 1m tail -F ....

and it will end gracefully.

See the manual. You can also specify the signal sent to the command ahead.

allinurl commented 3 years ago

By the way, are you running this as root? it seems centos has some sort of issue when reading a log as a user. Maybe related to #868?