【问题标题】:AWS log Insigts parse NGINX logAWS log Insights 解析 NGINX 日志
【发布时间】:2022-02-18 11:08:27
【问题描述】:

我正在尝试使用 aws log insight 对包含 nginx 日志的日志组运行查询。

这是我在我的 ec2 机器上设置的日志格式:

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

示例 NGINX 日志:

xx.xx.xx.xx - - [10/Nov/2020:15:28:30 +0530] "POST /xx HTTP/1.1" 200 57 "https://xxxx.in/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"

我正在尝试使用带有以下代码的日志见解来解析此问题:

parse @message '* - - [*] "* * *" * * "-" "*"' as remote_addr, timestamp, request_type, location, protocol, response_code, body_bytes_sent

我收到以下错误:

Expression is invalid: parse@message'* - - [*] "* * *" * * "-" "*"'asremote_addr,timestamp,request_type,location,protocol,response_code,body_bytes_sent

任何帮助将不胜感激

【问题讨论】:

    标签: nginx amazon-cloudwatch amazon-cloudwatchlogs aws-cloudwatch-log-insights


    【解决方案1】:

    您已经完成了 99% 的工作。缺少的只是匹配选择器和输出变量的数量,因此如果您将user_agent 附加到您的列表中,它将开始工作。

    示例工作查询:

    fields @message
    | parse @message '* - - [*] "* * *" * * "-" "*"' as remote_addr, timestamp, request_type, location, protocol, response_code, body_bytes_sent, user_agent
    | display request_type, location
    

    【讨论】:

      【解决方案2】:

      如果有referrer和user_agent会更好

      fields @timestamp, @message
      | parse @message '* - - [*] "* * *" * * "*" "*"' as remote_addr, timestamp, request_type, location, protocol, response_code, body_bytes_sent, referrer, user_agent
      | display @timestamp, remote_addr, request_type, location, protocol, response_code, body_bytes_sent, referrer, user_agent
      | sort @timestamp desc
      

      【讨论】:

        猜你喜欢
        • 2014-11-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-01
        • 1970-01-01
        • 2017-09-24
        • 2017-07-07
        • 1970-01-01
        • 2019-10-12
        相关资源
        最近更新 更多