この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
直近 1 時間の東京リージョン〜大阪リージョンのレイテンシーを一発で確認したく、「インフラストラクチャのパフォーマンス」機能を AWS CLI で利用してみました。
AWS Network Manager の「インフラストラクチャのパフォーマンス」機能は最近リリースされた機能であり、AWS の任意のリージョン間や任意の AZ 間、特定の AZ 内のレイテンシーを確認できる機能です。レイテンシー情報を CloudWatch にメトリクスとして発行することもできます。
レイテンシーを AWS CLI で確認
直近 1 時間の東京リージョン〜大阪リージョン間のレイテンシーを取得する場合は下記を実行します。
START_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ" -d "1 hour ago"`
END_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ"`
aws ec2 get-aws-network-performance-data \
--start-time $START_TIME \
--end-time $END_TIME \
--data-queries Id=id1,Source=ap-northeast-1,Destination=ap-northeast-3,Metric=aggregate-latency,Statistic=p50,Period=five-minutes \
--output table
一行で記載すると下記です。
START_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ" -d "1 hour ago"`; END_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ"`; aws ec2 get-aws-network-performance-data --start-time $START_TIME --end-time $END_TIME --data-queries Id=id1,Source=ap-northeast-1,Destination=ap-northeast-3,Metric=aggregate-latency,Statistic=p50,Period=five-minutes --output table
実行結果例です。Value
がレイテンシー情報です。なお、2022 年 12 月 5 日時点では、AWS CloudShell で実行する場合は AWS CLI v2 のバージョンアップが必要でした。
$ aws --version
aws-cli/2.9.4 Python/3.9.11 Linux/4.14.294-220.533.amzn2.x86_64 exec-env/CloudShell exe/x86_64.amzn.2 prompt/off
$ START_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ" -d "1 hour ago"`; END_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ"`; aws ec2 get-aws-network-performance-data --start-time $START_TIME --end-time $END_TIME --data-queries Id=id1,Source=ap-northeast-1,Destination=ap-northeast-3,Metric=aggregate-latency,Statistic=p50,Period=five-minutes --output table
-------------------------------------------------------------------------------------------------
| GetAwsNetworkPerformanceData |
+-----------------------------------------------------------------------------------------------+
|| DataResponses ||
|+----------------+------+--------------------+---------------+------------------+-------------+|
|| Destination | Id | Metric | Period | Source | Statistic ||
|+----------------+------+--------------------+---------------+------------------+-------------+|
|| ap-northeast-3| id1 | aggregate-latency | five-minutes | ap-northeast-1 | p50 ||
|+----------------+------+--------------------+---------------+------------------+-------------+|
||| MetricPoints |||
||+-------------------------------+---------------------------------+-----------+-------------+||
||| EndDate | StartDate | Status | Value |||
||+-------------------------------+---------------------------------+-----------+-------------+||
||| 2022-12-05T08:55:00+00:00 | 2022-12-05T08:50:00+00:00 | OK | 8.152991 |||
||| 2022-12-05T09:00:00+00:00 | 2022-12-05T08:55:00+00:00 | OK | 8.13745 |||
||| 2022-12-05T09:05:00+00:00 | 2022-12-05T09:00:00+00:00 | OK | 8.158973 |||
||| 2022-12-05T09:10:00+00:00 | 2022-12-05T09:05:00+00:00 | OK | 8.15698 |||
||| 2022-12-05T09:15:00+00:00 | 2022-12-05T09:10:00+00:00 | OK | 8.148474 |||
||| 2022-12-05T09:20:00+00:00 | 2022-12-05T09:15:00+00:00 | OK | 8.135941 |||
||| 2022-12-05T09:25:00+00:00 | 2022-12-05T09:20:00+00:00 | OK | 8.145973 |||
||| 2022-12-05T09:30:00+00:00 | 2022-12-05T09:25:00+00:00 | OK | 8.151984 |||
||| 2022-12-05T09:35:00+00:00 | 2022-12-05T09:30:00+00:00 | OK | 8.15449 |||
||| 2022-12-05T09:40:00+00:00 | 2022-12-05T09:35:00+00:00 | OK | 8.139469 |||
||| 2022-12-05T09:45:00+00:00 | 2022-12-05T09:40:00+00:00 | OK | 8.137439 |||
||+-------------------------------+---------------------------------+-----------+-------------+||
出力結果の時間は UTC です。
出力形式はoutput
オプションでtable
形式を指定していますが、任意の出力形式に変更することも query
で出力内容を限定することもできます。
コマンドの実行内容の説明
ここからは、上記で実行したコマンドに関する説明となります。
パラメータを変えることで、任意のリージョン間や任意の AZ 間、特定の AZ 内のレイテンシーに変更したり、レイテンシーの取得期間を変更したりできます。
まず、AWS CLI の利用に関するユーザーガイドは次の箇所です。
Monitor network infrastructure performance - Amazon Virtual Private Cloud
レイテンシーを取得するget-aws-network-performance-data
コマンドのドキュメントです。
get-aws-network-performance-data — AWS CLI 1.27.22 Command Reference
get-aws-network-performance-data — AWS CLI 2.9.4 Command Reference
get-aws-network-performance-data
コマンドの実行において次のオプション指定は必須でした。
- start-time
- end-time
- data-queries
start-time
とend-time
はレイテンシーの値を取得する期間を指定します。
今回はdate
コマンドで現在の時刻と 1 時間前の時刻を整形・出力して利用しています。
現在の時刻を整形して出力する例です。
$ date "+%Y-%m-%dT%H:%M:%3SZ"
2022-12-05T09:43:022Z
1 時間前の時刻を整形して出力する例です。hour
以外にsecond
minute
month
year
を指定することもできます。
$ date "+%Y-%m-%dT%H:%M:%3SZ" -d "1 hour ago"
2022-12-05T08:43:022Z
data-queries
オプションのパラメータについて補足します。
- Id
- クエリに関連付けされるユーザー定義の ID です
- 任意の値でよいので AWS CLI のドキュメントと同じく
id1
を指定しています
- Source
- ソースのリージョン、または、AZ (Availability Zone) を指定します
- リージョンの指定例
- ap-northeast-1
- ap-northeast-3
- AZ の指定例
- apne1-az1
- apne1-az2
- apne1-az4
- Destination
- 送信先のリージョン、または、AZ (Availability Zone) を指定します
- 指定例は Source と同様です
- Metric
- 集計するメトリックを指定します
- 現在は
aggregation-latency
のみのサポートです
- Statistic
- 統計方法を指定します
- 現在は中央値である
P50
(50 パーセンタイル) のみのサポートです
- Period
- レイテンシーを出力する間隔を指定します
- 現在は次の値をサポートしています
- five-minutes
- fifteen-minutes
- one-hour
- three-hours
- one-day
- one-week
指定した 60 分のレイテンシー情報を出力する例をいくつか紹介します。
東京リージョン〜大阪リージョンの 5 分間隔のレイテンシーを出力するコマンド例です。
aws ec2 get-aws-network-performance-data \
--start-time 2022-12-05T00:00:000Z \
--end-time 2022-12-05T01:00:000Z \
--data-queries Id=id1,Source=ap-northeast-1,Destination=ap-northeast-3,Metric=aggregate-latency,Statistic=p50,Period=five-minutes \
--output table
出力結果です。
$ START_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ" -d "1 hour ago"`; END_TIME=`date "+%Y-%m-%dT%H:%M:%3SZ"`; aws ec2 get-aws-network-performance-data --start-time $START_TIME --end-time $END_TIME --data-queries Id=id1,Source=ap-northeast-1,Destination=ap-northeast-3,Metric=aggregate-latency,Statistic=p50,Period=five-minutes --output table
-------------------------------------------------------------------------------------------------
| GetAwsNetworkPerformanceData |
+-----------------------------------------------------------------------------------------------+
|| DataResponses ||
|+----------------+------+--------------------+---------------+------------------+-------------+|
|| Destination | Id | Metric | Period | Source | Statistic ||
|+----------------+------+--------------------+---------------+------------------+-------------+|
|| ap-northeast-3| id1 | aggregate-latency | five-minutes | ap-northeast-1 | p50 ||
|+----------------+------+--------------------+---------------+------------------+-------------+|
||| MetricPoints |||
||+-------------------------------+---------------------------------+-----------+-------------+||
||| EndDate | StartDate | Status | Value |||
||+-------------------------------+---------------------------------+-----------+-------------+||
||| 2022-12-05T05:55:00+00:00 | 2022-12-05T05:50:00+00:00 | OK | 8.171495 |||
||| 2022-12-05T06:00:00+00:00 | 2022-12-05T05:55:00+00:00 | OK | 8.176996 |||
||| 2022-12-05T06:05:00+00:00 | 2022-12-05T06:00:00+00:00 | OK | 8.182976 |||
||| 2022-12-05T06:10:00+00:00 | 2022-12-05T06:05:00+00:00 | OK | 8.175997 |||
||| 2022-12-05T06:15:00+00:00 | 2022-12-05T06:10:00+00:00 | OK | 8.179472 |||
||| 2022-12-05T06:20:00+00:00 | 2022-12-05T06:15:00+00:00 | OK | 8.166493 |||
||| 2022-12-05T06:25:00+00:00 | 2022-12-05T06:20:00+00:00 | OK | 8.156486 |||
||| 2022-12-05T06:30:00+00:00 | 2022-12-05T06:25:00+00:00 | OK | 8.146965 |||
||| 2022-12-05T06:35:00+00:00 | 2022-12-05T06:30:00+00:00 | OK | 8.16099 |||
||| 2022-12-05T06:40:00+00:00 | 2022-12-05T06:35:00+00:00 | OK | 8.158933 |||
||| 2022-12-05T06:45:00+00:00 | 2022-12-05T06:40:00+00:00 | OK | 8.18299 |||
||+-------------------------------+---------------------------------+-----------+-------------+||
東京リージョンの AZapne1-az4
〜apne1-az1
の 15 分間隔のレイテンシーを出力するコマンド例です。
aws ec2 get-aws-network-performance-data \
--start-time 2022-12-05T00:00:000Z \
--end-time 2022-12-05T01:00:000Z \
--data-queries Id=id1,Source=apne1-az4,Destination=apne1-az1,Metric=aggregate-latency,Statistic=p50,Period=fifteen-minutes \
--output table
実行結果です。
$ aws ec2 get-aws-network-performance-data --start-time 2022-12-05T00:00:000Z --end-time 2022-12-05T01:00:000Z --data-queries Id=id1,Source=apne1-az4,Destination=apne1-az1,Metric=aggregate-latency,Statistic=p50,Period=fifteen-minutes --output table
--------------------------------------------------------------------------------------------
| GetAwsNetworkPerformanceData |
+------------------------------------------------------------------------------------------+
|| DataResponses ||
|+-------------+------+--------------------+------------------+-------------+-------------+|
|| Destination | Id | Metric | Period | Source | Statistic ||
|+-------------+------+--------------------+------------------+-------------+-------------+|
|| apne1-az1 | id1 | aggregate-latency | fifteen-minutes | apne1-az4 | p50 ||
|+-------------+------+--------------------+------------------+-------------+-------------+|
||| MetricPoints |||
||+-----------------------------+-------------------------------+----------+-------------+||
||| EndDate | StartDate | Status | Value |||
||+-----------------------------+-------------------------------+----------+-------------+||
||| 2022-12-05T00:15:00+00:00 | 2022-12-05T00:00:00+00:00 | OK | 1.8444885 |||
||| 2022-12-05T00:30:00+00:00 | 2022-12-05T00:15:00+00:00 | OK | 1.8419975 |||
||| 2022-12-05T00:45:00+00:00 | 2022-12-05T00:30:00+00:00 | OK | 1.8419975 |||
||| 2022-12-05T01:00:00+00:00 | 2022-12-05T00:45:00+00:00 | OK | 1.8414946 |||
||| 2022-12-05T01:15:00+00:00 | 2022-12-05T01:00:00+00:00 | OK | 1.8449903 |||
||+-----------------------------+-------------------------------+----------+-------------+||
東京リージョンの AZapne1-az4
内の 60 分間隔のレイテンシーを出力するコマンドです。同一 AZ 内のレイテンシーを出力する場合はSource
とDestination
の両方でapne1-az4
を指定します。
aws ec2 get-aws-network-performance-data \
--start-time 2022-12-05T00:00:000Z \
--end-time 2022-12-05T01:00:000Z \
--data-queries Id=id1,Source=apne1-az4,Destination=apne1-az4,Metric=aggregate-latency,Statistic=p50,Period=one-hour \
--output table
実行結果です。AZ 内のレイテンシーの場合はStatus
は出力されないようです。
$ aws ec2 get-aws-network-performance-data --start-time 2022-12-05T00:00:000Z --end-time 2022-12-05T01:00:000Z --data-queries Id=id1,Source=apne1-az4,Destination=apne1-az4,Metric=aggregate-latency,Statistic=p50,Period=one-hour --output table
-------------------------------------------------------------------------------------
| GetAwsNetworkPerformanceData |
+-----------------------------------------------------------------------------------+
|| DataResponses ||
|+-------------+------+---------------------+-----------+------------+-------------+|
|| Destination | Id | Metric | Period | Source | Statistic ||
|+-------------+------+---------------------+-----------+------------+-------------+|
|| apne1-az4 | id1 | aggregate-latency | one-hour | apne1-az4 | p50 ||
|+-------------+------+---------------------+-----------+------------+-------------+|
||| MetricPoints |||
||+------------------------------+--------------------------------+---------------+||
||| EndDate | StartDate | Value |||
||+------------------------------+--------------------------------+---------------+||
||| 2022-12-05T01:00:00+00:00 | 2022-12-05T00:00:00+00:00 | 0.27244174 |||
||| 2022-12-05T02:00:00+00:00 | 2022-12-05T01:00:00+00:00 | 0.27248 |||
||+------------------------------+--------------------------------+---------------+||
これまでの記載内容をまとめたものが冒頭で記載したコマンド例になります。
AWS Cloud Shell 環境の AWS CLI v2 バージョンアップ
AWS CloudShell で利用する AWS CLI v2 のバージョンを上げる一例を紹介します。
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install --update
You can now run: /usr/local/bin/aws --version
$ aws --version
aws-cli/2.9.4 Python/3.9.11 Linux/4.14.294-220.533.amzn2.x86_64 exec-env/CloudShell exe/x86_64.amzn.2 prompt/off
さいごに
なにか問題が起きたときに、レイテンシーに問題がなかったかすぐに確認したいと思い、習熟も兼ねて AWS CLI によるレイテンシー情報の取得を試してみました。レイテンシーをすぐに確認できるのは助かりますね。
以上、このブログがどなたかのご参考になれば幸いです。