按计量获取订阅的使用情况数据

适用于:合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心

可以使用 MeterUsageRecord 资源集合获取客户在当前计费周期内特定 Azure 服务或资源的计量使用情况记录。 此资源集合表示整个 Azure 计划中当前计费周期的每个计量的聚合总计。

必备条件

  • 合作伙伴中心身份验证中所述的凭据。 此方案只支持使用应用凭据和用户凭据进行身份验证。

  • 客户 ID (customer-tenant-id)。 如果不知道客户的 ID,可以通过选择“客户”工作区、客户列表中的“客户”和“帐户”,在合作伙伴中心中查找该 ID。 在客户的“帐户”页上的“客户帐户信息” 部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id) 相同。

  • 订阅 ID

此新路由等效于 subscriptions/{subscription-id}/usagerecords/resources,它将继续仅适用于 Microsoft Azure (MS-AZR-0145P) 订阅。 此新路由将支持 Microsoft Azure (MS-AZR-0145P) 订阅和 Azure 计划。 若要获取 Azure 计划的此信息,需要切换到此新路由。 除了以下部分中提到的属性外,响应与旧路由相同。

C#

若要在当前计费周期内获取特定 Azure 服务或资源的客户的计量使用情况记录,请执行以下操作:

  1. 使用 IAggregatePartner.Customers 集合调用 ById () 方法。

  2. 调用 Subscriptions 属性和 UsageRecords,然后调用 “计量” 属性。 通过调用 Get () 或 GetAsync () 方法完成。

    // IAggregatePartner partnerOperations;
    // var selectedCustomerId as string;
    // var selectedSubscriptionId as string;
    
    var usageRecords = partnerOperations.Customers.ById(selectedCustomerId).Subscriptions.ById(selectedSubscriptionId).UsageRecords.Meters.Get();
    

有关示例,请参阅以下示例:

  • 示例: 控制台测试应用
  • 项目: PartnerSDK.FeatureSamples
  • 类: GetSubscriptionUsageRecordsByMeter.cs

REST 请求

请求语法

方法 请求 URI
GET {baseURL}/v1/customers/{customer-tenant-id}/subscriptions/{subscription-id}/meterusagerecords HTTP/1.1

URI 参数

下表列出了获取客户的分级使用情况信息所需的查询参数。

名称 类型 必须 说明
customer-tenant-id guid Y 与客户对应的 GUID。
subscription-id guid Y 对应于合作伙伴中心 订阅资源的标识符的 GUID,它表示 Microsoft Azure (MS-AZR-0145P) 订阅或 Azure 计划。 对于 Azure 计划订阅资源,请在此路由中提供 plan-id 作为 订阅 ID

请求标头

有关详细信息,请参阅合作伙伴中心 REST 标头

请求正文

无。

请求示例

GET https://api.partnercenter.microsoft.com/v1/customers/{customer-tenant-id}/subscriptions/{subscription-id}/meterusagerecords HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: e128c8e2-4c33-4940-a3e2-2e59b0abdc67
MS-CorrelationId: 47c36033-af5d-4457-80a4-512c1626fac4

REST 响应

如果成功,此方法在响应正文中返回 PagedResourceCollection<MeterUsageRecord> 资源。

响应的成功和错误代码

每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 有关完整列表,请参阅 错误代码

Microsoft Azure (MS-AZR-0145P) 订阅的响应示例

在此示例中,客户购买了 145P Azure PayG

对于具有 Microsoft Azure (MS-AZR-0145P) 订阅的客户,API 响应不会有任何更改。

HTTP/1.1 200 OK
Content-Length: 1120
Content-Type: application/json
MS-CorrelationId: 47c36033-af5d-4457-80a4-512c1626fac4
MS-RequestId: e128c8e2-4c33-4940-a3e2-2e59b0abdc67
Date: Tue, 17 Sep 2019 20:31:45 GMT

{
    "totalCount": 1,
    "items": [
        {
            "status": "active",
            "offerId": "MS-AZR-0145P",
            "resourceId": "11111111-F347-41B6-B02C-187B1B778A43",
            "id": "11111111-F347-41B6-B02C-187B1B778A43",
            "resourceName": "Microsoft Azure",
            "name": "Microsoft Azure",
            "totalCost": 22.861172,
            "currencyLocale": "fr-FR",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-01T23:04:41.193+00:00",
            "attributes": {
                "objectType": "SubscriptionMonthlyUsageRecord"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/{customer-tenant-id}/subscriptions/usagerecords/",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}

Azure 计划的 REST 响应示例

在此示例中,客户购买了 Azure 计划。

对于具有 Azure 计划的客户,API 响应中存在以下更改:

  • currencyLocale 替换为 currencyCode
  • usdTotalCost 是一个新字段
HTTP/1.1 200 OK
Content-Length: 1120
Content-Type: application/json
MS-CorrelationId: 47c36033-af5d-4457-80a4-512c1626fac4
MS-RequestId: e128c8e2-4c33-4940-a3e2-2e59b0abdc67
Date: Fri, 26 Feb 2016 20:31:45 GMT

{
    "totalCount": 4,
    "items": [
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNVX-005J-Data Transfer In (GB)",
            "meterName": "Data Transfer In",
            "category": "Bandwidth",
            "subcategory": "Bandwidth",
            "quantityUsed": 0.01129,
            "unit": "1 GB",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        },
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNVX-005J-Data Transfer Out (GB)",
            "meterName": "Data Transfer Out",
            "category": "Bandwidth",
            "subcategory": "Bandwidth",
            "quantityUsed": 0.000224,
            "unit": "1 GB",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        },
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNZ5-006G-10K Batch Write Operations",
            "meterName": "Batch Write Operations",
            "category": "Storage",
            "subcategory": "Tables",
            "quantityUsed": 0.2462,
            "unit": "10K",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        },
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNZ5-006G-Data Stored (GB/Month)",
            "meterName": "LRS Data Stored",
            "category": "Storage",
            "subcategory": "Tables",
            "quantityUsed": 0.002632,
            "unit": "1 GB/Month",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/<customer-tenant-id>/subscriptions/<subscription-id>/meterusagerecords",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}