[AWS]CloudWatch AgentのWindows版を試す
コンニチハ、千葉です。
CloudWatch Agentが発表され、メトリクスやログの収集も1つのエージェントで行えるようになりました。詳細については以下のエントリを参照してください。
今回はWindows版について試してみます。
試してみた
環境
- リージョン:東京
- AMI:ami-fc259e9a (Windows_Server-2016-Japanese-Full-Base-2017.11.29)
- インスタンスタイプ:t2.small
IAMポリシーのアタッチ
起動したEC2にAmazonSSMFullAccess
とAmazonEC2ReadOnlyAccess
をアタッチします。
SSMのバージョンアップ
SSMエージェントのバージョンが2.2.93.0
以上である必要があります。Systems Manager経由でアップデートしてみましょう。
現在のバージョンは2.2.64.0
だったので、アップデートします。Run Commandから実行します。
バージョンが2.2.103.0
にアップデートできました。
CloudWatch Agentのインストール
Run Commandでインストールします。Windowsの場合も、ログインせずにインストールすることができます。AmazonCloudWatchAgent
を指定します。
ログを確認したところSuccessfully installed arn:aws:ssm:::package/AmazonCloudWatchAgent 1.73.9
と表示されました。問題なくインストールできてます。
設定の出力
CloudWatch Agentの設定をパラメータストアに格納できます。これにより複数のインスタンスがあったとしても、SSMを利用して一括で設定することができます。設定情報を出力するためにWindowsにログインしコマンドを実行します。同じ設定を他のインスタンスにも適用する場合、この作業は1度のみ実施します。
windowsにログインしコンマンドプロンプトを起動し、以下を入力します。
1 2 | cd "C:\Program Files\Amazon\AmazonCloudWatchAgent" amazon-cloudwatch-agent-config-wizard.exe |
各設定項目を設定して行きます。OSはwindowsを選択します。
1 2 3 4 | Which OS are you planning to use the agent? 1. linux 2. windows default choice: [2]: |
EC2を選択します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Trying to fetch the default region based on ec2 metadata... Are you using EC2 or On-Premises hosts? 1. EC2 2. On-Premises default choice: [1]: 既存のCloudWatch Logの設定を移行するかですが、今回は新規なので移行しないを選択します。 Do you have any existing CloudWatch Log Agent configuration file to import for migration? 1. yes 2. no default choice: [2]: |
CPU、memoryなどメトリクスを取得を選択します。
1 2 3 4 | Do you want to monitor any host metrics? e.g. CPU, memory, etc. 1. yes 2. no default choice: [1]: |
コアあたりのCPUメトリクスを取得を選択します。
1 2 3 4 | Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply. 1. yes 2. no default choice: [1]: |
利用可能なディメンジョンを取得を選択します。
1 2 3 4 | 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]: |
60秒間隔でメトリクスを取得します。
1 2 3 4 5 6 | 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]: |
メトリクスの取得レベルを選択します。
1 2 3 4 5 6 | Which default metrics config do you want? 1. Basic 2. Standard 3. Advanced 4. None default choice: [1]: |
設定内容のjsonが出力され、内容を確認します。問題ないので1を選択します。
1 2 3 4 | 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]: |
監視するログファイルを指定します。今回は、監視しないため選択しませんでした。
1 2 3 4 5 | Do you want to monitor any customized log files? 1. yes 2. no default choice: [1]: 2 |
イベントログの監視を選択します。
1 2 3 4 | Do you want to monitor any Windows event log? 1. yes 2. no default choice: [1]: |
イベントログ名を指定します。
1 2 | Windows event log name: default choice: [System] |
取得するイベントログのレベルを指定します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | Do you want to monitor VERBOSE level events for Windows event log System ? 1. yes 2. no default choice: [1]: Do you want to monitor INFORMATION level events for Windows event log System ? 1. yes 2. no default choice: [1]: Do you want to monitor WARNING level events for Windows event log System ? 1. yes 2. no default choice: [1]: Do you want to monitor ERROR level events for Windows event log System ? 1. yes 2. no default choice: [1]: Do you want to monitor CRITICAL level events for Windows event log System ? 1. yes 2. no default choice: [1]: |
CloudWatchへ出力するロググループ名を指定します。
1 2 | Log group name: default choice: [System] |
CloudWatchログへ出力するときのフォーマットを指定します。
1 2 3 4 | In which format do you want to store windows event to CloudWatch Logs? 1. XML: XML format in Windows Event Viewer 2. Plain Text: Legacy CloudWatch Windows Agent (SSM Plugin) Format default choice: [1]: |
追加のログ設定は実施しないので2を選択します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | Do you want to specify any additional Windows event log to monitor? 1. yes 2. no default choice: [1]: 2 設定内容が記載されたjsonが表示されます。 [code:json] { "logs" : { "logs_collected" : { "windows_events" : { "collect_list" : [ { "event_format" : "xml" , "event_levels" : [ "VERBOSE" , "INFORMATION" , "WARNING" , "ERROR" , "CRITICAL" ], "event_name" : "System" , "log_group_name" : "System" } ] } } }, "metrics" : { "append_dimensions" : { "AutoScalingGroupName" : "${aws:AutoScalingGroupName}" , "ImageId" : "${aws:ImageId}" , "InstanceId" : "${aws:InstanceId}" , "InstanceType" : "${aws:InstanceType}" }, "metrics_collected" : { "Memory" : { "measurement" : [ "% Committed Bytes In Use" ], "metrics_collection_interval" : 60 }, "Paging File" : { "measurement" : [ "% Usage" ], "metrics_collection_interval" : 60, "resources" : [ "*" ] } } } } [ /code ] 設定をパラメータストアに保管を選択します。 Do you want to store the config in the SSM parameter store? 1. yes 2. no default choice: [1]: |
パラメータストア名を指定します。
1 2 | What is the parameter store name do you want to store your config? default choice: [agent-config-windows] |
データを格納するパラメータストアのリージョンを指定します。
1 2 3 | Trying to fetch the default region based on ec2 metadata... Which region do you want to store the config in the parameter store? default choice: [ap-northeast-1] |
パラメータストアに格納するためのクレデンシャルを指定します。これで設定が完了です。
1 2 3 4 | Which AWS credential should be used to send json config to parameter store? 1. XXXXXXXX(From SDK) 2. Other default choice: [1]: |
パラメータストアを確認してみます。CloudWatch Agent用の設定が格納されてました。
設定を反映
パラメータストアに出力した設定を利用し、CloudWatch Agentの設定をします。これはSSMを利用して実施します。
AmazonCloudWatch-ManageAgent
を選択し、設定を更新します。オプションに設定が格納されているパラメータストア名agent-config-windows
を指定します。
CloudWatchへの出力確認
CloudWatchからメトリクスが取得できているか確認します。
CloudWatchログが取得できています!
ディスク使用率やメモリも取得できてました!
最後に
今回は、Windowsに対してCloudWatch Agentの設定を行いました。多少のパラメータに差はありますが、手順としてはLinuxと同じ手順で実施できました。OSの差をあまり意識せずに設定できるのは便利だなぁと思いました。また、複数サーバに対して一括で設定できるのも効率的でかなり素敵です。