Azure Metric Batch API

Rest API地址    
https://learn.microsoft.com/en-us/rest/api/monitor/metrics-batch/batch?view=rest-monitor-2023-10-01&tabs=HTTP#code-try-0

需要给SP subscriptions基本的Monitoring Reader权限

endpoint : https://eastus.metrics.monitor.azure.com

merticnames : cpu_percent,cpu_limit
metricnamespace : Microsoft.Sql/servers/databases

Body :  
{
  "resourceids": [
    "/subscriptions/5a088000-0995-476d-9a7c-a27b1ddf4cfb/resourceGroups/RG-sqldb1/providers/Microsoft.Sql/servers/344704000sqlserver1/databases/344704000sqldb1"
  ]
}


Body支持多个ResourceID

其中metricnamespace和merticnames在Supported metrics with Azure Monitor
https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/metrics-index

Sample Data:
{
  "values": [
    {
      "starttime": "2024-05-22T13:32:18Z",
      "endtime": "2024-05-22T14:32:18Z",
      "interval": "PT1M",
      "value": [
        {
          "id": "/subscriptions/5a088000-0995-476d-9a7c-a27b1ddf4cfb/resourceGroups/RG-sqldb1/providers/Microsoft.Sql/servers/344704000sqlserver1/databases/344704000sqldb1/providers/Microsoft.Insights/metrics/cpu_percent",
          "type": "Microsoft.Insights/metrics",
          "name": {
            "value": "cpu_percent",
            "localizedValue": "CPU percentage"
          },
          "displayDescription": "CPU percentage",
          "unit": "Percent",
          "timeseries": [
            {
              "metadatavalues": [],
              "data": [
                {
                  "timeStamp": "2024-05-22T13:32:00Z",
                  "average": 0
                },
                {
                  "timeStamp": "2024-05-22T13:33:00Z",
                  "average": 0
                },
                {
                  "timeStamp": "2024-05-22T13:45:00Z",
                  "average": 0
                },
                {
                  "timeStamp": "2024-05-22T13:46:00Z",
                  "average": 0
                },
                {
                  "timeStamp": "2024-05-22T13:47:00Z",
                  "average": 0
                },
                {
                  "timeStamp": "2024-05-22T14:30:00Z",
                  "average": 0
                },
                {
                  "timeStamp": "2024-05-22T14:31:00Z",
                  "average": 0
                }
              ]
            }
          ]
        },
        {
          "id": "/subscriptions/5a088000-0995-476d-9a7c-a27b1ddf4cfb/resourceGroups/RG-sqldb1/providers/Microsoft.Sql/servers/344704000sqlserver1/databases/344704000sqldb1/providers/Microsoft.Insights/metrics/cpu_limit",
          "type": "Microsoft.Insights/metrics",
          "name": {
            "value": "cpu_limit",
            "localizedValue": "CPU limit"
          },
          "displayDescription": "CPU limit. Applies to vCore-based databases.",
          "unit": "Count",
          "timeseries": [
            {
              "metadatavalues": [],
              "data": [
                {
                  "timeStamp": "2024-05-22T13:32:00Z"
                },
                {
                  "timeStamp": "2024-05-22T13:33:00Z"
                },
                {
                  "timeStamp": "2024-05-22T13:34:00Z"
                },
                {
                  "timeStamp": "2024-05-22T13:35:00Z"
                },
                {
                  "timeStamp": "2024-05-22T13:36:00Z"
                }
              ]
            }
          ]
        }
      ],
      "namespace": "Microsoft.Sql/servers/databases",
      "resourceregion": "eastus",
      "resourceid": "/subscriptions/5a088000-0995-476d-9a7c-a27b1ddf4cfb/resourceGroups/RG-sqldb1/providers/Microsoft.Sql/servers/344704000sqlserver1/databases/344704000sqldb1"
    }
  ]
}