Simple Log Analyzer

Kalau kamu baca langsung log nginx bakal langsung pusing kan? Dengan GoAccess kamu bisa membaca log nginx secara realtime dan lebih mudah (karena ada interface nya).

GoAccess ini simpel ga perlu agent untuk ngirim log nya, bisa jalan di terminal atau bisa provide realtime HTML report.


Lists Tools You Must Installed

  1. nginx

  2. GoAccess


Hal yang Harus diperhatikan

  1. Pastikan user punya akses ke /var/log/nginx

  2. Kita ga akan menggunakan option –ssl di GoAccess jadi kamu ga usah build dari script, bisa install menggunakan apt get install goaccess

  3. Pastikan udah setup ssl nya di domain kamu. Di sini saya udah siapin 1 domain buat test, report.ipang.my.id

  4. It can work with cloudflare proxy but make sure you setup SSL/TLS mode correctly (I use “Full” mode because I enable cloudflare proxy and use Lets Encrypt on server)


Setup GoAccess di Nginx

  1. Run command goaccess
goaccess -f /var/log/nginx/access.log -o /tmp/report/index.html  --real-time-html --log-format=COMBINED  --ws-url=wss://report.ipang.my.id:443/socket.io --daemonized

# -f /var/log/nginx/access.log -> lokasi log yang mau di buat report
# -o /tmp/report/index.html -> lokasi report yang di generate goaccess
# --real-time-html -> buat report realtime
# --log-format=COMBINED -> [standard log format yang digunakanan beberapa webserver](http://fileformats.archiveteam.org/wiki/Combined_Log_Format)
# --ws-url=wss://report.ipang.my.id:443/socket.io  -> lokasi websocket, menggunakan wss (websocket secure) karena kita pake https tapi tetap harus di tulis port https nya 443. 
##--daemonized -> *run it in background*
  1. Tambahkan line berikut di config file nginx
    #setup for report.ipang.my.id
    #open report.ipang.my.id it will direct to goaccess report
    root /tmp/report/;

    location / {
        index index.html;
        try_files $uri $uri/ =404;
    }

     location /socket.io {
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection $connection_upgrade;
       proxy_pass http://localhost:7890;
       proxy_buffering off;
       proxy_read_timeout 7d;
     }
  1. Kalau kamu ga mau pake domain baru, bisa tambahin path baru untuk goaccess
  #setup for report.ipang.my.id/report.html
  location /report.html {
     alias /tmp/report/index.html;
    #please use basic_auth for security purpose
    #auth_basic_user_file /etc/nginx/.auth-report;
    #auth_basic "halo kak";
  }
GoAccess Realtime Working

GoAccess Realtime Working

Check Websocket at Network Tab

Check Websocket at Network Tab

Permasalahan yang Mungkin Kamu Temui

  1. Report tidak realtime. Ini banyak kemungkinan, tapi coba cek tab Network nya, apa benar websocket mengarah ke path /socket.io
Websocket Masih Mengarah ke Port

Websocket Masih Mengarah ke Port

  1. GoAccess tidak jalan di background. Jangan lupa gunakan opsi --daemonized

  2. Ga bisa setup/pake SSL di domain. Ga masalah, kamu masih bisa setup GoAccess tanpa SSL

goaccess -f /var/log/nginx/access.log -o /tmp/report/index.html  --real-time-html --log-format=COMBINED  --ws-url=ws://report.ipang.my.id:80/socket.io --daemonized

#remember it using ws:// than wss://

Jika kamu merasa tulisan ini bermanfaat & membantu kamu, kamu bisa berdonasi lewat saweria

If you feel this website help you, you can donate at saweria