简体   繁体   English

在aws cloudwatch中过滤日志流

[英]Filter log streams in aws cloudwatch

Is there anyway to filter the log streams with patterns using the CloudWatch console? 无论如何使用CloudWatch控制台过滤使用模式的日志流?

For example, I have the following log streams in a log group - Log Group: 例如,我在日志组中有以下日志流 - 日志组:

'/var/prod/logs'. '在/ var / PROD /日志'。

Log Streams: 日志流:

/prod/[node_instance_id]/nginx_access / PROD / [node_instance_id] / nginx_access
/prod/[node_instance_id]/nginx_error / PROD / [node_instance_id] / nginx_error

I have a multi-node environment with auto scaling etc. So the log streams can be quite messy - here is an example of what I see in the log streams. 我有一个自动缩放等多节点环境。所以日志流可能非常混乱 - 这是我在日志流中看到的一个例子。

/prod/1a2b3c4d5e/nginx_access / PROD / 1a2b3c4d5e / nginx_access
/prod/1a2b3c4d5e/nginx_error / PROD / 1a2b3c4d5e / nginx_error
/prod/1b2b3c4d5e/nginx_access / PROD / 1b2b3c4d5e / nginx_access
/prod/1b2b3c4d5e/nginx_error / PROD / 1b2b3c4d5e / nginx_error
/prod/1c2b3c4d5e/nginx_access / PROD / 1c2b3c4d5e / nginx_access
/prod/1c2b3c4d5e/nginx_error / PROD / 1c2b3c4d5e / nginx_error

I am trying to filter the log streams to be all 'nginx_access' only. 我试图过滤日志流只是'nginx_access'。 But from the console, it looks like I can only specify the prefix. 但是从控制台看,我看起来只能指定前缀。 Is there anyway that I could filter log streams using something like '*nginx_access'? 无论如何,我可以使用'* nginx_access'之类的东西过滤日志流吗?

The DescribeLogStreams API only supports filtering by prefix, and the console is listing your log streams with that API. DescribeLogStreams API仅支持按前缀过滤,控制台将使用该API列出您的日志流。 It is not possible to filter by something other than a prefix. 无法通过前缀之外的其他内容进行过滤。

The best practice in your case would be to use 2 log groups, one for each type: 在您的情况下,最佳做法是使用2个日志组,每种类型一个:

  • /var/prod/nginx_access 在/ var / PROD / nginx_access
  • /var/prod/nginx_error 在/ var / PROD / nginx_error

That way you can navigate to your logs by first choosing the appropriate log group, and then searching for the instance id with the prefix filter. 这样,您可以首先选择适当的日志组,然后使用前缀过滤器搜索实例ID,从而导航到日志。

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

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