

# 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 Insights を使用して調べることができる CloudWatch Logs の可用性と往復時間の詳細な測定値を発行します。

Internet Monitor のクライアントのロケーションの精度の詳細については、「[Internet Monitor の位置情報と精度](CloudWatch-IM-inside-internet-monitor.md#IMGeolocationSourceAccuracy)」を参照してください。

このセクションの例は、CloudWatch Logs Insights クエリを作成して、独自のアプリケーショントラフィックの測定値やメトリクスについて詳細を知るのに役立ちます。CloudWatch Logs Insights でこれらの例を使用する場合は、*monitorName* を独自のモニタ名に置き換えます。

**トラフィック最適化の提案を表示する**

Internet Monitor の **[トラフィックインサイト]** タブでは、ロケーション別にフィルタリングされたトラフィック最適化の提案を表示できます。そのタブ内に存在する **[トラフィック最適化の提案]** セクションに表示されている情報と同じ情報を、ロケーションの詳細度フィルターなしで表示するには、次の 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)」を参照してください。