本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
將 CLI 與網際網路監視器搭配使用的範例
本節包含搭配 AWS Command Line Interface 網際網路監視器操作使用 的範例。
開始之前,請確定您登入以 AWS CLI 使用具有您要監控之 Amazon Virtual Private Clouds (VPCs)、Network Load Balancer、Amazon CloudFront 分佈或 Amazon WorkSpaces 目錄的相同 AWS 帳戶。網路監視器不支援跨帳戶存取資源。如需使用 的詳細資訊 AWS CLI,請參閱 AWS CLI 命令參考。如需搭配網際網路監視器使用 API 動作的詳細資訊,請參閱網際網路監視器 API 參考指南。
建立監視器
在網路監視器中建立監視器時,您需要提供名稱並將資源與監視器建立關聯,以顯示應用程式網際網路流量的所在位置。您可以指定一個流量百分比來定義受監控的應用程式流量。這也會決定受監控的城市網路數量,城市網路即用戶端位置和 ASN [通常為網際網路服務供應商 (ISP)]。若要協助控制帳單,您也可以選擇針對應用程式資源,設定要監控的城市網路上限數量。如需詳細資訊,請參閱選擇城市網路上限。
最後,您可以選擇是否要將應用程式的所有網際網路測量結果發佈到 Amazon S3。前 500 個城市網路 (依流量計算) 的網際網路測量結果會透過網路監視器自動發佈至 CloudWatch Logs,但您也可以選擇將所有測量結果發佈到 S3。
若要使用 建立監視器 AWS CLI,請使用 create-monitor
命令。下列命令會建立一個監控 100% 流量但將城市網路上限設定為 10,000 個的監視器、新增 VPC 資源,以及選擇將網際網路測量結果發佈到 Amazon S3。
注意
網路監視器每五分鐘會針對將流量傳送至各監視器的前 500 個城市網路 (用戶端位置和 ASN [通常為網際網路服務供應商 (ISP)]),將網際網路度量發佈至 CloudWatch Logs。您也可以選擇將所有受監控之城市網路 (最多 500,000 個城市網路服務限制) 的網際網路度量發佈至 Amazon S3 儲存貯體。如需詳細資訊,請參閱在網際網路監視器中將網際網路測量結果發佈至 Amazon S3 。
aws internetmonitor --create-monitor monitor-name "TestMonitor" \ --traffic-percentage-to-monitor 100 \ --max-city-networks-to-monitor 10000 \ --resources "arn:aws:ec2:us-east-1:111122223333:vpc/vpc-11223344556677889" \ --internet-measurements-log-delivery S3Config="{BucketName=amzn-s3-demo-bucket,LogDeliveryStatus=ENABLED}"
{ "Arn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor", "Status": "ACTIVE" }
注意
您無法變更監視器的名稱。
檢視螢幕詳細資料
若要使用 檢視監視器的相關資訊 AWS CLI,請使用 get-monitor
命令。
aws internetmonitor get-monitor --monitor-name "TestMonitor"
{ "ClientLocationType": "city", "CreatedAt": "2022-09-22T19:27:47Z", "ModifiedAt": "2022-09-22T19:28:30Z", "MonitorArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor", "MonitorName": "TestMonitor", "ProcessingStatus": "OK", "ProcessingStatusInfo": "The monitor is actively processing data", "Resources": [ "arn:aws:ec2:us-east-1:111122223333:vpc/vpc-11223344556677889" ], "MaxCityNetworksToMonitor": 10000, "Status": "ACTIVE" }
列出運作狀態事件
如果應用程式的網際網路流量效能降低,網路監視器會在監視器中建立運作狀態事件。若要使用 查看目前運作狀態事件的清單 AWS CLI,請使用 list-health-events
命令
aws internetmonitor list-health-events --monitor-name "TestMonitor"
{ "HealthEvents": [ { "EventId": "2022-06-20T01-05-05Z/latency", "Status": "RESOLVED", "EndedAt": "2022-06-20T01:15:14Z", "ServiceLocations": [ { "Name": "us-east-1" } ], "PercentOfTotalTrafficImpacted": 1.21, "ClientLocations": [ { "City": "Lockport", "PercentOfClientLocationImpacted": 60.370000000000005, "PercentOfTotalTraffic": 2.01, "Country": "United States", "Longitude": -78.6913, "AutonomousSystemNumber": 26101, "Latitude": 43.1721, "Subdivision": "New York", "NetworkName": "YAHOO-BF1" } ], "StartedAt": "2022-06-20T01:05:05Z", "ImpactType": "PERFORMANCE", "EventArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor/health-event/2022-06-20T01-05-05Z/latency" }, { "EventId": "2022-06-20T01-17-56Z/latency", "Status": "RESOLVED", "EndedAt": "2022-06-20T01:30:23Z", "ServiceLocations": [ { "Name": "us-east-1" } ], "PercentOfTotalTrafficImpacted": 1.29, "ClientLocations": [ { "City": "Toronto", "PercentOfClientLocationImpacted": 75.32, "PercentOfTotalTraffic": 1.05, "Country": "Canada", "Longitude": -79.3623, "AutonomousSystemNumber": 14061, "Latitude": 43.6547, "Subdivision": "Ontario", "CausedBy": { "Status": "ACTIVE", "Networks": [ { "AutonomousSystemNumber": 16509, "NetworkName": "Amazon.com" } ], "NetworkEventType": "AWS" }, "NetworkName": "DIGITALOCEAN-ASN" }, { "City": "Lockport", "PercentOfClientLocationImpacted": 22.91, "PercentOfTotalTraffic": 2.01, "Country": "United States", "Longitude": -78.6913, "AutonomousSystemNumber": 26101, "Latitude": 43.1721, "Subdivision": "New York", "NetworkName": "YAHOO-BF1" }, { "City": "Hangzhou", "PercentOfClientLocationImpacted": 2.88, "PercentOfTotalTraffic": 0.7799999999999999, "Country": "China", "Longitude": 120.1612, "AutonomousSystemNumber": 37963, "Latitude": 30.2994, "Subdivision": "Zhejiang", "NetworkName": "Hangzhou Alibaba Advertising Co.,Ltd." } ], "StartedAt": "2022-06-20T01:17:56Z", "ImpactType": "PERFORMANCE", "EventArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor/health-event/2022-06-20T01-17-56Z/latency" }, { "EventId": "2022-06-20T01-34-20Z/latency", "Status": "RESOLVED", "EndedAt": "2022-06-20T01:35:04Z", "ServiceLocations": [ { "Name": "us-east-1" } ], "PercentOfTotalTrafficImpacted": 1.15, "ClientLocations": [ { "City": "Lockport", "PercentOfClientLocationImpacted": 39.45, "PercentOfTotalTraffic": 2.01, "Country": "United States", "Longitude": -78.6913, "AutonomousSystemNumber": 26101, "Latitude": 43.1721, "Subdivision": "New York", "NetworkName": "YAHOO-BF1" }, { "City": "Toronto", "PercentOfClientLocationImpacted": 29.770000000000003, "PercentOfTotalTraffic": 1.05, "Country": "Canada", "Longitude": -79.3623, "AutonomousSystemNumber": 14061, "Latitude": 43.6547, "Subdivision": "Ontario", "CausedBy": { "Status": "ACTIVE", "Networks": [ { "AutonomousSystemNumber": 16509, "NetworkName": "Amazon.com" } ], "NetworkEventType": "AWS" }, "NetworkName": "DIGITALOCEAN-ASN" }, { "City": "Hangzhou", "PercentOfClientLocationImpacted": 2.88, "PercentOfTotalTraffic": 0.7799999999999999, "Country": "China", "Longitude": 120.1612, "AutonomousSystemNumber": 37963, "Latitude": 30.2994, "Subdivision": "Zhejiang", "NetworkName": "Hangzhou Alibaba Advertising Co.,Ltd." } ], "StartedAt": "2022-06-20T01:34:20Z", "ImpactType": "PERFORMANCE", "EventArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor/health-event/2022-06-20T01-34-20Z/latency" } ] }
檢視特定運作狀態事件
若要使用 CLI 查看有關特定運作狀態事件的更詳細資訊,請使用您的監視器名稱和運作狀態事件 ID 執行 get-health-event
命令。
aws internetmonitor get-monitor --monitor-name "TestMonitor" --event-id "health-event/TestMonitor/2021-06-03T01:02:03Z/latency"
{ "EventId": "2022-06-20T01-34-20Z/latency", "Status": "RESOLVED", "EndedAt": "2022-06-20T01:35:04Z", "ServiceLocations": [ { "Name": "us-east-1" } ], "EventArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor/health-event/2022-06-20T01-34-20Z/latency", "LastUpdatedAt": "2022-06-20T01:35:04Z", "ClientLocations": [ { "City": "Lockport", "PercentOfClientLocationImpacted": 39.45, "PercentOfTotalTraffic": 2.01, "Country": "United States", "Longitude": -78.6913, "AutonomousSystemNumber": 26101, "Latitude": 43.1721, "Subdivision": "New York", "NetworkName": "YAHOO-BF1" }, { "City": "Toronto", "PercentOfClientLocationImpacted": 29.770000000000003, "PercentOfTotalTraffic": 1.05, "Country": "Canada", "Longitude": -79.3623, "AutonomousSystemNumber": 14061, "Latitude": 43.6547, "Subdivision": "Ontario", "CausedBy": { "Status": "ACTIVE", "Networks": [ { "AutonomousSystemNumber": 16509, "NetworkName": "Amazon.com" } ], "NetworkEventType": "AWS" }, "NetworkName": "DIGITALOCEAN-ASN" }, { "City": "Shenzhen", "PercentOfClientLocationImpacted": 4.07, "PercentOfTotalTraffic": 0.61, "Country": "China", "Longitude": 114.0683, "AutonomousSystemNumber": 37963, "Latitude": 22.5455, "Subdivision": "Guangdong", "NetworkName": "Hangzhou Alibaba Advertising Co.,Ltd." }, { "City": "Hangzhou", "PercentOfClientLocationImpacted": 2.88, "PercentOfTotalTraffic": 0.7799999999999999, "Country": "China", "Longitude": 120.1612, "AutonomousSystemNumber": 37963, "Latitude": 30.2994, "Subdivision": "Zhejiang", "NetworkName": "Hangzhou Alibaba Advertising Co.,Ltd." } ], "StartedAt": "2022-06-20T01:34:20Z", "ImpactType": "PERFORMANCE", "PercentOfTotalTrafficImpacted": 1.15 }
檢視監視器清單
若要使用 CLI 查看您帳戶中所有監視器的清單,請執行 list-monitors
命令。
aws internetmonitor list-monitors
{ "Monitors": [ { "MonitorName": "TestMonitor", "ProcessingStatus": "OK", "Status": "ACTIVE" } ], "NextToken": " zase12" }
編輯監視器
若要使用 CLI 更新監視器的相關資訊,請使用 update-monitor
命令並指定要更新的監視器名稱。例如,您可以更新要監控的流量百分比、要監控的城市網路數量上限、新增或移除網路監視器用來監控流量的資源,以及將監控狀態從 變更為 ACTIVE
INACTIVE
,反之亦然。請注意,您無法變更監視器的名稱。
update-monitor
呼叫的回應僅會傳回 MonitorArn
和 Status
。
下列範例會說明如何使用 update-monitor
命令將要監控的城市網路上限數量變更為 50000
:
aws internetmonitor update-monitor --monitor-name "TestMonitor" --max-city-networks-to-monitor 50000
{ "MonitorArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor", "Status": " ACTIVE " }
以下範例會說明如何新增和移除資源:
aws internetmonitor update-monitor --monitor-name "TestMonitor" \ --resources-to-add "arn:aws:ec2:us-east-1:111122223333:vpc/vpc-11223344556677889" \ --resources-to-remove "arn:aws:ec2:us-east-1:111122223333:vpc/vpc-2222444455556666"
{ "MonitorArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor", "Status": "ACTIVE" }
以下範例會說明如何使用 update-monitor
命令將監視器狀態變更為 INACTIVE
:
aws internetmonitor update-monitor --monitor-name "TestMonitor" --status "INACTIVE"
{ "MonitorArn": "arn:aws:internetmonitor:us-east-1:111122223333:monitor/TestMonitor", "Status": "INACTIVE" }
刪除監視器
您可以使用 delete-monitor
命令,利用 CLI 刪除監視器。首先,您必須將監視器設定為非作用中。若要執行此操作,請使用 update-monitor
命令將狀態變更為 INACTIVE
。使用 get-monitor
命令並檢查狀態,確認監視器為非作用中。
監視器狀態為 INACTIVE
後,您便可以使用 CLI 執行 delete-monitor
命令來刪除監視器。成功的 delete-monitor
呼叫回應是空白的。
aws internetmonitor delete-monitor --monitor-name "TestMonitor"
{}