查看从特定位置到 Azure 区域的相对延迟View relative latency to Azure regions from specific locations

警告

此功能目前处于预览状态,并且仍在测试稳定性。This feature is currently in preview and still being tested for stability.

本教程介绍如何使用 Azure 网络观察程序服务,根据用户的人口统计,帮助确定要将应用程序或服务部署到哪个 Azure 区域。In this tutorial, learn how to use the Azure Network Watcher service to help you decide what Azure region to deploy your application or service in, based on your user demographic. 此外,还可以使用此服务来帮助评估服务提供商与 Azure 之间的连接。Additionally, you can use it to help evaluate service providers' connections to Azure.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

创建网络观察程序Create a network watcher

如果已至少在一个 Azure 区域中部署了网络观察程序,则可以跳过本部分所述的任务。If you already have a network watcher in at least one Azure region, you can skip the tasks in this section. 创建网络观察程序的资源组。Create a resource group for the network watcher. 此示例在 China East 2 区域创建了资源组,但你可以在任何 Azure 区域创建资源组。In this example, the resource group is created in the China East 2 region, but you can create the resource group in any Azure region.

New-AzResourceGroup -Name NetworkWatcherRG -Location chinaeast2

创建网络观察程序。Create a network watcher. 必须至少在一个 Azure 区域创建网络观察程序。You must have a network watcher created in at least one Azure region. 在此示例中,网络观察程序在“中国东部 2”Azure 区域中创建。In this example, a network watcher is created in the China East 2 Azure region.

New-AzNetworkWatcher -Name NetworkWatcher_chinaeast2 -ResourceGroupName NetworkWatcherRG -Location chinaeast2

将特定位置到单个 Azure 区域的相对网络延迟进行比较Compare relative network latencies to a single Azure region from a specific location

评估服务提供商,或者排查用户在从特定位置连接到部署服务的 Azure 区域时报告的问题(例如,“该站点运行速度缓慢”)。Evaluate service providers, or troubleshoot a user reporting an issue such as "the site was slow," from a specific location to the azure region where a service is deployed. 例如,以下命令返回 2017 年 12 月 13 到 15 日,中国北京市与 Azure China East 2 区域之间的平均相对 Internet 服务提供商延迟:For example, the following command returns the average relative Internet service provider latencies between the city of Beijing in China and the China East 2 Azure region between December 13-15, 2017:

Get-AzNetworkWatcherReachabilityReport `
  -NetworkWatcherName NetworkWatcher_chinaeast2 `
  -ResourceGroupName NetworkWatcherRG `
  -Location "China East 2" `
  -Country "China" `
  -State "Beijing" `
  -StartTime "2017-12-13" `
  -EndTime "2017-12-15"

备注

在上述命令中指定的区域,不需要与检索网络观察程序时指定的区域相同。The region you specify in the previous command doesn't need to be the same as the region you specified when you retrieved the network watcher. 上述命令只要求指定现有的网络观察程序。The previous command simply requires that you specify an existing network watcher. 网络观察程序可以位于任何区域。The network watcher can be in any region. 如果为 -Country-State 指定了值,这些值必须有效。If you specify values for -Country and -State, they must be valid. 这些值区分大小写。The values are case-sensitive. 数据适用于有限数量的国家/地区、州/省和城市。Data is available for a limited number of countries/regions, states, and cities. 运行查看可用的国家/地区、州/省、城市和提供商中的命令,查看可用于上一条命令的国家/地区、城市和州/省的列表。Run the commands in View available countries/regions, states, cities, and providers to view a list of available countries/regions, cities, and states to use with the previous command.

警告

必须为 -StartTime-EndTime 指定过去 30 天内的日期。You must specify a date within the past 30 days for -StartTime and -EndTime. 指定之前的日期将不会返回任何数据。Specifying a prior date will result in no data being returned.

上述命令的输出如下所示:The output from the previous command follows:

AggregationLevel   : State
ProviderLocation   : {
                       "Country": "China",
                       "State": "Beijing"
                     }
ReachabilityReport : [
                       {
                         "Provider": "Qwest Communications Company, LLC - ASN 209",
                         "AzureLocation": "China East 2",
                         "Latencies": [
                           {
                             "TimeStamp": "2017-12-14T00:00:00Z",
                             "Score": 92
                           },
                           {
                             "TimeStamp": "2017-12-13T00:00:00Z",
                             "Score": 92
                           }
                         ]
                       },
                       {
                         "Provider": "Comcast Cable Communications, LLC - ASN 7922",
                         "AzureLocation": "China East 2",
                         "Latencies": [
                           {
                             "TimeStamp": "2017-12-14T00:00:00Z",
                             "Score": 96
                           },
                           {
                             "TimeStamp": "2017-12-13T00:00:00Z",
                             "Score": 96
                           }
                         ]
                       }
                     ]

在返回的输出中,Score 的值是区域和提供商之间的相对延迟。In the returned output, the value for Score is the relative latency across regions and providers. 分数为 1 表示延迟最差(最高),100 表示延迟最低。A score of 1 is the worst (highest) latency, whereas 100 is the lowest latency. 相对延迟采用当日的平均值。The relative latencies are averaged for the day. 在前面的示例中,很明显可以看到,这两天的延迟相同,并且两家提供商的延迟差别很小,同时,在 1-100 的梯度上,两家提供商的延迟都比较低。In the previous example, while it's clear that the latencies were the same both days and that there is a small difference between the latency of the two providers, it's also clear that the latencies for both providers are low on the 1-100 scale. 尽管这符合预期,但由于中国北京市的实际位置靠近 Azure 中国东部 2 区域,有时结果将不符合预期。While this is expected, since the city of Beijing in China is physically close to the China East 2 Azure region, sometimes results aren't as expected. 指定的日期范围越大,在一段时间后,平均延迟会越高。The larger the date range you specify, the more you can average latency over time.

将特定位置到不同 Azure 区域的相对网络延迟进行比较Compare relative network latencies across Azure regions from a specific location

如果未使用 -Location 指定特定位置与特定 Azure 区域之间的相对延迟,也同样可以确定从特定实际位置到所有 Azure 区域的相对延迟。If, instead of specifying the relative latencies between a specific location and a specific Azure region using -Location, you wanted to determine the relative latencies to all Azure regions from a specific physical location, you can do that too. 例如,如果主要用户是位于北京市的 Comcast 用户,以下命令可以帮助评估要将服务部署在哪个 Azure 区域:For example, the following command helps you evaluate what azure region to deploy a service in if your primary users are Comcast users located in Beijing city:

Get-AzNetworkWatcherReachabilityReport `
  -NetworkWatcherName NetworkWatcher_chinaeast2 `
  -ResourceGroupName NetworkWatcherRG `
  -Provider "Comcast Cable Communications, LLC - ASN 7922" `
  -Country "China" `
  -State "Beijing" `
  -StartTime "2017-12-13" `
  -EndTime "2017-12-15"

备注

与指定单个位置时不同,如果未指定位置,或指定了多个位置(例如“中国北部 2”、“中国北部”),则运行该命令时,必须指定 Internet 服务提供商。Unlike when you specify a single location, if you don't specify a location, or specify multiple locations, such as "China North 2", "China North", you must specify an Internet service provider when running the command.

查看可用的国家/地区、州/省、城市和提供商View available countries/regions, states, cities, and providers

数据适用于特定的 Internet 服务提供商、国家/地区、州/省和城市。Data is available for specific Internet service providers, countries/regions, states, and cities. 若要查看你可以查看其数据的所有可用 Internet 服务提供商、国家/地区、州/省和城市的列表,请输入以下命令:To view a list of all available Internet service providers, countries/regions, states, and cities, that you can view data for, enter the following command:

Get-AzNetworkWatcherReachabilityProvidersList -NetworkWatcherName NetworkWatcher_chinaeast2 -ResourceGroupName NetworkWatcherRG

数据仅适用于上一条命令返回的国家/地区、州/省和城市。Data is only available for the countries/regions, states, and cities returned by the previous command. 上述命令要求指定现有的网络观察程序。The previous command requires you to specify an existing network watcher. 该示例指定了名为 NetworkWatcherRG 的资源组中的 NetworkWatcher_chinaeast2 网络观察程序,但你可以指定任何现有的网络观察程序 。The example specified the NetworkWatcher_chinaeast2 network watcher in a resource group named NetworkWatcherRG, but you can specify any existing network watcher. 如果没有现有的网络观察程序,可以通过完成创建网络观察程序中的任务来创建一个。If you don't have an existing network watcher, create one by completing the tasks in Create a network watcher.

运行上述命令后,可以根据需要,通过指定 CountryStateCity 的有效值,来筛选返回的输出。After running the previous command, you can filter the output returned by specifying valid values for Country, State, and City, if desired. 例如,若要查看中国北京市海淀区的 Internet 服务提供商列表,请输入以下命令:For example, to view the list of Internet service providers available in Handian, Beijing, in China, enter the following command:

Get-AzNetworkWatcherReachabilityProvidersList `
  -NetworkWatcherName NetworkWatcher_chinaeast2 `
  -ResourceGroupName NetworkWatcherRG `
  -City haidian `
  -Country "China" `
  -State beijing

警告

Country 指定的值必须采用大写和小写。The value specified for Country must be upper and lowercase. StateCity 指定的值必须采用小写。The values specified for State and City must be lowercase. 这些值必须已列在运行上述命令(未在该命令中指定 CountryStateCity 的值)后返回的输出中。The values must be listed in the output returned after running the command with no values for Country, State, and City. 如果指定错误的大小写,或者为 CountryStateCity 指定的值不在运行上述命令(未在该命令中指定这些属性的值)后返回的输出中,则返回的输出为空。If you specify the incorrect case, or specify a value for Country, State, or City that is not in the output returned after running the command with no values for these properties, the returned output is empty.