Web server log analysis using GoAccess

    image
    Not so long ago, we came across a GoAccess utility, which allows you to analyze web server logs and build reports. The utility is written in C and is available in almost all repositories of Linux distributions. Project Address .

    This article will not be anything revolutionary, just a short HOWTO, most of which you can find in the documentation.

    And so in order:

    1. Installation

    yum  install goaccess
    


    2. Settings

    In the /etc/goaccess.conf file, uncomment the lines for analyzing nginx logs:

    time-format %H:%M:%S
    date-format %d/%b/%Y
    log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" 
    


    3. Log

    analysis. The analysis result can be obtained in two modes, in console (interactive), and in the form of a report. The program supports several types of reports, such as html, json and csv.

    The simplest case of running the program is to analyze the current log:

    goaccess -a  -f 


    In this case, we get the analysis of the current log in the following form:
    image
    You can navigate through the parameters using TAB.

    And the web report will look like this:
    image

    Now, consider the case when we need to analyze not the entire log, but only a certain part of it:

    1. Analysis of the logs for the last 2 hours:

    sed -n '/'$(date '+%H:%M:%S' -d '2 hours ago')'/, $ p'   | goaccess -a 
    


    2. Analysis for the last 2 days:

    sed -n '/'$(date '+%d/%b/%Y' -d '2 day ago')'/, $ p'   | goaccess -a
    


    3. Analysis for a specific date:

    sed -n '/18\/Jan\/2016/,/19\/Jan\/2016/ p'   | goaccess -a 
    


    4. Getting html report:

    goaccess -a  -f  > report.html
    


    Author: System Administrator Company Magvai69

    Also popular now: