CentOS 7使用goaccess分析nginx日誌

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

CentOS 7使用goaccess分析nginx日誌

世界上最可怕的事情,沒有之一

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

CentOS 7使用goaccess分析nginx日誌

世界上最可怕的事情,沒有之一

CentOS 7使用goaccess分析nginx日誌

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

CentOS 7使用goaccess分析nginx日誌

世界上最可怕的事情,沒有之一

CentOS 7使用goaccess分析nginx日誌

CentOS 7使用goaccess分析nginx日誌

在網頁上輸入程序員,出現的第一條就擊倒了我!!!

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

CentOS 7使用goaccess分析nginx日誌

世界上最可怕的事情,沒有之一

CentOS 7使用goaccess分析nginx日誌

CentOS 7使用goaccess分析nginx日誌

在網頁上輸入程序員,出現的第一條就擊倒了我!!!

CentOS 7使用goaccess分析nginx日誌

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

CentOS 7使用goaccess分析nginx日誌

世界上最可怕的事情,沒有之一

CentOS 7使用goaccess分析nginx日誌

CentOS 7使用goaccess分析nginx日誌

在網頁上輸入程序員,出現的第一條就擊倒了我!!!

CentOS 7使用goaccess分析nginx日誌

CentOS 7使用goaccess分析nginx日誌

然而,就算時光倒流,我還是想成為一個程序員。

背景

Web服務器如Nginx,Apache的access_log一般都包括了很多關鍵信息,可以用於性能分析或者運營分析,CentOS 7的EPEL源集成了一個非常好用access_log分析工具goaccess,本文主要記錄瞭如何使用goaccess進行nginx的日誌分析:

安裝

CentOS 7使用goaccess分析nginx日誌

配置

Nginx的log文件默認存放在/var/log/nginx/access_log, 基本的用法如下:

CentOS 7使用goaccess分析nginx日誌

第一次使用goaccess的時候,會彈出下面的對話框,要求配置access_log的時間和日誌格式, nginx默認的日誌格式就是NCSA, 所以一般就選第一個就可以了,然後goaccess在分析完成後會在終端上顯示分析結果。

CentOS 7使用goaccess分析nginx日誌

Goaccess還可以生成html格式的報表,有點可惜的是,目前好像僅支持English,命令也非常簡單:

CentOS 7使用goaccess分析nginx日誌

最後生成的報表包括pv, hits, agents等各種統計:

CentOS 7使用goaccess分析nginx日誌

高級用法

Goaccess也支持日誌定製,比如現在絕大部分nginx可能都會包括vhost,即一個物理nginx服務器可以支持多個域名的虛擬主機,但是nginx默認的NCSA日誌格式在/etc/nginx/nginx.conf中配置如下,不包括vhost字段, 所以我們就無法在報表中區分不同虛擬主機的請求:

CentOS 7使用goaccess分析nginx日誌

為了支持vhost,我將nginx的log_format定製成下面這個樣子, 主要是添加了$server_name字段用來顯示vhost, 還有末尾的$xxx_time, 用來顯示每個請求的耗時:

CentOS 7使用goaccess分析nginx日誌

為了讓goaccess能適配這個格式,需要將/etc/goaccess.conf中修改成如下格式:

CentOS 7使用goaccess分析nginx日誌

其中,具體的指示符號可以參考goaccess的官方文檔, 比如%^,代表忽略對應的字段:

SPECIFIERS

  • %x A date and time field matching the time-format and date-format variables. This is used when a timestamp is given instead of the date and time being in two separate variables.

  • %t time field matching the time-format variable.

  • %d date field matching the date-format variable.

  • %v The server name according to the canonical name setting (Server Blocks or Virtual Host).

  • %e This is the userid of the person requesting the document as determined by HTTP authentication.

  • %h host (the client IP address, either IPv4 or IPv6)

  • %r The request line from the client. This requires specific delimiters around the request (single quotes, double quotes, etc) to be parsable. Otherwise, use a combination of special format specifiers such as %m, %U, %q and %H to parse individual fields.

    Note: Use either %r to get the full request OR %m, %U, %q and %H to form your request, do not use both.

  • %m The request method.

  • %U The URL path requested.

    Note: If the query string is in %U, there is no need to use %q. However, if the URL path, does not include any query string, you may use %q and the query string will be appended to the request.

  • %q The query string.

  • %H The request protocol.

  • %s The status code that the server sends back to the client.

  • %b The size of the object returned to the client.

  • %R The "Referer" HTTP request header.

  • %u The user-agent HTTP request header.

  • %D The time taken to serve the request, in microseconds.

  • %T The time taken to serve the request, in seconds with milliseconds resolution.

  • %L The time taken to serve the request, in milliseconds as a decimal number.

  • %^ Ignore this field.

  • %~ Move forward through the log string until a non-space (!isspace) char is found.

  • ~h The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field.

Goaccess還可以從管道支持輸入,這樣可以做一些更靈活的處理,比如,access_log日誌中的request字段並不包括server_name, 為了讓request能夠包含完整的url, 我們可以用下面的命令,因為awk的第4列包含了server_name, 這個命令將server_name放到了request的前面組成了完整的url,再用作goaccess的輸入:

CentOS 7使用goaccess分析nginx日誌

末尾有彩蛋奧........


我們的名字

CentOS 7使用goaccess分析nginx日誌

上班的我,臉上寫滿了認真

CentOS 7使用goaccess分析nginx日誌

認真,讓我們邁向成功

大多數人都有“職業病”,還不輕,比如:

CentOS 7使用goaccess分析nginx日誌

別人在找不同,而我在在找bug......

CentOS 7使用goaccess分析nginx日誌

看到不好的代碼

CentOS 7使用goaccess分析nginx日誌

有時候也佩服別人

CentOS 7使用goaccess分析nginx日誌

世界上最可怕的事情,沒有之一

CentOS 7使用goaccess分析nginx日誌

CentOS 7使用goaccess分析nginx日誌

在網頁上輸入程序員,出現的第一條就擊倒了我!!!

CentOS 7使用goaccess分析nginx日誌

CentOS 7使用goaccess分析nginx日誌

然而,就算時光倒流,我還是想成為一個程序員。

CentOS 7使用goaccess分析nginx日誌

雲谷計算,原創出品。

相關推薦

推薦中...