Share via


使用 Azure 監視器 CLI 取得 Load Balancer 計量

在本文中,您將了解使用 Azure 監視器 CLI 列出 Load Balancer 計量的一些範例。

如需使用 Azure 監視器 CLI 擷取計量的完整參考文件和其他範例,請參閱 az monitor metrics 參考

透過 CLI 的計量名稱資料表

當您使用 CLI 時,Load Balancer 計量可能會針對 CLI 參數值使用不同的計量名稱。 透過 --metric dimension 參數指定計量名稱時,請改用 CLI 計量名稱。 例如,指定 --metric VipAvaialbility 的參數來使用計量資料路徑可用性。

以下表格包含常見的 Load Balancer 計量、CLI 計量名稱,以及建議查詢彙總值:

計量 CLI 計量名稱 建議的彙總
資料路徑可用性 VipAvailability 平均
健康情況探查狀態 DipAvailability 平均
SYN (同步) 計數 SYNCount 平均
SNAT 連線計數 SnatConnectionCount Sum
配置的 SNAT 連接埠 AllocatedSnatPorts 平均
使用的 SNAT 連接埠 UsedSnatPorts 平均
位元組計數 ByteCount Sum
封包計數 PacketCount Sum

如需計量定義和進一步的詳細資料,請參閱監視負載平衡器資料參考

Load Balancer 計量的 CLI 範例

az monitor metrics 命令用於檢視 Azure 資源計量。 若要查看 Standard Load Balancer 可用的計量定義,請執行 az monitor metrics list-definitions 命令。

# Display available metric definitions for a Standard Load Balancer resource

az monitor metrics list-definitions --resource <resource_id>

注意

在下列所有範例中,以 Standard Load Balancer 的唯一資源識別碼取代 <resource_id>

若要擷取資源的 Standard Load Balancer 計量,您可以使用 az monitor metrics list 命令。 例如,使用 --metric DipAvailability 選項從 Standard Load Balancer 收集健康情況探查狀態計量。


# List the Health Probe Status metric from a Standard Load Balancer

az monitor metrics list --resource <resource_id> --metric DipAvailability 

當您執行上述命令時,健康情況探查狀態的輸出會類似下列輸出:

user@Azure:~$ az monitor metrics list --resource <resource_id> --metric DipAvailability
{
  "cost": 59,
  "interval": "0:01:00",
  "namespace": "Microsoft.Network/loadBalancers",
  "resourceregion": "eastus2",
  "timespan": "2022-06-30T15:22:39Z/2022-06-30T16:22:39Z",
  "value": [
    {
      "displayDescription": "Average Load Balancer health probe status per time duration",
      "errorCode": "Success",
      "errorMessage": null,
      "id": "/subscriptions/6a5f35e9-6951-499d-a36b-83c6c6eed44a/resourceGroups/myResourceGroup2/providers/Microsoft.Network/loadBalancers/myLoadBalancer/providers/Microsoft.Insights/metrics/DipAvailability",
      "name": {
        "localizedValue": "Health Probe Status",
        "value": "DipAvailability"
      },
      "resourceGroup": "myResourceGroup2",
      "timeseries": [],
      "type": "Microsoft.Insights/metrics",
      "unit": "Count"
    }
  ]
}
...

您可使用 –-aggregation 參數來指定計量的彙總類型。 如需建議的彙總,請參閱監視負載平衡器資料參考 (./monitor-load-balancer-reference.md)。


# List the average Health Probe Status metric from a Standard Load Balancer

az monitor metrics list --resource <resource_id> --metric DipAvailability --aggregation Average 

若要指定計量的間隔,請使用 --interval 參數並以 ##h##m 格式指定值。 預設間隔是 1 分鐘。


# List the average List the average Health Probe Status metric from a Standard Load Balancer in 5 minute intervals

az monitor metrics list --resource <resource_id> --metric DipAvailability --aggregation Average --interval 5m

根據預設,az monitor metrics list 會傳回過去一小時資源的彙總計量。 您可使用格式為 date (yyyy-mm-dd) time (hh:mm:ss.xxxxx) timezone (+/-hh:mm) 的 --start-time--end-time 來查詢一段時間的計量資料。 若要列出從 2022 年 5 月 5 日到 2022 年 5 月 10 日每天彙總的平均健康情況探查狀態,請使用下列命令:

# List average Health Probe Status metric aggregated per day from May 5, 2022 and May 10, 2022. 

az monitor metrics list --resource <resource_id> --metric DipAvailability --start-time 2022-05-01T00:00:00Z --end-time 2022-05-10T00:00:00Z --interval PT24H --aggregation Average

注意

開始和結束時間均使用 yyyy-mm-dd 格式表示。 例如,在 2022 年 5 月 5 日與 2022 年 5 月 10 日之間的每一天都會以 2022-05-012022-05-10 表示。

若要分割維度上的計量,例如「BackendIPAddress」,請在 --filter 旗標中指定維度。 計量的維度是成對的名稱和值,其中包含更多資料來說明計量值。 若要深入了解每個計量支援哪些維度,請參閱監視負載平衡器資料參考

# List average Health Probe Status metric and filter for all BackendIPAddress dimensions

az monitor metrics list --resource $res --metric DipAvailability --filter "BackendIPAddress eq '*'" --aggregation Average

您也可以指定特定的維度值。

# List average Health Probe Status metric and filter for the 10.1.0.4 BackendIPAddress dimension

az monitor metrics list --resource <resource_id> --metric DipAvailability --filter "BackendIPAddress eq '10.1.0.4'" --aggregation Average 

如果您需要依據多個維度值篩選,請在值之間使用 and 來指定 --filter 值。

# List average Health Probe Status metric and filter for all BackendIPAddress and BackendPort dimensions

az monitor metrics list --resource <resource_id> --metric DipAvailability --filter "BackendIPAddress eq '*' and BackendPort eq '*'" --aggregation Average 

下一步