AWS日志记录解析NGINX日志

时间:2020-11-10 10:08:35

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

我正在尝试使用aws日志洞察对包含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

任何帮助都会得到感谢

1 个答案:

答案 0 :(得分:3)

您已经完成了 99% 的工作。缺少的只是匹配选择器和输出变量的数量,因此如果您将 .../index/_search?q=content:"search term" 附加到您的列表中,它将开始工作。

示例工作查询:

user_agent