Search code examples
azureazure-sdkazure-sdk-python

Azure Metric: dtu_used does not accept zero dimension case


I am trying to get the metrics of Microsoft.Sql/servers/ resource: The resource_id is: /subscriptions/******-8**2-44**-95**-****13a5****/resourceGroups/SQLTesting/providers/Microsoft.Sql/servers/sqltest As in example metrics

resource_id="/subscriptions/******-8**2-44**-95**-****13a5****/resourceGroups/SQLTesting/providers/Microsoft.Sql/servers/sqltest"
today = datetime.datetime.now().date()
    yesterday = today - datetime.timedelta(days=1)

    metrics_data = client.metrics.list(
        resource_id,
        timespan="{}/{}".format(yesterday, today),
        interval='PT1H',
        metricnames='dtu_used',
        aggregation='Average'
    )

    for item in metrics_data.value:
        # azure.mgmt.monitor.models.Metric
        print("{} ({})".format(item.name.localized_value, item.unit.name))
        for timeserie in item.timeseries:
            for data in timeserie.data:
                # azure.mgmt.monitor.models.MetricData
                print("{}: {}".format(data.time_stamp, data.total))

But I am getting ErrorResponseException: Metric: dtu_used does not accept zero dimension case error. How to fix it?


Solution

  • In metric definition, there is a property called isDimensionRequired, when querying for its value you must provide a filter for the dimension; if you do not do so the metric query will fail.

    So, for dtu_used metric of SQL Server, the value is true which means that you need to provide the DataBaseResourceId in filter.

    enter image description here

    Here is a ample:

    enter image description here

    So, basically, you need to add a filter in the metric query.