0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CloudWatch エージェントで既存ログを収集するためのサンプル設定

Posted at

CloudWatch>ロググループ>ライブテールでリアルタイムに参照することを考えると
特定のロググループは意味のある単位(まとめて時系列を追いたい単位)でまとめるのが良いと想像できる。

参考にさせていただいた記事

テスト用の設定ファイル

# cat /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
{
        "agent": {
                "run_as_user": "root"
        },
        "logs": {
                "logs_collected": {
                        "files": {
                                "collect_list": [
                                        {
                                                "file_path": "/var/work/sample.log",
                                                "log_group_class": "STANDARD",
                                                "log_group_name": "sample.log",
                                                "log_stream_name": "{instance_id}",
                                                "retention_in_days": 1
                                        },
                                        {
                                                "file_path": "/var/work/sample_2025-10-26_15-25-50.log",
                                                "log_group_class": "STANDARD",
                                                "log_group_name": "sample.log",
                                                "log_stream_name": "{instance_id}_2",
                                                "retention_in_days": 1
                                        }
                                ]
                        }
                }
        }
}

EC2にアタッチしたマネージドポリシー(組み込みポリシー)

CloudWatchAgentServerPolicy
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CWACloudWatchServerPermissions",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData",
                "ec2:DescribeVolumes",
                "ec2:DescribeTags",
                "logs:PutLogEvents",
                "logs:PutRetentionPolicy",
                "logs:DescribeLogStreams",
                "logs:DescribeLogGroups",
                "logs:CreateLogStream",
                "logs:CreateLogGroup",
                "xray:PutTraceSegments",
                "xray:PutTelemetryRecords",
                "xray:GetSamplingRules",
                "xray:GetSamplingTargets",
                "xray:GetSamplingStatisticSummaries"
            ],
            "Resource": "*"
        },
        {
            "Sid": "CWASSMServerPermissions",
            "Effect": "Allow",
            "Action": [
                "ssm:GetParameter"
            ],
            "Resource": "arn:aws:ssm:*:*:parameter/AmazonCloudWatch-*"
        }
    ]
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?