Metrics Batch - Batch

Lists the metric values for multiple resources.

POST {endpoint}/subscriptions/{subscriptionId}/metrics:getBatch?metricnamespace={metricnamespace}&metricnames={metricnames}&api-version=2023-05-01-preview
POST {endpoint}/subscriptions/{subscriptionId}/metrics:getBatch?starttime={starttime}&endtime={endtime}&interval={interval}&metricnamespace={metricnamespace}&metricnames={metricnames}&aggregation={aggregation}&top={top}&orderby={orderby}&filter={filter}&api-version=2023-05-01-preview

URI Parameters

Name In Required Type Description
endpoint
path True

string

url

The regional endpoint to use, for example https://eastus.metrics.monitor.azure.com. The region should match the region of the requested resources. For global resources, the region should be 'global'.

subscriptionId
path True

string

The subscription identifier for the resources in this batch.

api-version
query True

string

Client Api Version.

metricnames
query True

string[]

The names of the metrics (comma separated) to retrieve.

metricnamespace
query True

string

Metric namespace that contains the requested metric names.

aggregation
query

string

The list of aggregation types (comma separated) to retrieve. Examples: average, minimum, maximum

endtime
query

string

The end time of the query. It is a string in the format 'yyyy-MM-ddTHH:mm:ss.fffZ'.

filter
query

string

The filter is used to reduce the set of metric data returned.
Example:
Metric contains metadata A, B and C.
- Return all time series of C where A = a1 and B = b1 or b2
filter=A eq ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’
- Invalid variant:
filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B = ‘b2’
This is invalid because the logical or operator cannot separate two different metadata names.
- Return all time series where A = a1, B = b1 and C = c1:
filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’
- Return all time series where A = a1
filter=A eq ‘a1’ and B eq ‘’ and C eq ‘.

interval
query

string

The interval (i.e. timegrain) of the query in ISO 8601 duration format. Defaults to PT1M. Special case for 'FULL' value that returns single datapoint for entire time span requested. Examples: PT15M, PT1H, P1D, FULL

orderby
query

string

The aggregation to use for sorting results and the direction of the sort. Only one order can be specified. Examples: sum asc

starttime
query

string

The start time of the query. It is a string in the format 'yyyy-MM-ddTHH:mm:ss.fffZ'. If you have specified the endtime parameter, then this parameter is required. If only starttime is specified, then endtime defaults to the current time. If no time interval is specified, the default is 1 hour.

top
query

integer

int32

The maximum number of records to retrieve per resource ID in the request. Valid only if filter is specified. Defaults to 10.

Request Body

Name Type Description
resourceids

string[]

The list of resource IDs to query metrics for.

Responses

Name Type Description
200 OK

MetricResultsResponse

The response to a metrics query.

Other Status Codes

AdditionalInfoErrorResponse

Describes the format of Error response.

Headers

x-ms-error-code: string

Security

AADToken

Azure Active Directory OAuth2 Authentication

Type: oauth2
Flow: application
Token URL: https://login.microsoftonline.com/common/oauth2/v2.0/token

Scopes

Name Description
https://metrics.monitor.azure.com/.default https://metrics.monitor.azure.com/.default

Examples

Query Storage Metrics

Sample Request

POST {endpoint}/subscriptions/123456728-abcd-1234-abcd-123456789abc/metrics:getBatch?starttime=2023-02-01T20:00:00.123Z&endtime=2023-02-01T23:00:00.345Z&interval=PT15M&metricnamespace=Microsoft.Storage/storageAccounts&metricnames=Ingress,Egress&aggregation=average,minimum,maximum&top=10&orderby=average desc&filter=ApiName eq 'GetBlob' or ApiName eq 'GetBlobServiceProperties' and Authentication eq '*'&api-version=2023-05-01-preview

{
  "resourceids": [
    "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage1",
    "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage2"
  ]
}

Sample Response

{
  "values": [
    {
      "starttime": "2023-02-01T20:00:00.123Z",
      "endtime": "2023-02-01T23:00:00.345Z",
      "interval": "PT15M",
      "value": [
        {
          "id": "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage1/providers/Microsoft.Insights/metrics/Ingress",
          "type": "Microsoft.Insights/metrics",
          "name": {
            "value": "Ingress",
            "localizedValue": "Ingress"
          },
          "displayDescription": "The amount of ingress data, in bytes. This number includes ingress from an external client into Azure Storage as well as ingress within Azure.",
          "unit": "Bytes",
          "timeseries": [
            {
              "metadatavalues": [
                {
                  "name": {
                    "value": "apiname",
                    "localizedValue": "apiname"
                  },
                  "value": "GetBlob"
                },
                {
                  "name": {
                    "value": "authentication",
                    "localizedValue": "authentication"
                  },
                  "value": "SAS"
                }
              ],
              "data": [
                {
                  "timeStamp": "2023-02-01T20:00:00Z",
                  "average": 437,
                  "minimum": 437,
                  "maximum": 437
                },
                {
                  "timeStamp": "2023-02-01T20:15:00Z",
                  "average": 438.0735294117647,
                  "minimum": 437,
                  "maximum": 583
                },
                {
                  "timeStamp": "2023-02-01T20:30:00Z",
                  "average": 437,
                  "minimum": 437,
                  "maximum": 437
                },
                {
                  "timeStamp": "2023-02-01T20:45:00Z",
                  "average": 437.54477611940297,
                  "minimum": 437,
                  "maximum": 583
                },
                {
                  "timeStamp": "2023-02-01T21:00:00Z",
                  "average": 437,
                  "minimum": 437,
                  "maximum": 437
                },
                {
                  "timeStamp": "2023-02-01T21:15:00Z",
                  "average": 438.0735294117647,
                  "minimum": 437,
                  "maximum": 583
                },
                {
                  "timeStamp": "2023-02-01T21:30:00Z",
                  "average": 437,
                  "minimum": 437,
                  "maximum": 437
                },
                {
                  "timeStamp": "2023-02-01T21:45:00Z",
                  "average": 437.54477611940297,
                  "minimum": 437,
                  "maximum": 583
                },
                {
                  "timeStamp": "2023-02-01T22:00:00Z",
                  "average": 437,
                  "minimum": 437,
                  "maximum": 437
                },
                {
                  "timeStamp": "2023-02-01T22:15:00Z",
                  "average": 438.0735294117647,
                  "minimum": 437,
                  "maximum": 583
                },
                {
                  "timeStamp": "2023-02-01T22:30:00Z",
                  "average": 437,
                  "minimum": 437,
                  "maximum": 437
                },
                {
                  "timeStamp": "2023-02-01T22:45:00Z",
                  "average": 437.542750929368,
                  "minimum": 437,
                  "maximum": 583
                }
              ]
            },
            {
              "metadatavalues": [
                {
                  "name": {
                    "value": "apiname",
                    "localizedValue": "apiname"
                  },
                  "value": "GetBlobServiceProperties"
                },
                {
                  "name": {
                    "value": "authentication",
                    "localizedValue": "authentication"
                  },
                  "value": "AccountKey"
                }
              ],
              "data": [
                {
                  "timeStamp": "2023-02-01T20:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:00:00Z",
                  "average": 342,
                  "minimum": 342,
                  "maximum": 342
                },
                {
                  "timeStamp": "2023-02-01T22:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:45:00Z"
                }
              ]
            }
          ],
          "errorCode": "Success"
        },
        {
          "id": "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage1/providers/Microsoft.Insights/metrics/Egress",
          "type": "Microsoft.Insights/metrics",
          "name": {
            "value": "Egress",
            "localizedValue": "Egress"
          },
          "displayDescription": "The amount of egress data. This number includes egress to external client from Azure Storage as well as egress within Azure. As a result, this number does not reflect billable egress.",
          "unit": "Bytes",
          "timeseries": [
            {
              "metadatavalues": [
                {
                  "name": {
                    "value": "apiname",
                    "localizedValue": "apiname"
                  },
                  "value": "GetBlobServiceProperties"
                },
                {
                  "name": {
                    "value": "authentication",
                    "localizedValue": "authentication"
                  },
                  "value": "AccountKey"
                }
              ],
              "data": [
                {
                  "timeStamp": "2023-02-01T20:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:00:00Z",
                  "average": 796,
                  "minimum": 796,
                  "maximum": 796
                },
                {
                  "timeStamp": "2023-02-01T22:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:45:00Z"
                }
              ]
            },
            {
              "metadatavalues": [
                {
                  "name": {
                    "value": "apiname",
                    "localizedValue": "apiname"
                  },
                  "value": "GetBlob"
                },
                {
                  "name": {
                    "value": "authentication",
                    "localizedValue": "authentication"
                  },
                  "value": "SAS"
                }
              ],
              "data": [
                {
                  "timeStamp": "2023-02-01T20:00:00Z",
                  "average": 361,
                  "minimum": 361,
                  "maximum": 361
                },
                {
                  "timeStamp": "2023-02-01T20:15:00Z",
                  "average": 365.83088235294116,
                  "minimum": 361,
                  "maximum": 1018
                },
                {
                  "timeStamp": "2023-02-01T20:30:00Z",
                  "average": 361,
                  "minimum": 361,
                  "maximum": 361
                },
                {
                  "timeStamp": "2023-02-01T20:45:00Z",
                  "average": 363.4514925373134,
                  "minimum": 361,
                  "maximum": 1018
                },
                {
                  "timeStamp": "2023-02-01T21:00:00Z",
                  "average": 361,
                  "minimum": 361,
                  "maximum": 361
                },
                {
                  "timeStamp": "2023-02-01T21:15:00Z",
                  "average": 365.83088235294116,
                  "minimum": 361,
                  "maximum": 1018
                },
                {
                  "timeStamp": "2023-02-01T21:30:00Z",
                  "average": 361,
                  "minimum": 361,
                  "maximum": 361
                },
                {
                  "timeStamp": "2023-02-01T21:45:00Z",
                  "average": 363.4514925373134,
                  "minimum": 361,
                  "maximum": 1018
                },
                {
                  "timeStamp": "2023-02-01T22:00:00Z",
                  "average": 361,
                  "minimum": 361,
                  "maximum": 361
                },
                {
                  "timeStamp": "2023-02-01T22:15:00Z",
                  "average": 365.83088235294116,
                  "minimum": 361,
                  "maximum": 1018
                },
                {
                  "timeStamp": "2023-02-01T22:30:00Z",
                  "average": 361,
                  "minimum": 361,
                  "maximum": 361
                },
                {
                  "timeStamp": "2023-02-01T22:45:00Z",
                  "average": 363.4423791821561,
                  "minimum": 361,
                  "maximum": 1018
                }
              ]
            }
          ],
          "errorCode": "Success"
        }
      ],
      "namespace": "microsoft.storage/storageaccounts",
      "resourceregion": "eastus",
      "resourceid": "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage1"
    },
    {
      "starttime": "2023-02-01T20:00:00.123Z",
      "endtime": "2023-02-01T23:00:00.345Z",
      "interval": "PT15M",
      "value": [
        {
          "id": "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage2/providers/Microsoft.Insights/metrics/Ingress",
          "type": "Microsoft.Insights/metrics",
          "name": {
            "value": "Ingress",
            "localizedValue": "Ingress"
          },
          "displayDescription": "The amount of ingress data, in bytes. This number includes ingress from an external client into Azure Storage as well as ingress within Azure.",
          "unit": "Bytes",
          "timeseries": [
            {
              "metadatavalues": [
                {
                  "name": {
                    "value": "apiname",
                    "localizedValue": "apiname"
                  },
                  "value": "GetBlobServiceProperties"
                },
                {
                  "name": {
                    "value": "authentication",
                    "localizedValue": "authentication"
                  },
                  "value": "AccountKey"
                }
              ],
              "data": [
                {
                  "timeStamp": "2023-02-01T20:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:00:00Z",
                  "average": 330,
                  "minimum": 330,
                  "maximum": 330
                },
                {
                  "timeStamp": "2023-02-01T22:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:45:00Z"
                }
              ]
            }
          ],
          "errorCode": "Success"
        },
        {
          "id": "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage2/providers/Microsoft.Insights/metrics/Egress",
          "type": "Microsoft.Insights/metrics",
          "name": {
            "value": "Egress",
            "localizedValue": "Egress"
          },
          "displayDescription": "The amount of egress data. This number includes egress to external client from Azure Storage as well as egress within Azure. As a result, this number does not reflect billable egress.",
          "unit": "Bytes",
          "timeseries": [
            {
              "metadatavalues": [
                {
                  "name": {
                    "value": "apiname",
                    "localizedValue": "apiname"
                  },
                  "value": "GetBlobServiceProperties"
                },
                {
                  "name": {
                    "value": "authentication",
                    "localizedValue": "authentication"
                  },
                  "value": "AccountKey"
                }
              ],
              "data": [
                {
                  "timeStamp": "2023-02-01T20:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T20:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:00:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T21:45:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:00:00Z",
                  "average": 880,
                  "minimum": 880,
                  "maximum": 880
                },
                {
                  "timeStamp": "2023-02-01T22:15:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:30:00Z"
                },
                {
                  "timeStamp": "2023-02-01T22:45:00Z"
                }
              ]
            }
          ],
          "errorCode": "Success"
        }
      ],
      "namespace": "microsoft.storage/storageaccounts",
      "resourceregion": "eastus",
      "resourceid": "/subscriptions/123456728-abcd-1234-abcd-123456789abc/resourceGroups/TestGroup/providers/Microsoft.Storage/storageAccounts/TestStorage2"
    }
  ]
}
x-ms-error-code: BadRequest
{
  "error": {
    "additionalInfo": [
      {
        "type": "string",
        "info": "TraceId={00000000-0000-0000-0000-000000000000}"
      },
      {
        "type": "string",
        "info": "ExceptionType=Microsoft.Online.Metrics.MetricsMP.Utilities.RPRequestFormatException"
      }
    ],
    "code": "BadRequest",
    "message": "Query endTime: 06/06/2021 00:00:00 is out of the Max metrics retention period: 93.00:00:00, traceId: {00000000-0000-0000-0000-000000000000}"
  }
}

Definitions

Name Description
AdditionalInfo

Additional information about the error

AdditionalInfoErrorResponse

The response to a metrics query that results in a bad request, with optional additional information.

Error

Top level error object that contains all relevant information.

LocalizableString

The localizable string class.

MetadataValue

Represents a metric metadata value.

Metric

The result data of a query.

MetricResultsResponse

The metrics result for a resource.

MetricUnit

The unit of the metric.

MetricValue

Represents a metric value.

ResourceIdList

The comma separated list of resource IDs to query metrics for.

TimeSeriesElement

A time series result type. The discriminator value is always TimeSeries in this case.

Values

The collection of metric data responses per resource, per metric.

AdditionalInfo

Additional information about the error

Name Type Description
info

string

Additional information related to the error.

type

string

The type of the info property (e.g. string).

AdditionalInfoErrorResponse

The response to a metrics query that results in a bad request, with optional additional information.

Name Type Description
error

Error

Top level error object that contains all relevant information.

Error

Top level error object that contains all relevant information.

Name Type Description
additionalInfo

AdditionalInfo[]

Additional information about the error

code

string

Error code

message

string

Error message indicating why the operation failed.

LocalizableString

The localizable string class.

Name Type Description
localizedValue

string

The display name.

value

string

The invariant value.

MetadataValue

Represents a metric metadata value.

Name Type Description
name

LocalizableString

The name of the metadata.

value

string

The value of the metadata.

Metric

The result data of a query.

Name Type Description
displayDescription

string

Detailed description of this metric.

errorCode

string

'Success' or the error details on query failures for this metric.

errorMessage

string

Error message encountered querying this specific metric.

id

string

The metric Id.

name

LocalizableString

The name and the display name of the metric, i.e. it is localizable string.

timeseries

TimeSeriesElement[]

The time series returned when a data query is performed.

type

string

The resource type of the metric resource.

unit

MetricUnit

The unit of the metric.

MetricResultsResponse

The metrics result for a resource.

Name Type Description
values

Values[]

The collection of metric data responses per resource, per metric.

MetricUnit

The unit of the metric.

Name Type Description
BitsPerSecond

string

ByteSeconds

string

Bytes

string

BytesPerSecond

string

Cores

string

Count

string

CountPerSecond

string

MilliCores

string

MilliSeconds

string

NanoCores

string

Percent

string

Seconds

string

Unspecified

string

MetricValue

Represents a metric value.

Name Type Description
average

number

The average value in the time range.

count

number

The number of samples in the time range. Can be used to determine the number of values that contributed to the average value.

maximum

number

The greatest value in the time range.

minimum

number

The least value in the time range.

timeStamp

string

The timestamp for the metric value in ISO 8601 format.

total

number

The sum of all of the values in the time range.

ResourceIdList

The comma separated list of resource IDs to query metrics for.

Name Type Description
resourceids

string[]

The list of resource IDs to query metrics for.

TimeSeriesElement

A time series result type. The discriminator value is always TimeSeries in this case.

Name Type Description
data

MetricValue[]

An array of data points representing the metric values. This is only returned if a result type of data is specified.

metadatavalues

MetadataValue[]

The metadata values returned if $filter was specified in the call.

Values

The collection of metric data responses per resource, per metric.

Name Type Description
endtime

string

The end time, in datetime format, for which the data was retrieved.

interval

string

The interval (window size) for which the metric data was returned in ISO 8601 duration format with a special case for 'FULL' value that returns single datapoint for entire time span requested (Examples: PT15M, PT1H, P1D, FULL). This may be adjusted and different from what was originally requested if AutoAdjustTimegrain=true is specified.

namespace

string

The namespace of the metrics been queried

resourceid

string

The resource that has been queried for metrics.

resourceregion

string

The region of the resource been queried for metrics.

starttime

string

The start time, in datetime format, for which the data was retrieved.

value

Metric[]

The value of the collection.