Azure-cli: [Monitor] Metrics lists accepts multiple comma-separated values rather than space-separated

Created on 22 Sep 2017  路  11Comments  路  Source: Azure/azure-cli

The azure metrics API supports multiple aggregation types e.g. average, total, minimum, maximum, etc (for more info see here). This is passed as an additional argument in the odata query string e.g. (aggregationType eq 'Total').

The az monitor metrics list command does not accept this argument, which means you'll only get the default aggregation. This can block scenarios such as trying to find out the total number of Azure Functions executions you have via the CLI.

Environment info:

azure-cli (2.0.16)
monitor (0.0.9)
Monitor bug

Most helpful comment

@paulbatum and @acabrera-rms could you guys try the latest version of Azure CLI (2.0.25). Changes were made to the metrics in 2.0.24 build.

PR: https://github.com/Azure/azure-cli/commit/9b7005681eb0c5a74feb82f276fa3b81823d3485#diff-ff5a7b93c40504879176ac7665bc2809

All 11 comments

Still not working az: error: unrecognized arguments: --aggregation Total Count
azure-cli (2.0.3)

@paulbatum and @acabrera-rms could you guys try the latest version of Azure CLI (2.0.25). Changes were made to the metrics in 2.0.24 build.

PR: https://github.com/Azure/azure-cli/commit/9b7005681eb0c5a74feb82f276fa3b81823d3485#diff-ff5a7b93c40504879176ac7665bc2809

This is working great for me. Here's a quick example:

az monitor metrics list --resource /subscriptions/<subid>/resourceGroups/<rg>/providers/Microsoft.Web/sites/<functionapp> --metric FunctionExecutionUnits,FunctionExecutionCount --aggregation Total --interval PT1H

--metric FunctionExecutionUnits,FunctionExecutionCount

Does this actually return both metrics? The CLI does not accept comma-separated lists.

I'm confused.. yeah it works:

{
  "cost": 0.0,
  "interval": "1:00:00",
  "timespan": "2018-01-26T18:22:24Z/2018-01-26T19:22:24Z",
  "value": [
    {
      "id": "/subscriptions/<SUBID>/resourceGroups/pbtest/providers/Microsoft.Web/sites/pbtest/providers/Microsoft.Insights/metrics/FunctionExecutionUnits",
      "name": {
        "localizedValue": "Function Execution Units",
        "value": "FunctionExecutionUnits"
      },
      "resourceGroup": "pbtest",
      "timeseries": [
        {
          "data": [
            {
              "average": null,
              "count": null,
              "maximum": null,
              "minimum": null,
              "timeStamp": "2018-01-26T18:22:00+00:00",
              "total": 12523136.0
            }
          ],
          "metadatavalues": []
        }
      ],
      "type": "Microsoft.Insights/metrics",
      "unit": "Count"
    },
    {
      "id": "/subscriptions/<SUBID>/resourceGroups/pbtest/providers/Microsoft.Web/sites/pbtest/providers/Microsoft.Insights/metrics/FunctionExecutionCount",
      "name": {
        "localizedValue": "Function Execution Count",
        "value": "FunctionExecutionCount"
      },
      "resourceGroup": "pbtest",
      "timeseries": [
        {
          "data": [
            {
              "average": null,
              "count": null,
              "maximum": null,
              "minimum": null,
              "timeStamp": "2018-01-26T18:22:00+00:00",
              "total": 1438.0
            }
          ],
          "metadatavalues": []
        }
      ],
      "type": "Microsoft.Insights/metrics",
      "unit": "Count"
    }
  ]
}

@paulbatum thanks for the confirmation. This works because the service accepts a string of space-separated values. Glad the command is working better for you.

@troydai we should fix this so that --metric becomes --metrics and accepts a space-separated list of values that we concatenate with commas. The comma syntax will still work because the server accepts it, but we need to make it clear that the command DOES accept multiple values and promote the favored syntax for doing that.

On my radar.

I can confirm that is working good for me, I'm using azure-cli (2.0.25), I'm able to use the --aggregation parameter, however something that was pretty cool and convenient stopped working, I'm talking about the --interval parameter (that has replaced --time-grain), before I was able to pull 3 months data in one shot, now I'm getting the error:
azure.mgmt.monitor.models.error_response.ErrorResponseException: Invalid time grain duration: P3M, supported ones are: 00:01:00,00:05:00,00:15:00,00:30:00,01:00:00,06:00:00,12:00:00,1.00:00:00

As I said, in earlier versions I was pulling data with parameter, e.g --time-grain P3M 馃槩 馃槶 馃槥 馃樋

@acabrera-rms, thank you for the feedback. Would --start-time and --end-time help you?

@troydai, those parameters are intended for specifying a period of time. I was talking about the Interval of the data (granularity?!?!?!), before I was able to pull 1 month in a single shot. Now, let's say, to get metrics for Dec 2017 I am getting 31 different values rather than just one.
I'd like to do something like:
--interval P1M --start-time 2017-12-01T00:00:00Z --end-time 2017-12-31T00:00:00Z
but, P1M is not supported anymore 馃槩 馃槶

Whatever is supported is a function of the service, not the CLI.

Was this page helpful?
0 / 5 - 0 ratings