Skip to content

Custom json #2810

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

Open
apnagaev opened this issue Mar 24, 2025 · 1 comment
Open

Custom json #2810

apnagaev opened this issue Mar 24, 2025 · 1 comment

Comments

@apnagaev
Copy link

apnagaev commented Mar 24, 2025

Hi! Can you help with parse my logs.
Configuration in openresty:

log_format main '{ '
        '"@timestamp": "$time_iso8601", '
        '"request_method": "$request_method", '
        '"request_uri": "$request_uri", '
        '"request_length": "$request_length", '
        '"server_protocol": "$server_protocol", '
        '"remote_addr": "$remote_addr", '
        '"referer": "$http_referer", '
        '"status": $status, '
        '"bytes": $body_bytes_sent, '
        '"agent": "$http_user_agent", '
        '"x_forwarded": "$http_x_forwarded_for", '
        '"host": "$http_host", '
        '"up_addr": "$upstream_addr",'
        '"up_host": "$upstream_http_host",'
        '"up_resp_time": "$upstream_response_time",'
        '"request_time": "$request_time",'
        '"req_id": "$http_req_id"'
        ' }';

 
    access_log  /tmp/cache/access.log  main;

I can't finde true log\date\time format for use goaccess(((

my log-file strings examles:

{ "@timestamp": "2025-03-18T21:23:38+03:00", "request_method": "GET", "request_uri": "/uri/", "request_length": "115", "server_protocol": "HTTP/1.1", "remote_addr": "10.90.90.104", "referer": "-", "status": 200, "bytes": 3269, "agent": "Blackbox Exporter/0.26.0", "x_forwarded": "-", "host": "mydomain.local", "up_addr": "192.168.192.168:80","up_host": "-","up_resp_time": "0.005","request_time": "0.005","req_id": "-" }
{ "@timestamp": "2025-03-18T21:23:38+03:00", "request_method": "GET", "request_uri": "/metrics", "request_length": "407", "server_protocol": "HTTP/1.1", "remote_addr": "10.90.90.104", "referer": "-", "status": 200, "bytes": 3783, "agent": "Prometheus/3.2.1", "x_forwarded": "-", "host": "10.90.90.78:80", "up_addr": "-","up_host": "-","up_resp_time": "-","request_time": "0.003","req_id": "-" }
{ "@timestamp": "2025-03-18T21:23:38+03:00", "request_method": "HEAD", "request_uri": "/", "request_length": "342", "server_protocol": "HTTP/1.1", "remote_addr": "3.20.63.178", "referer": "https://mydomain.local", "status": 301, "bytes": 0, "agent": "Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.uptimerobot.com/)", "x_forwarded": "-", "host": "mydomain.local", "up_addr": "-","up_host": "-","up_resp_time": "-","request_time": "0.000","req_id": "-" }
{ "@timestamp": "2025-03-18T21:23:38+03:00", "request_method": "GET", "request_uri": "/uri/", "request_length": "267", "server_protocol": "HTTP/1.1", "remote_addr": "10.90.90.107", "referer": "-", "status": 200, "bytes": 1074, "agent": "-", "x_forwarded": "-", "host": "mydomain.local", "up_addr": "10.90.90.76:82","up_host": "-","up_resp_time": "0.007","request_time": "0.007","req_id": "-" }
{ "@timestamp": "2025-03-18T21:23:38+03:00", "request_method": "GET", "request_uri": "/uri", "request_length": "267", "server_protocol": "HTTP/1.1", "remote_addr": "10.90.90.107", "referer": "-", "status": 200, "bytes": 686, "agent": "-", "x_forwarded": "-", "host": "mydomain.local", "up_addr": "10.90.90.76:82","up_host": "-","up_resp_time": "0.007","request_time": "0.007","req_id": "-" }
{ "@timestamp": "2025-03-18T21:23:39+03:00", "request_method": "GET", "request_uri": "/uri/", "request_length": "441", "server_protocol": "HTTP/1.1", "remote_addr": "10.90.90.107", "referer": "-", "status": 200, "bytes": 1074, "agent": "(http-plugin)", "x_forwarded": "-", "host": "mydomain.local", "up_addr": "10.90.90.76:82","up_host": "-","up_resp_time": "0.004","request_time": "0.004","req_id": "-" }

Thanks in advance!

@allinurl
Copy link
Owner

This should do it:

# goaccess log --log-format='{ "@timestamp": "%dT%t+%^", "request_method": "%m", "request_uri": "%U", "server_protocol": "%H", "remote_addr": "%h", "referer": "%R", "status": "%s", "bytes": "%b", "agent": "%u", "host": "%v", "request_time": "%T" }' --date-format=%Y-%m-%d --time-format=%T --date-spec=min

Image

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