LoginSignup
1
1

CloudWatchAgentをインストールしてサーバーの監視を行う④(Linux用CloudWatchAgentConfigファイルの生成、CloudWatchAgent起動)

Last updated at Posted at 2024-02-29

前回の記事にてEC2へCloudWatchAgentのインストールを行いました。
今回は、Linuxサーバー用にCloudWatchAgentConfigファイルを作成し、CloudWatchAgentの起動をする手順についてご紹介します。
amazon-cloudwatch-agent-config-wizardを実行した際の設定内容と、CloudWatchAgentの起動・常駐化・停止コマンド、amazon-cloudwatch-agent-ctlのコマンドリファレンスなどを確認していきます。

作業の流れ

1.VPCへCloudWatchAgentに必要なVPCエンドポイントを作成する
2.EC2を構築し、IAMロールをアタッチする(CloudWatchAgentとSSM権限の付与)
3.EC2に対してCloudWatchAgentをインストールする
4.CloudWatchAgentのconfigファイルを設定し、CPU・メモリ・プロセスなどのメトリクスを取得する
  Linux用CloudwatchAgent設定ファイルの生成・CloudwatchAgentの起動←いまここ
  Windows用CloudwatchAgent設定ファイルの生成・CloudwatchAgentの起動
5.SNSトピックの作成
6.CloudWatchAgentで取得したメトリクスに対してCloudWatchAlarmを設定する

構成図確認

改めて構成図を確認します。
前回の記事にて、EC2内にCloudWatchAgentをインストールしました。
今回はCloudWatchAgentConfigファイルの作成・記述を中心に作業していきます。
image.png

CloudWatchAgentConfigファイルについて

CloudWatchAgentを利用してEC2のメモリ使用率・ディスク使用率・プロセス死活監視を行う際は、監視したいメトリクスの内容をCloudWatchAgentのConfigファイルに定義する必要があります。

CloudwatchAgent設定ウィザード(Linux)でConfigファイルを生成する

まずはCloudWatchAgentがインストールされたサーバーにて、CloudWatchAgent設定ウィザードによるConfigファイル作成を行います。
EC2にログインし、下記コマンドを実行します。

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

コマンドを実行すると、CloudWatchAgentの設定ファイル作成ウィザードが立ち上がります。

================================================================
= Welcome to the Amazon CloudWatch Agent Configuration Manager =
=                                                              =
= CloudWatch Agent allows you to collect metrics and logs from =
= your host and send them to CloudWatch. Additional CloudWatch =
= charges may apply.                                           =
================================================================

対話式でCloudWatchAgentの設定ファイルを生成できるので、質問の回答を選んでいきましょう。下記からはCloudWatchAgentウィザードの質問内容と回答例を記載していきます。
※質問内容はCloudWatchAgentのバージョンによって異なります。本記事の内容はCloudWatchAgent1.300031.0b313の内容です。

使用するOSの種類

On which OS are you planning to use the agent?
1. linux
2. windows
3. darwin
default choice: [1]:
1

今回はLinuxへCloudWatchAgentをインストールするので、[1]を選択します。

CloudWatchAgentを利用するサーバーの種別(EC2かオンプレのサーバーか)

Trying to fetch the default region based on ec2 metadata...
I! imds retry client will retry 1 timesAre you using EC2 or On-Premises hosts?
1. EC2
2. On-Premises
default choice: [1]:

今回はEC2へインストールするので[1]を選択します。

CloudWatchAgentを動かすユーザー

Which user are you planning to run the agent?
1. cwagent
2. root
3. others
default choice: [1]:
1

今回はcwagentで起動させたいので[1]を選択します。
※セキュリティ的には、デーモンプロセスを動かすユーザーには最小限の権限のみ付与する方が望ましいです。システムのセキュリティポリシーに従い、必要な場合はcwagentユーザー等を設定することも検討してください。
参考:CloudWatch エージェントの別のユーザーとしての実行

StatsDデーモンの利用有無

Do you want to turn on StatsD daemon?
1. yes
2. no
default choice: [1]:
1

StatsDの利用有無です。StatsDはオープンソースのシステム統計ツールで、CloudWatchAgentのカスタムメトリクス取得のために利用されています。
今回はCloudWatchAgentでメモリ・ディスク監視などのカスタムメトリクスを収集するため、[1]を選択します。
参考:StatsD を使用してカスタムメトリクスを取得する

StatsDデーモンにて使用するポート番号

Which port do you want StatsD daemon to listen to?
default choice: [8125]

StatsDデーモンで利用するポート番号です。
今回はデフォルトの8125番を使用します。

StatsDデーモンが情報を集める間隔

What is the collect interval for StatsD daemon?
1. 10s
2. 30s
3. 60s
default choice: [1]:

StatsDデーモンが情報を収集する際の時間間隔です。
これもデフォルトの10秒を使用します。

StatsDデーモンがメトリクスを集約する間隔

What is the aggregation interval for metrics collected by StatsD daemon?
1. Do not aggregate
2. 10s
3. 30s
4. 60s
default choice: [4]:

StatsDデーモンがメトリクスを集約する際の時間間隔です。
これもデフォルトの60秒を使用します。

CollectDの利用有無

Do you want to monitor metrics from CollectD?
WARNING: CollectD must be installed or the Agent will fail to start
1. yes
2. no
default choice: [1]:

CollectDの利用有無です。CollectDもオープンソースのシステム統計ツールです。Linux系OSの場合、CloudWatchAgentを利用してメモリ使用率やディスク利用率・プロセス数などのカスタムメトリクス監視を行いたい場合は、CollectDを利用します。
今回はメトリクスやディスク使用率監視を行いたいため、デフォルトの[1]を選択します。
参考:collectd を使用してカスタムメトリクスを取得する

※また、ここの設定事項の中には「WARNING: CollectD must be installed or the Agent will fail to start」という警告があります。
サーバーにCollectDがインストールされていない場合は、CloudWatchAgentの起動時に下記のようなエラーメッセージが出力され、Agentの起動に失敗します。

 Error running agent: Error parsing /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml, open /usr/share/collectd/types.db: no such file or directory

上記エラーが出た場合は下記URLの手順を参考にcollectDをインストールする必要があります。
・AmazonLinux2の場合のCollectDインストール手順
参考:Amazon公式ブログ:CloudWatch エージェントとcollectd の使用開始
※「Step 4: Install/configure with State Manager」内の「collectd: manually」の手順参照
・その他Linux系OSの場合はEPEL リポジトリの有効化後にCollectDをインストール
参考:CentOS、RHEL、または Amazon Linux を実行している Amazon EC2 インスタンスの EPEL リポジトリを有効にする方法を教えてください

CPU・メモリのカスタムメトリクス収集有無

Do you want to monitor any host metrics? e.g. CPU, memory, etc.
1. yes
2. no
default choice: [1]:

CPU・メモリ監視の有無です。CPU・メモリ監視を行いたいため、[1]を選択します。

コア当たりのCPUメトリクス収集の有無

Do you want to monitor cpu metrics per core?
1. yes
2. no
default choice: [1]:

1コア当たりのメモリ・CPUメトリクス収集の有無です。
ここはデフォルトの[1]を選択します。

EC2メトリクスのディメンションとしてイメージID・インスタンスID・インスタンスタイプ、オートスケーリンググループ名を追加するか

Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available?
1. yes
2. no
default choice: [1]:

CloudWatchメトリクスのディメンションの設定です。
ディメンションはメトリクスの識別に使われる値です。
この値を1にすると、AWSマネジメントコンソール上からはこのような見え方でメトリクスが出力されます。
image.png

ディメンションを設定すると、上記画像のように、イメージID・インスタンスID・インスタンスタイプなどの情報がメトリクスの識別子として追加されます。
CloudWatchメトリクスのディメンションにどのような情報を付与するかは、運用にも関わってくる部分です。CloudWatchAgentを用いてサーバー監視を行う場合は、実際の運用フローも考慮しながら取得するメトリクスやディメンションを設定してください。
※ここについては、別記事にて補足していこうと思います。

メトリクスをインスタンスIDで集約するか

Do you want to aggregate ec2 dimensions (InstanceId)?
1. yes
2. no
default choice: [1]:
1

収集されたメトリクスが集計されるディメンションとしてインスタンスIDを指定するか否かの設定です。今回はデフォルトの[1]を選択します。
この値を1にすると、AWSマネジメントコンソール上からはこのような見え方でメトリクスが出力されます。
image.png

サーバー内の環境によって、単一インスタンスから複数のメトリクスが出力される場合もあります。例えば、CPU利用率がコアごとに別々のメトリクスで出力されたり、ディスク使用率がディスク全体ではなくマウントポイントやデバイスごとに出力されることが考えられます。インスタンスIDでメトリクスを集計することで、別々に出力されるメトリクスをインスタンスID毎にまとめることができます。

メトリクス収集を高頻度で行うか

Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution for all metrics, but you can customize for specific metrics in the output json file.
1. 1s
2. 10s
3. 30s
4. 60s
default choice: [4]:

メトリクス収集を高頻度で行うか否かの設定です。
今回は60秒未満でメトリクス収集を行う必要はないため、デフォルトの60秒を選択します。

メトリクスセットの確認

Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:

CloudWatchで収集したいメトリクスセットに関する設定項目です。Basic・Standard・Advancedそれぞれの設定で、収集されるメトリクスが変わります。今回は検証用のため[1](Basic)を選択します。

参考:CloudWatch エージェントの事前定義されたメトリクスセット

ここまでの設定内容の確認

ここまで設定すると、これまでの設定内容から生成されたConfigファイルがJson形式で出力されます。

Current config as follows:

出力されるJSONは、例えば下記のような形になります。

出力されるJsonの例(折り畳み)
{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "cwagent"
        },
        "metrics": {
                "aggregation_dimensions": [
                        [
                                "InstanceId"
                        ]
                ],
                "append_dimensions": {
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
                        "ImageId": "${aws:ImageId}",
                        "InstanceId": "${aws:InstanceId}",
                        "InstanceType": "${aws:InstanceType}"
                },
                "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"
                        }
                }
        }
}
Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additional items.
1. yes
2. no
default choice: [1]:

ここまでの設定内容に問題がないかの確認です。
出力されたJsonファイルの内容で大丈夫な場合は、[1]を選択します。

CloudwatchLogsエージェントの存在確認

Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration?
1. yes
2. no
default choice: [2]:

既にCloudWachLogAgentをインストールしており、インポートする設定ファイルが存在するかどうかの確認です。デフォルトの状態であればサーバー内にCloudWachLogAgentは存在しないはずなので、[2]を選択します。

監視対象のログファイルに関する確認

Do you want to monitor any log files?
1. yes
2. no
default choice: [1]:

監視したいログファイルがあるかどうかの設定です。今回は/var/log/messagesを監視したいため、[1]を選択します。

Log file path:

監視対象のログファイルのパスを入力します。今回は/var/log/messagesを監視したいため、下記のように入力しエンターキーを押下します。

Log file path:
/var/log/messages

ログファイルのパスを入力すると、ロググループ名を聞かれます。

Log group name:
default choice: [messages]

今回はロググループ名をデフォルトの「messages」として設定するため、表示内容から変更せずエンターキーを押下します。

Log group class:
1. STANDARD
2. INFREQUENT_ACCESS
default choice: [1]:

CloudWatchLogsのロググループのクラスをスタンダードクラスとするか低頻度アクセスクラスとするかの設定です。今回はスタンダードクラスを利用したいため、[1]を選択します。
低頻度アクセスのロググループを利用した場合、データ転送量がスタンダードクラスのロググループの半額程度になります。しかし、サブスクリプションフィルタやメトリクスフィルタなどの機能を利用することができません。
参考:アクセス頻度の低いログ用の新しい Amazon CloudWatch ログクラスを割引価格で提供(Amazon Web Services ブログ)

Log stream name:
default choice: [{instance_id}]

ログストリーム名の設定です。今回はデフォルトのインスタンスIDでログストリームを出力したいため、[1]を選択します。

Log Group Retention in days
1. -1
2. 1
3. 3
4. 5
5. 7
6. 14
7. 30
8. 60
9. 90
10. 120
11. 150
12. 180
13. 365
14. 400
15. 545
16. 731
17. 1096
18. 1827
19. 2192
20. 2557
21. 2922
22. 3288
23. 3653
default choice: [1]:

ロググループの保持期間です。「-1」を指定すると、無制限でログが保持されるようになります。今回は検証のためデフォルトの[1](ログ保持期間無制限)を選択します。
CloudWachLogは保持する際に0.033USD/GBの料金が発生するため、実際に設定を行う際はコストも念頭に置いたうえで保持期間を指定してください。
参考:Amazon CloudWatch 料金表

Do you want to specify any additional log files to monitor?
1. yes
2. no
default choice: [1]:
2

さらに収集したいログがあるかどうかの設定です。今回は/var/log/messagesのみログ監視するため、[2]を選択します。

x-ray利用有無に関する確認

Do you want the CloudWatch agent to also retrieve X-ray traces?
1. yes
2. no
default choice: [1]:
2

x-rayとCloudWatchを統合するかどうかの設定です。今回はx-rayは試用しない為、[2]を選択します。
x-rayを利用すると、サーバー内のアプリケーションが処理するリクエストについてデータ収集を行い、コンソール上から分析・表示することができるようになります。
参考:AWS X-Ray の概要

設定ファイルの保管先・バックアップ先の通知、設定ファイルの内容確認

Existing config JSON identified and copied to:  /opt/aws/amazon-cloudwatch-agent/etc/backup-configs
Saved config file to /opt/aws/amazon-cloudwatch-agent/bin/config.json successfully.
Current config as follows:

Configウィザードによって生成された設定ファイルの保管先・バックアップ先と、生成されたjsonファイルの内容が表示されます。
Configウィザードによって生成された設定ファイルは、下記に保管されます。

[ColoudWatchAgentのConfigファイル保管先]
/opt/aws/amazon-cloudwatch-agent/bin/config.json

また、config.jsonは下記ディレクトリにバックアップされます。

[CLoudWatchAgentのConfigファイルバックアップ先]
/opt/aws/amazon-cloudwatch-agent/etc/backup-configs

CloudWatchConfigウィザードにより生成されたJSONファイルは、例えば下記のような内容になります。

config.jsonの例
{
        "agent": {
                "metrics_collection_interval": 60,
                "run_as_user": "cwagent"
        },
        "logs": {
                "logs_collected": {
                        "files": {
                                "collect_list": [
                                        {
                                                "file_path": "/var/log/messages",
                                                "log_group_class": "STANDARD",
                                                "log_group_name": "messages",
                                                "log_stream_name": "{instance_id}",
                                                "retention_in_days": -1
                                        }
                                ]
                        }
                }
        },
        "metrics": {
                "aggregation_dimensions": [
                        [
                                "InstanceId"
                        ]
                ],
                "append_dimensions": {
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
                        "ImageId": "${aws:ImageId}",
                        "InstanceId": "${aws:InstanceId}",
                        "InstanceType": "${aws:InstanceType}"
                },
                "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"
                        }
                }
        }
}
Please check the above content of the config.
The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json.
Edit it manually if needed.

「jsonファイルは/opt/aws/amazon-cloudwatch-agent/bin/config.jsonにあるので、必要なら手動で編集してください」というようなことが表示されます。

生成したConfigファイルをSSMパラメータストアにアップロードするかの確認

Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:
2
Program exits now.

config.jsonの内容ををSSMパラメータストアにアップロードするかどうか聞かれます。
今回はSSMパラメータストアにConfigファイルをアップロードしない為、[2]を選択しました。
これで、すべてのCloudWatchの設定ファイル生成が完了しました。

※パラメータストアにCloudWatchConfigファイルをアップロードする場合

EC2に設定しているIAMロールに「CloudWatchAgentAdminPolicy」の権限が付与されている場合は、[1]を選択するとSSMパラメータストアにConfigファイルをアップロードすることができます。
[1]を選択した場合は、下記のような形でパラメータストアの名前について追加質問が発生します。

What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our managed AWS policy)
default choice: [AmazonCloudWatch-linux]

パラメータストアにアップロードするCloudWatchConfigファイルは、必ず「AmazonCloudWatch-」で始まる名前にする必要があります。
参考:CloudWatch エージェントで使用する IAM ロールとユーザーを作成する

Trying to fetch the default region based on ec2 metadata...
I! imds retry client will retry 1 timesWhich region do you want to store the config in the parameter store?
default choice: [ap-northeast-1]

パラメータストアのリージョンを指定します。

Successfully put config to Parameter store agent-config-linux.
Program exits now.

パラメータストアにファイルを送信した場合、送信が成功すると上記のようなメッセージとともにウィザードが終了します。

CloudwatchAgentの操作

CloudWatchAgentのConfigファイル生成が完了したら、CloudWatchAgentを起動・常駐化などを行います。
CloudWatchAgentを起動・常駐化・ステータス確認などの操作は以下に記載するコマンドで行えます。

Configファイルの読み込み

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:Configファイルのパス

CloudWatchAgentのConfigウィザードを利用した場合は、/opt/aws/amazon-cloudwatch-agent/bin配下にconfig.jsonが存在する為下記コマンドを実行します。

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json

CloudWatchAgentの起動・常駐化・ステータス確認

■CloudWatchAgentの起動

sudo systemctl start amazon-cloudwatch-agent

■CloudWatchAgentの常駐化

sudo systemctl enable amazon-cloudwatch-agent

■CloudWatchAgentのステータス確認

sudo systemctl status amazon-cloudwatch-agent

■CloudWatchAgentの停止

sudo systemctl stop amazon-cloudwatch-agent

amazon-cloudwatch-agent-ctlコマンドのオプションについて

CloudWatchAgentのファイル読み込み・起動にはamazon-cloudwatch-agent-ctlコマンド(opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl)を使用します。
amazon-cloudwatch-agent-ctlコマンドについて公式ガイド内のリファレンスを探しましたが見当たらなかったため、サーバー内で出力したコマンドリファレンスをChatGPTに翻訳してもらったものをここに共有しておきます。
※ここにご紹介するコマンドリファレンスはCloudWatchAgentのバージョン1.300032.2b361にて確認したものです。

-a: アクションを指定します。

    stop: エージェントプロセスを停止します。
    start: エージェントプロセスを開始します。
    status: エージェントプロセスの状態を取得します。
    fetch-config: エージェントに設定を適用します。-c で設定の指定が必要です。対象の設定は、場所(SSMパラメータストア名、ファイル名)または 'default' に基づいています。
    append-config: 既存のJSON設定にローカルのJSON設定ファイルを追加します。-c で設定の指定が必要です。対象の設定は、場所(SSMパラメータストア名、ファイル名)または 'default' に基づいています。
    remove-config: エージェントの設定を削除します。-c で設定の指定が必要です。対象の設定は、場所(SSMパラメータストア名、ファイル名)、または 'all' に基づいています。
    set-log-level: ログレベルを設定します。-l でレベルを指定します。
-m: モードを指定します。

    ec2: EC2ホストであることを示します。
    onPremise, onPrem: オンプレミスホストであることを示します。
    auto: 環境をEC2メタデータから自動的に判断します。EC2メタデータが利用できない場合、正確でない可能性があります。
-c: Amazon CloudWatch エージェントの設定を指定します。

    default: クイックトライアル用のデフォルト設定。
    ssm:<parameter-store-name>: SSMパラメータストア名。
    file:<file-path>: ホスト上のファイルパス。
    all: すべての既存の設定。remove-config アクションにのみ適用されます。
-s: エージェントの設定後にオプションで再起動します。fetch-config、append-config、remove-config アクションでのみ使用されます。

-l: エージェントのログレベルを設定します。set-log-level アクションでのみ使用されます。

例えば、下記のように使えるようです。

EC2インスタンスにSSMパラメータストアの設定を適用し、その後エージェントを再起動

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s

-a……アクションを指定。
fetch-config……エージェントに設定を適用。
-m……モードを指定。上記例ではec2ホストを指定。
-c……CloudWatchAgentの設定ファイルを指定。上記例ではSSMパラメータストアの「AmazonCloudWatch-Config.json」を指定。
-s……エージェントに設定を適用後再起動するように指定。

オンプレミスホストにローカルのJSON設定ファイルを追加し、その後エージェントを再起動

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s

-a……アクションを指定。
append-config……既存のConfigファイルにローカルのJSONファイルを追加。
-m……モードを指定。上記例ではオンプレミスホストを指定。
-c……CloudWatchAgentの設定ファイルを指定。上記例では/tmp/config.jsonを指定。
-s……エージェントに/tmp/config.jsonの設定を追加後再起動するように指定。

CloudWatchAgentの状態確認

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status

-a……アクションを指定。
status……CloudWatchAgentの状態を取得。

また、出力したコマンドリファレンスの原文は下記となります。

amazon-cloudwatch-agent-ctlコマンドリファレンス(英語)(折り畳み)
    usage:  amazon-cloudwatch-agent-ctl -a
            stop|start|status|fetch-config|append-config|remove-config|set-log-level
            [-m ec2|onPremise|onPrem|auto]
            [-c default|all|ssm:<parameter-store-name>|file:<file-path>]
            [-s]
            [-l INFO|DEBUG|WARN|ERROR|OFF]

    e.g.
    1. apply a SSM parameter store config on EC2 instance and restart the agent afterwards:
        amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s
    2. append a local json config file on onPremise host and restart the agent afterwards:
        amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s
    3. query agent status:
        amazon-cloudwatch-agent-ctl -a status

    -a: action
        stop:                                   stop the agent process.
        start:                                  start the agent process.
        status:                                 get the status of the agent process.
        fetch-config:                           apply config for agent, followed by -c. Target config can be based on location (ssm parameter store name, file name), or 'default'.
        append-config:                          append json config with the existing json configs if any, followed by -c. Target config can be based on the location (ssm parameter store name, file name), or 'default'.
        remove-config:                          remove config for agent, followed by -c. Target config can be based on the location (ssm parameter store name, file name), or 'all'.
        set-log-level:                          sets the log level, followed by -l to provide the level in all caps.

    -m: mode
        ec2:                                    indicate this is on ec2 host.
        onPremise, onPrem:                      indicate this is on onPremise host.
        auto:                                   use ec2 metadata to determine the environment, may not be accurate if ec2 metadata is not available for some reason on EC2.

    -c: amazon-cloudwatch-agent configuration
        default:                                default configuration for quick trial.
        ssm:<parameter-store-name>:             ssm parameter store name.
        file:<file-path>:                       file path on the host.
        all:                                    all existing configs. Only apply to remove-config action.

    -s: optionally restart after configuring the agent configuration
        this parameter is used for 'fetch-config', 'append-config', 'remove-config' action only.

    -l: log level to set the agent to INFO, DEBUG, WARN, ERROR, or OFF
        this parameter is used for 'set-log-level' only.

ここまでお読みいただきありがとうございました。
本当はこの記事の中でCloudwatchメトリクスの出力確認まで書ききる予定でしたが、想定以上に記事が長くなってしまったため一旦ここで分割しようと思います。
次回はWindowsでのCloudwatchAgentConfigファイルの生成などについて確認していきます。
CloudWatchの設定ファイルの各項目については、別途補足記事を作成しようと思います。

1
1
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
1
1