Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoAccess Parsing Log File #2568

Closed
dairoot opened this issue Oct 14, 2023 · 1 comment
Closed

GoAccess Parsing Log File #2568

dairoot opened this issue Oct 14, 2023 · 1 comment

Comments

@dairoot
Copy link

dairoot commented Oct 14, 2023

My logs look like this:

{"time_local":"15/Oct/2023:17:53:31 +0800","remote_addr":"10.0.3.15","request_method":"POST","request_uri":"/media/data/v5/materials","server_protocol":"HTTP/1.1","host":"ad.ifeiqu.com","request_body":"{\"start_date\":\"2023-10-09\",\"end_date\":\"2023-10-14\",\"order_by\":\"bef_cost\",\"reverse\":1,\"page_size\":20,\"page\":1,\"common\":\"仙侠\",\"media\":74,\"designer\":[\"705\",\"706\",\"707\",\"486\",\"491\",\"492\",\"139\",\"493\",\"495\",\"496\",\"497\",\"498\",\"526\",\"532\",\"547\",\"582\",\"611\",\"647\",\"652\",\"525\",\"527\",\"494\",\"485\",\"588\",\"499\",\"500\",\"501\",\"502\",\"610\",\"660\"],\"ywuser\":[\"690\"],\"games\":[15432,15430,15266,15027,15116,15167,15114,15026,14968,14557,11923,12013,11594,12003,12722,12944,13442,13487,13825,12673,13223,13353],\"sum_time\":0,\"sum_dimen\":0}","status":"200","body_bytes_sent":"6018","http_referrer":"https://ad.ifeiqu.com/","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36","http_x_forwarded_for":"112.94.213.4","request_time":1.718,"upstream_addr":"127.0.0.1:50006","upstream_connect_time":"0.000","upstream_header_time":"1.718","upstream_response_time":"1.718"}

Goaccess 命令,Mac OS,从brew 安装。

LC_TIME="en_US.UTF-8" goaccess t.log --log-format='{"time_local":"%x","remote_addr":"%h","request_method":"%m","request_uri":"%U","server_protocol":"%H","host":"%v","request_body":"%q","status":"%s","body_bytes_sent":"%b","http_referrer":"%R","http_user_agent":"%u","http_x_forwarded_for":"~h","request_time":%T,"upstream_addr":"%^","upstream_connect_time":"%^","upstream_header_time":"%^","upstream_response_time":"%^"}' --datetime-format='%d/%b/%Y:%H:%M:%S %z'

It gave me error, but the error is not obvious to me

==21385== GoAccess - version 1.8 - Oct  1 2023 05:45:10
==21385== Config file: /usr/local/Cellar/goaccess/1.8/etc/goaccess/goaccess.conf
==21385== https://goaccess.io - <hello@goaccess.io>
==21385== Released under the MIT License.
==21385==
==21385== FILE: t.log
==21385== Parsed 1 lines producing the following errors:
==21385==
==21385== Token for '%h' specifier is NULL.
==21385==
==21385== Format Errors - Verify your log/date/time format
Cleaning up resources...
@dairoot
Copy link
Author

dairoot commented Oct 14, 2023

My /etc/nginx/nginx.conf file look like this:


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format json_combined escape=json
  '{'
    '"time_local":"$time_local",'
    '"remote_addr":"$remote_addr",'
    '"request_method":"$request_method",'
    '"request_uri":"$request_uri",'
    '"server_protocol":"$server_protocol",'
    '"host":"$host",'
    '"request_body":"$request_body",'
    '"status":"$status",'
    '"body_bytes_sent":"$body_bytes_sent",'
    '"http_referrer":"$http_referer",'
    '"http_user_agent":"$http_user_agent",'
    '"http_x_forwarded_for":"$http_x_forwarded_for",'
    '"request_time":$request_time,'
    '"upstream_addr":"$upstream_addr",'
    '"upstream_connect_time":"$upstream_connect_time",'
    '"upstream_header_time":"$upstream_header_time",'
    '"upstream_response_time":"$upstream_response_time"'
  '}';

...

Propose a coding requirement: Can GoAccess automatically parse the log_format from the specified /etc/nginx/nginx.conf file to format the log file without users having to manually specify the log_format?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants