

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 CloudWatch Logs Insights 探索 Internet Monitor 度量結果
<a name="CloudWatch-IM-view-cw-tools-logs-insights"></a>

您可以使用 CloudWatch Logs Insights 查詢來篩選特定城市或地理位置 （用戶端位置）、用戶端 ASN (ISP) 和 AWS 來源位置的日誌子集。Internet Monitor 會發布針對 CloudWatch Logs 的詳細可用性與往返時間度量資料，您可透過 CloudWatch Logs Insights 進行深入分析。

若要進一步了解網路監視器中的用戶端位置準確度，請參閱[網路監視器中的地理位置資訊和準確度](CloudWatch-IM-inside-internet-monitor.md#IMGeolocationSourceAccuracy)。

本節中的範例可協助您建立 CloudWatch Logs Insights 查詢，以深入了解自己的應用程式流量度量和指標。如果您在 CloudWatch Logs Insights 中使用這些範例，請以自己的監視器名稱取代 *MonitorName*。

**檢視流量最佳化建議**

在網路監視器中的**流量洞察**索引標籤中，您可以檢視依位置篩選的流量最佳化建議。若要查看該索引標籤上**流量最佳化建議**區段中顯示的相同資訊，但其未提供位置精細程度篩選器，則可以使用下列 CloudWatch Logs Insights 查詢。

1. 在 中 AWS 管理主控台，導覽至 CloudWatch Logs Insights。

1. 在 **Log Group** (日誌群組) 中，選取 `/aws/internet-monitor/monitorName/byCity` 和 `/aws/internet-monitor/monitorName/byCountry`，然後指定時間範圍。

1. 新增以下查詢，然後執行該查詢。

```
fields @timestamp, 
clientLocation.city as @city, clientLocation.subdivision as @subdivision, clientLocation.country as @country,
`trafficInsights.timeToFirstByte.currentExperience.serviceName` as @serviceNameField,
concat(@serviceNameField, ` (`, `serviceLocation`, `)`) as @currentExperienceField,
concat(`trafficInsights.timeToFirstByte.ec2.serviceName`, ` (`, `trafficInsights.timeToFirstByte.ec2.serviceLocation`, `)`) as @ec2Field,
`trafficInsights.timeToFirstByte.cloudfront.serviceName` as @cloudfrontField,
concat(`clientLocation.networkName`, ` (AS`, `clientLocation.asn`, `)`) as @networkName
| filter ispresent(`trafficInsights.timeToFirstByte.currentExperience.value`)
| stats avg(`trafficInsights.timeToFirstByte.currentExperience.value`) as @averageTTFB,
avg(`trafficInsights.timeToFirstByte.ec2.value`) as @ec2TTFB,
avg(`trafficInsights.timeToFirstByte.cloudfront.value`) as @cloudfrontTTFB,
sum(`bytesIn` + `bytesOut`) as @totalBytes,
latest(@ec2Field) as @ec2,
latest(@currentExperienceField) as @currentExperience,
latest(@cloudfrontField) as @cloudfront,
count(*) by @networkName, @city, @subdivision, @country
| display @city, @subdivision, @country, @networkName, @totalBytes, @currentExperience, @averageTTFB, @ec2, @ec2TTFB, @cloudfront, @cloudfrontTTFB
| sort @totalBytes desc
```

**檢視網際網路可用性和 RTT (p50、p90 及 p95)**

若要檢視流量的網際網路可用性和往返時間 (p50、p90 及 p95)，可以使用下列 CloudWatch Logs Insights 查詢。

**最終使用者地理位置：**美國伊利諾州芝加哥

**最終使用者網路 (ASN)：**AS7018 

**AWS 服務位置：**美國東部 （維吉尼亞北部） 區域

若要檢視日誌，請依下列步驟執行：

1. 在 中 AWS 管理主控台，導覽至 CloudWatch Logs Insights。

1. 在 **Log Group** (日誌群組) 中，選取 `/aws/internet-monitor/monitorName/byCity` 和 `/aws/internet-monitor/monitorName/byCountry`，然後指定時間範圍。

1. 新增以下查詢，然後執行該查詢。

該查詢會傳回在所選時段內，從伊利諾州芝加哥 AS7018 連線至美國東部 (維吉尼亞北部) 區域的所有使用者效能資料。

```
fields @timestamp, 
internetHealth.availability.experienceScore as availabilityExperienceScore, 
internetHealth.availability.percentageOfTotalTrafficImpacted as percentageOfTotalTrafficImpacted,
internetHealth.performance.experienceScore as performanceExperienceScore,
internetHealth.performance.roundTripTime.p50 as roundTripTimep50, 
internetHealth.performance.roundTripTime.p90 as roundTripTimep90, 
internetHealth.performance.roundTripTime.p95 as roundTripTimep95
 | filter clientLocation.country == `United States` 
 and clientLocation.city == `Chicago` 
 and serviceLocation == `us-east-1` 
 and clientLocation.asn == 7018
```

如需詳細資訊，請參閱[使用 CloudWatch Logs Insights 分析日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)。