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 agent設定ファイルから正規表現でプロセス監視

Last updated at Posted at 2025-09-09

liuwanying999

IAMロールの設定

ロール名:CWagent-test-role
IAMポリシーをアタッチします。
CloudWatchAgentServerPolicy
AdministratorAccess

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "*",
            "Resource": "*"
        }
    ]
}
EC2を構築

*無料版Linux EC2
 t3.micro
 キーペア CWagent-EC2-keypair

IAMロールをEC2にアタッチ
EC2のプロセスを確認

ps -ef: 全ユーザーの全プロセスを、さらに詳細な情報付きで表示します。
プロセスを確認した上で、agent設定ファイルのpatternセクションを修正

基本プロセスとして、systemdが存在するはず。
コマンドラインを利用するため、詳細なコマンドラインでpattern設定値に入れ替え。

例えば、/usr/lib/systemd/systemdの場合、
s*を^/usr/lib/systemd$に入れ替え。

"procstat": [
                        {
                            "pattern": "s*",
                            "measurement": [
                                "pid_count"
                             ],
                            "metrics_collection_interval": 60
                         }
EC2にCloudWatch Agentのインストール
CloudWatch Agentの設定

上記のプロセスpattern設定値を基づいて、設定ファイルを修正

{
    "agent": {
            "metrics_collection_interval": 60,
            "run_as_user": "cwagent"
    },
    "metrics": {
            "aggregation_dimensions": [
                    [
                            "InstanceId"
                    ]
            ],
            "append_dimensions": {
                    "InstanceId": "${aws:InstanceId}"
            },
            "metrics_collected": {
                    "collectd": {
                            "metrics_aggregation_interval": 60
                    },
                    "disk": {
                            "measurement": [
                                    "used_percent"
                            ],
                            "metrics_collection_interval": 60,
                            "resources": [
                                    "/"                            ]
                    },
                    "mem": {
                            "measurement": [
                                    "mem_used_percent"
                            ],
                            "metrics_collection_interval": 60
                    },
                    "statsd": {
                            "metrics_aggregation_interval": 60,
                            "metrics_collection_interval": 10,
                            "service_address": ":8125"
                    },
                    "procstat": [
                        {
                            "pattern": "s*",
                            "measurement": [
                                "pid_count"
                             ],
                            "metrics_collection_interval": 60
                         }                
               ]
            }
        }
}
AWSコンソール上でメトリクスを確認

.systemdというメトリクスがAWSコンソールに反映されていること

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?