スキップしてコンテンツを表示

How to use regex in CloudWatch agent to exclude specific files from a log group?

0

Hello AWS community,

I am currently setting up CloudWatch logs on my EC2 instance using the CloudWatch agent. I have the following use case, but I'm facing difficulties filtering files using regex:

# My goal:

I have two categories of log files:

Files that match the pattern *_error_yyyymmdd.log, which I want to send to a log group called /logs/error

and Files that match the pattern *_web_error_yyyymmdd.log are sent to a different log group /logs/web_error

I do not want the logs from web_error be included in error log group.

I try to use regular expression but not work. Does cloud watch agent configuration file support regex for file path? If not, is there any simple way to implement this?

Thank you!

1回答
1
承認された回答

Hello.

As far as I know, only the asterisk wildcard can be used in the Logs section of CloudWatch Agent.
Therefore, I think the problem can be solved by creating separate directories for "_error_yyyymmdd.log" and "_web_error_yyyymmdd.log".
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Logssection

In other words, as shown below, it is possible to set the file path in the CloudWatch Agent settings, so I think you can deal with this by changing the output file path on the application side.

      "files": {
        "collect_list": [
          {
            "file_path": "/var/log/httpd/error/logs/*_error_*.log",
            "log_group_name": "/logs/error",
            "log_stream_name": "{instance_id}"
          },
          {
            "file_path": "/var/log/httpd/web_error/logs/*_web_error_*.log",
            "log_group_name": "/logs/web_error",
            "log_stream_name": "{instance_id}"
          }
        ]
      }
エキスパート
回答済み 2年前
エキスパート
レビュー済み 2年前
エキスパート
レビュー済み 2年前
  • Thank you for your answer. So I need to separate the output filepath of these 2 logs type to different directory.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

関連するコンテンツ