简体   繁体   English

AWS Cloudwatch Insights 如何使用多个日志组进行查询

[英]AWS Cloudwatch Insights how to query using multiple log groups

Reading the documentation seems that is possible in AWS Cloudwatch to run queries with multiple log groups but I can not see any example on how to do it.阅读文档似乎可以在 AWS Cloudwatch 中运行多个日志组的查询,但我看不到有关如何执行此操作的任何示例。

I would like to join two log groups using common attributes and select some logs using filter.我想加入两个使用公共属性的日志组和 select 使用过滤器的一些日志。

Has anyone run into the same problem and found a solution?有没有人遇到同样的问题并找到解决方案? Thanks in advance.提前致谢。

You can install Athena Cloudwatch Connector .您可以安装Athena Cloudwatch 连接器 Before that, you will able to query in Athena using each log group like a table.在此之前,您将能够像使用表一样使用每个日志组在 Athena 中进行查询。

select s.message, c.message, split_part(c.message, '/',3)
from "lambda:athena-cloudwatch-catalog"."/aws/lambda/<LOG_GROUP_1>".all_log_streams c,
"lambda:athena-cloudwatch-catalog"."/aws/lambda/<LOG_GROUP_2>".all_log_streams s
where 
s.message like split_part(c.message, '/',3) and
c.message like '%S3%';

If you are talking about AWS Console, the option to select multiple log groups is a checkbox and you can select over 20 log groups.如果您在谈论 AWS 控制台,则 select 多个日志组的选项是一个复选框,您可以 select 超过 20 个日志组。 AWS CloudWatch 见解控制台

If you refer to the AWS CLI, you can also choose multiple log groups.如果您参考 AWS CLI,您还可以选择多个日志组。 First create the query (in one or more log groups) ( https://docs.aws.amazon.com/cli/latest/reference/logs/start-query.html ) and then get the results ( https://docs.aws.amazon.com/cli/latest/reference/logs/get-query-results.html )首先创建查询(在一个或多个日志组中)( https://docs.aws.amazon.com/cli/latest/reference/logs/start-query.html )然后获取结果( Z5E056Z5050A1C807BADEA755050A1C4BADEA7 .aws.amazon.com/cli/latest/reference/logs/get-query-results.html

Example:例子:

Query creation with multiple log groups:使用多个日志组创建查询:

aws logs start-query --log-group-names "/aws/apigateway/welcome" "/aws/lambda/Test01" 
--start-time 1598936400000 --end-time 1611464400000 --query-string "fields @timestamp, 
@message"

Recover result from created query:从创建的查询中恢复结果:

aws logs get-query-results --query-id <query_id>

AWS CLI CloudWatch 见解

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM