|
| 1 | +--- |
| 2 | +title: Get Load Balancer metrics with Azure Monitor CLI |
| 3 | +titleSuffix: Azure Load Balancer |
| 4 | +description: In this article, get started using the Azure Monitor CLI to collect health and usage metrics for Azure Load Balancer. |
| 5 | +services: load-balancer |
| 6 | +author: mbender-ms |
| 7 | +ms.author: mbender |
| 8 | +ms.service: load-balancer |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 06/09/2022 |
| 11 | +ms.custom: template-how-to |
| 12 | +--- |
| 13 | + |
| 14 | +<!-- |
| 15 | +Remove all the comments in this template before you sign-off or merge to the |
| 16 | +main branch. |
| 17 | +--> |
| 18 | + |
| 19 | +# Get Load Balancer metrics with Azure Monitor CLI |
| 20 | + |
| 21 | +In this article, you'll learn some examples to list Load Balancer metrics using Azure Monitor CLI. |
| 22 | + |
| 23 | +Complete reference documentation and other samples for retrieving metrics using Azure Monitor CLI are available in the [az monitor metrics reference](/cli/azure/monitor/metrics). |
| 24 | + |
| 25 | +## Table of metric names via CLI |
| 26 | + |
| 27 | +When you use CLI, Load Balancer metrics may use a different metric name for the CLI parameter value. When specifying the metric name via the `--metric dimension` parameter, use the CLI metric name instead. For example, the metric Data path availability would be used by specifying a parameter of `--metric VipAvaialbility`. |
| 28 | + |
| 29 | +Here's a table of common Load Balancer metrics, the CLI metric name, and recommend aggregation values for queries: |
| 30 | + |
| 31 | +|Metric|CLI metric name|Recommended aggregation| |
| 32 | +|-----------------|-----------------|-----------------| |
| 33 | +|Data path availability |VipAvailability |Average | |
| 34 | +|Health probe status |DipAvailability |Average | |
| 35 | +|SYN (synchronize) count |SYNCount |Average | |
| 36 | +|SNAT connection count |SnatConnectionCount |Sum | |
| 37 | +|Allocated SNAT ports |AllocatedSnatPorts |Average| |
| 38 | +|Used SNAT ports |UsedSnatPorts |Average | |
| 39 | +|Byte count |ByteCount |Sum | |
| 40 | +|Packet count |PacketCount |Sum | |
| 41 | + |
| 42 | +For metric definitions and further details, refer to [Monitoring load balancer data reference](./monitor-load-balancer-reference.md). |
| 43 | + |
| 44 | +## CLI examples for Load Balancer metrics |
| 45 | +<!-- Introduction paragraph --> |
| 46 | + |
| 47 | +The [az monitor metrics](/cli/azure/monitor/metrics/) command is used to view Azure resource metrics. To see the metric definitions available for a Standard Load Balancer, you run the `az monitor metrics list-definitions` command. |
| 48 | + |
| 49 | +```azurecli |
| 50 | +# Display available metric definitions for a Standard Load Balancer resource |
| 51 | +
|
| 52 | +az monitor metrics list-definitions --resource <resource_id> |
| 53 | +``` |
| 54 | +>[!NOTE] |
| 55 | +>In the all the following examples, replace **<resource_id>** with the unique resource id of your Standard Load Balancer. |
| 56 | +
|
| 57 | +To retrieve Standard Load Balancer metrics for a resource, you can use the `az monitor metrics list` command. For example, use the `--metric DipAvailability` option to collect the Health Probe Status metric from a Standard Load Balancer. |
| 58 | + |
| 59 | +```azurecli |
| 60 | +
|
| 61 | +# List the Health Probe Status metric from a Standard Load Balancer |
| 62 | +
|
| 63 | +az monitor metrics list --resource <resource_id> --metric DipAvailability |
| 64 | +``` |
| 65 | + |
| 66 | +When you run the above command, the output for Health Probe status will be like the following output: |
| 67 | +```output |
| 68 | +user@Azure:~$ az monitor metrics list --resource <resource_id> --metric DipAvailability |
| 69 | +{ |
| 70 | + "cost": 59, |
| 71 | + "interval": "0:01:00", |
| 72 | + "namespace": "Microsoft.Network/loadBalancers", |
| 73 | + "resourceregion": "eastus2", |
| 74 | + "timespan": "2022-06-30T15:22:39Z/2022-06-30T16:22:39Z", |
| 75 | + "value": [ |
| 76 | + { |
| 77 | + "displayDescription": "Average Load Balancer health probe status per time duration", |
| 78 | + "errorCode": "Success", |
| 79 | + "errorMessage": null, |
| 80 | + "id": "/subscriptions/6a5f35e9-6951-499d-a36b-83c6c6eed44a/resourceGroups/myResourceGroup2/providers/Microsoft.Network/loadBalancers/myLoadBalancer/providers/Microsoft.Insights/metrics/DipAvailability", |
| 81 | + "name": { |
| 82 | + "localizedValue": "Health Probe Status", |
| 83 | + "value": "DipAvailability" |
| 84 | + }, |
| 85 | + "resourceGroup": "myResourceGroup2", |
| 86 | + "timeseries": [], |
| 87 | + "type": "Microsoft.Insights/metrics", |
| 88 | + "unit": "Count" |
| 89 | + } |
| 90 | + ] |
| 91 | +} |
| 92 | +... |
| 93 | +``` |
| 94 | +You can specify the aggregation type for a metric with the `–-aggregation` parameter. For recommended aggregations, see Monitoring load balancer data reference](./monitor-load-balancer-reference.md). |
| 95 | + |
| 96 | +```azurecli |
| 97 | +
|
| 98 | +# List the average Health Probe Status metric from a Standard Load Balancer |
| 99 | +
|
| 100 | +az monitor metrics list --resource <resource_id> --metric DipAvailability --aggregation Average |
| 101 | +``` |
| 102 | +To specify the interval to metrics, use the `--interval` parameter and specify a value in ##h##m format. The default interval is 1m. |
| 103 | + |
| 104 | +```azurecli |
| 105 | +
|
| 106 | +# List the average List the average Health Probe Status metric from a Standard Load Balancer in 5 minute intervals |
| 107 | +
|
| 108 | +az monitor metrics list --resource <resource_id> --metric DipAvailability --aggregation Average --interval 5m |
| 109 | +``` |
| 110 | +By default, az monitor metrics list returns the resource’s aggregate metrics from the last hour. You can query metric data over a period of time using `--start-time` and `--end-time` with the format of date (yyyy-mm-dd) time (hh:mm:ss.xxxxx) timezone (+/-hh:mm). To list the average Health Probe Status aggregated per day from May 5, 2022 and May 10, 2022, use the following command: |
| 111 | + |
| 112 | +```azurecli |
| 113 | +# List average Health Probe Status metric aggregated per day from May 5, 2022 and May 10, 2022. |
| 114 | +
|
| 115 | +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 |
| 116 | +``` |
| 117 | +>[!Note] |
| 118 | +>Start and end times are represented using a format of yyyy-mm-dd format. For example, every day between May 5, 2022 and May 10, 2022 would be represented as `2022-05-01` and `2022-05-10`. |
| 119 | +
|
| 120 | + |
| 121 | +To split metrics on a dimension, such as “BackendIPAddress”, specify the dimension in the `--filter` flag. Dimensions of a metric are name/value pairs that include more data to describe the metric value. To learn more about which dimensions are supported for each metric, see [Monitoring load balancer data reference](./monitor-load-balancer-reference.md). |
| 122 | + |
| 123 | +```azurecli |
| 124 | +# List average Health Probe Status metric and filter for all BackendIPAddress dimensions |
| 125 | +
|
| 126 | +az monitor metrics list --resource $res --metric DipAvailability --filter "BackendIPAddress eq '*'" --aggregation Average |
| 127 | +``` |
| 128 | + |
| 129 | +You can also specify a specific dimension value. |
| 130 | + |
| 131 | +```azurecli |
| 132 | +# List average Health Probe Status metric and filter for the 10.1.0.4 BackendIPAddress dimension |
| 133 | +
|
| 134 | +az monitor metrics list --resource <resource_id> --metric DipAvailability --filter "BackendIPAddress eq '10.1.0.4'" --aggregation Average |
| 135 | +``` |
| 136 | + |
| 137 | +In cases where you need to filter on multiple dimension values, specify the `--filter` value using `and` between the values. |
| 138 | + |
| 139 | +```azurecli |
| 140 | +# List average Health Probe Status metric and filter for all BackendIPAddress and BackendPort dimensions |
| 141 | +
|
| 142 | +az monitor metrics list --resource <resource_id> --metric DipAvailability --filter "BackendIPAddress eq '*' and BackendPort eq '*'" --aggregation Average |
| 143 | +``` |
| 144 | + |
| 145 | +## Next steps |
| 146 | +* [Review the metric definitions to better understand how each is generated](./load-balancer-standard-diagnostics.md#multi-dimensional-metrics) |
| 147 | +* [Create Connection Monitors for your Load Balancer](./load-balancer-standard-diagnostics.md) |
| 148 | +* [Create your own workbooks](../azure-monitor/visualize/workbooks-overview.md), you can take inspiration by clicking on the edit button in your detailed metrics dashboard |
0 commit comments