LoginSignup
0
0

【AWS SageMaker】NotebookインスタンスのCPUやメモリ使用率をCloudWatchで取得してみた

Posted at

背景

AWS SageMakerのNotebookインスタンスにて、Pythonでのマルチプロセス処理を行いたいと思った時に、NotebookインスタンスのCPUやメモリ使用率が気になったので、それらを取得してみました。

取得方法(概要)

AWSのこちらのサイトの方法を試してみました。
具体的には、CloudWatchエージェントをNotebookインスタンスにインストールして、CPUやメモリ使用率を取得します。

 => CloudWatch を使用して SageMaker リソース使用率を表示する

取得方法(詳細)

※この内容は2024年4月時点のものになります。

1. Notebookインスタンスのターミナルにて、CloudWatchエージェントのインストールコマンドを入力

Notebookインスタンスのターミナルを開きます。

スクショ.PNG

CloudWatchエージェントのインストールコマンドを入力します。

sh-4.2$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

2. ウィザードに従って、CloudWatchエージェントのインストール設定

NotebookインスタンスのOSはAmazon Linuxなので、1を選択します。

================================================================
= 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: [1]:

AWSサイトに記載の指示通り、オンプレミスの2を選択します。

Are you using EC2 or On-Premises hosts?
1. EC2
2. On-Premises
default choice: [1]:

こちらは1を選択しました。他の選択肢でも大丈夫かもしれません。

Please make sure the credentials and region set correctly on your hosts.
Refer to http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
Which user are you planning to run the agent?
1. cwagent
2. root
3. others
default choice: [1]:

AWSサイトに記載の指示通り、noの2を選択します。

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

AWSサイトに記載の指示通り、noの2を選択します。

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

メトリクス情報を取得したいので、yesの1を選択しました。

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

取得したいCPUメトリクス次第ですが、yesの1を選択しました。

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

メトリクス情報の取得間隔になります。60秒間隔の4を選択しました。
(所望の取得間隔に応じて選択。)

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

今回はbasicの1を選択しました。
(より詳細な情報を所望の場合は、2や3を選択する事になると思います。)

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

表示された設定configのままでOKなので、yesの1を選択しました。

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

既存のCloudWatchエージェントは無いので、noの2を選択しました。

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

ログファイルの監視は不要なので、noの2を選択しました。

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

AWS X-rayは不要なので、noの2を選択しました。

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

SSM(AWS System Manager)パラメータストアへの設定configの保存は不要なので、noの2を選択しました。

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.
Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:

3. CloudWatchエージェントを起動

CloudWatchエージェントの起動コマンドを入力します。

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

4. CPUやメモリ使用率が取得出来ている事を確認

別途、マネジメントコンソールからAWS CloudWatchにアクセスして、MetricsからCWAgentをクリックします。

スクショ2.PNG

メモリ使用率を確認する場合は、hostをクリックします。

スクショ3.PNG

メトリクス名にmem_used_percentの記載がある行を選択して、当該メトリクスをグラフ表示します。

figure.png

メモリ使用率のグラフを確認出来ました。

スクショ5.PNG

補足

Notebookインスタンスを落とし上げすると、インスタンスが変わるため、CloudWatchでのメトリクス取得も改めて行う必要がありました。

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