LoginSignup
0
0

More than 1 year has passed since last update.

EC2のWindowsサーバのメモリやディスク容量を監視したい

Posted at

はじめに

EC2のWindowsサーバはCloudWatchでCPUやネットワークI/Oくらいしか監視できません。メモリやディスク容量を監視する方法を見つけたので覚書します。

内容

作業の流れはこのようになります。

  • EC2にロールで権限を付与する
  • EC2にCloudWatch Agentをインストールおよび設定する
  • CloudWatchで監視を行う

EC2の準備

  1. EC2でWindowsサーバを作る
  2. EC2にロールを作成し、ポリシーCloudWatchAgentServerPolicyをアタッチします。

EC2のWindowsサーバ設定

ここからは監視対象のWindowsサーバーに管理者権限でログインして操作します。

  1. インストーラをダウンロードする。
    https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi
  2. ダウンロードしたインストーラを実行すると、このフォルダにインストールされます。
    C:\Program Files\Amazon\AmazonCloudWatchAgent
  3. インストールフォルダにある下記のプログラムを実行します。
    amazon-cloudwatch-agent-config-wizard.exe
  4. コマンドプロンプトの設定ウィザードが出てくるので、質問に答えていく。これによってインストールフォルダにconfig.jsonというファイルができます。
  5. 下記のサービスを起動します。
    Amazon CloudWatch Agent
ウィザードの質問と回答例
c:\Program Files\Amazon\AmazonCloudWatchAgent>amazon-cloudwatch-agent-config-wizard.exe
================================================================
= 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.                                           =
================================================================
On which OS are you planning to use the agent?
1. linux
2. windows
3. darwin
default choice: [2]:

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]:

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

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

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

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

Do you have any existing CloudWatch Log Agent configuration file to import for migration?
1. yes
2. no
default choice: [2]:

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

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

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]:

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

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]:

Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:
2
Current config as follows:
★省略★
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]:

Do you want to monitor any customized log files?
1. yes
2. no
default choice: [1]:
2
Do you want to monitor any Windows event log?
1. yes
2. no
default choice: [1]:
2
Saved config file to config.json successfully.
Current config as follows:
★省略★
Please check the above content of the config.
The config file is also located at config.json.
Edit it manually if needed.
Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:
2
Please press Enter to exit...

Program exits now.

CloudWatch画面からメトリクスを確認する

  1. AWSコンソールのCloudWatch画面で[メトリクス]-[すべてのメトリクス]を表示する。
  2. カスタム名前空間に[CWAgent]が作られるのでこれを開く。
  3. メトリクスをグラフ等で見る。
    image.png

おわりに

手順が多いので、メモリやディスク容量は最初から見えるとありがたいところです。しかし、ここで作ったconfig.jsonを使えば他のEC2でもAgentを入れて同じ情報を取得できるので、2代目以降はもう少し楽になると思います。

参考文献

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