共用方式為


取得客戶的 Azure 使用率記錄

適用於:合作夥伴中心 |美國政府適用的 Microsoft Cloud 合作夥伴中心

您可以使用 Azure 使用率 API,取得指定期間內客戶的 Azure 訂用帳戶使用量記錄。

必要條件

此 API 會針對任意時間範圍傳回每日和每小時未分級的耗用量。 不過, Azure 方案不支援此 API。 如果您有 Azure 方案,請參閱取得發票未計費取用明細專案和改為取得發票計費取用明細專案一文 這些文章說明如何在每一資源每計量每日層級取得評等耗用量。 此速率耗用量相當於 Azure 使用率 API 所提供的每日粒紋數據。 您必須使用發票標識碼來擷取計費使用量數據。 或者,您可以使用目前和先前的期間來取得未計費的使用量估計值。 Azure 方案訂用帳戶資源目前不支援每小時粒度數據和任意日期範圍篩選。

Azure 使用量 API

此 Azure 使用率 API 提供一段時間的使用率記錄存取權,代表計費系統中回報使用率的時間。 它可讓您存取用來建立和計算對帳檔案的相同使用率數據。 不過,它不知道計費系統對帳檔案邏輯。 您不應該預期對帳檔案摘要結果會比對從這個 API 擷取的結果正好在同一時間週期內。

例如,計費系統會採用相同的使用率數據,並套用延遲規則,以判斷對帳檔案中考慮的內容。 當計費期間關閉時,所有使用量直到帳單期間結束的一天結束,都會包含在對帳檔案中。 在計費期間結束后 24 小時內報告的任何延遲使用量,會在下一個對帳檔案中納入考慮。 如需合作夥伴計費方式的延遲規則,請參閱 取得 Azure 訂用帳戶的耗用量數據。

此 REST API 已分頁。 如果響應承載大於單一頁面,您必須遵循下一個連結以取得下一頁的使用率記錄。

案例:合作夥伴 A 已將 Azure 舊版訂用帳戶 (145P) 的帳單擁有權轉移給合作夥伴 B

如果合作夥伴將 Azure 舊版訂用帳戶的帳單擁有權轉移給另一個合作夥伴,當新的合作夥伴針對已轉移的訂用帳戶呼叫使用量 API 時,他們必須使用商務訂用帳戶標識碼(其顯示在合作夥伴中心帳戶中),而不是 Azure 權利標識符。 只有在合作夥伴 B 代表客戶 管理員 時,才會顯示 Azure 權利標識碼給客戶的 Azure 入口網站。

若要成功呼叫已轉移訂用帳戶的使用率 API,新合作夥伴必須使用商務訂用帳戶標識碼。

C#

若要取得 Azure 使用率記錄:

  1. 取得客戶標識碼和訂用帳戶標識碼。

  2. 呼叫 IAzureUtilizationCollection.Query 方法,以傳回包含使用率記錄的 ResourceCollection

  3. 取得 Azure 使用率記錄列舉值,以周遊使用率頁面。 這是必要步驟,因為資源集合已分頁。

// IAggregatePartner partnerOperations;
// string customerId;
// string subscriptionId;

IPartner partner = PartnerService.Instance.CreatePartnerOperations(credentials);

// Retrieve the utilization records for the last year in pages of 100 records.
var utilizationRecords = partner.Customers[customerId].Subscriptions[subscriptionId].Utilization.Azure.Query(
    DateTimeOffset.Now.AddYears(-1),
    DateTimeOffset.Now,
    size: 100);

// Create an Azure utilization enumerator which will aid us in traversing the utilization pages.
var utilizationRecordEnumerator = partner.Enumerators.Utilization.Azure.Create(utilizationRecords);

while (utilizationRecordEnumerator.HasValue)
{
    //
    // Insert code here to work with this page.
    //

    // Get the next page.
    utilizationRecordEnumerator.Next();
}

Java

合作夥伴中心 Java SDK 可用來管理合作夥伴中心資源。 它是由合作夥伴社群維護的開放原始碼專案,且 Microsoft 未正式支援。 如果您遇到問題,可以從社群取得協助在 GitHub 上提出問題

若要取得 Azure 使用率記錄,您必須先需要客戶識別碼和訂用帳戶識別碼。 接著, 您會呼叫 IAzureUtilizationCollection.query 函式,以傳回 包含使用率記錄的 ResourceCollection 。 因為資源集合已分頁,因此您必須取得 Azure 使用率記錄列舉值,以周遊使用率頁面。

// IAggregatePartner partnerOperations;
// String customerId;
// String subscriptionId;

ResourceCollection<AzureUtilizationRecord> utilizationRecords = partnerOperations.getCustomers()
  .byId(customerId).getSubscriptions().byId(subscriptionId)
  .getUtilization().getAzure().query(
      new DateTime().minusYears(1),
      new DateTime(),
      AzureUtilizationGranularity.Daily,
      true,
      100);

// Create an Azure utilization enumerator which will aid us in traversing the utilization pages
IResourceCollectionEnumerator<ResourceCollection<AzureUtilizationRecord>> utilizationRecordEnumerator =
    partnerOperations.getEnumerators().getUtilization().getAzure().create(utilizationRecords);

while (utilizationRecordEnumerator.hasValue())
{
    //
    // Insert code here to work with this page.
    //

    // get the next page
    utilizationRecordEnumerator.next();
}

PowerShell

合作夥伴中心 PowerShell 模組可用來管理合作夥伴中心資源。 它是由合作夥伴社群維護的開放原始碼專案,且 Microsoft 未正式支援。 如果您遇到問題,可以從社群取得協助在 GitHub 上提出問題

若要取得 Azure 使用率記錄,您必須先需要客戶識別碼和訂用帳戶識別碼。 然後,您呼叫 Get-PartnerCustomerSubscriptionUtilization。 此命令會傳回指定期間內所有可用的記錄。

# $customerId
# $subscriptionId

Get-PartnerCustomerSubscriptionUtilization -CustomerId $customerId -SubscriptionId $subscriptionId -StartDate (Get-Date).AddDays(-2).ToUniversalTime() -Granularity Hourly -ShowDetails

REST 要求

要求語法

方法 要求 URI
GET {baseURL}/v1/customers/{customer-tenant-id}/subscriptions/{subscription-id}/utilizations/azure?start_time={start-time}&end_time={end-time}&granularity={granularity}&show_details={True}

URI 參數

使用下列路徑和查詢參數來取得使用率記錄。

名稱 類型​​ 必要 描述
customer-tenant-id string Yes 識別客戶的 GUID 格式字串。
subscription-id string Yes 識別訂用帳戶的 GUID 格式字串。
start_time UTC 日期時間位移格式的字串 Yes 時間範圍的開始,表示計費系統中回報使用率的時間範圍。
end_time UTC 日期時間位移格式的字串 Yes 時間範圍的結尾,表示計費系統中回報使用率的時間範圍。
粒度 string No 定義使用量匯總的數據粒度。 可用的選項包括: daily (預設值)和 hourly
show_details boolean No 指定是否要取得實例層級的使用詳細數據。 預設值為 true
size number No 指定單一 API 呼叫所傳回的匯總數目。 預設值為 1000。 最大值為 1000。

要求標頭

如需詳細資訊,請參閱合作夥伴中心 REST 標頭

要求本文

要求範例

下列範例要求會產生類似對帳檔案在 7/2 - 8/1 期間顯示的結果。 這些結果可能不完全相符(如需詳細資訊,請參閱 Azure 使用率 API 一節)。

此範例要求會傳回計費系統中在上午 7/2 和上午 12 點 8/2 之間回報的使用率數據(UTC)。

GET https://api.partnercenter.microsoft.com/v1/customers/E499C962-9218-4DBA-8B83-8ADC94F47B9F/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/utilizations/azure?start_time=2017-07-02T00:00:00-08:00&end_time=2017-08-02T00:00:00-08:00 HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: e6a3b6b2-230a-4813-999d-57f883b60d38
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Host: api.partnercenter.microsoft.com

REST 回應

如果成功,這個方法會在回應本文中傳回 Azure 使用率記錄資源的集合。 如果相依系統中尚未準備好 Azure 使用率數據,此方法會傳回 HTTP 狀態代碼 204,其中包含 Retry-After 標頭。

回應成功和錯誤碼

每個回應都隨附 HTTP 狀態碼,會指出成功與否以及其他的偵錯資訊。 使用網路追蹤工具來讀取 HTTP 狀態代碼、 錯誤碼類型和其他參數。

回應範例

HTTP/1.1 200 OK
Content-Length: 2630
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: e6a3b6b2-230a-4813-999d-57f883b60d38
MS-CV: PjuGoYrw806o6A3Y.0
MS-ServerId: 030020525
Date: Fri, 04 Aug 2017 23:48:28 GMT

{
  "totalCount": 2,
  "items": [
    {
      "usageStartTime": "2017-06-07T17:00:00-07:00",
      "usageEndTime": "2017-06-08T17:00:00-07:00",
      "resource": {
        "id": "8767aeb3-6909-4db2-9927-3f51e9a9085e",
        "name": "Storage Admin",
        "category": "Storage",
        "subcategory": "Block Blob",
        "region": "Azure Stack"
      },
      "quantity": 0.217790327034891,
      "unit": "1 GB/Hr",
      "infoFields": {},
      "instanceData": {
        "resourceUri": "/subscriptions/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/resourcegroups/system.local/providers/Microsoft.Storage/storageaccounts/srphealthaccount",
        "location": "azurestack",
        "partNumber": "",
        "orderNumber": "",
        "additionalInfo": {
          "azureStack.MeterId": "09F8879E-87E9-4305-A572-4B7BE209F857",
          "azureStack.SubscriptionId": "cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a",
          "azureStack.Location": "local",
          "azureStack.EventDateTime": "06/05/2017 06:00:00"
        }
      },
      "attributes": {
        "objectType": "AzureUtilizationRecord"
      }
    },
    {
      "usageStartTime": "2017-06-07T17:00:00-07:00",
      "usageEndTime": "2017-06-08T17:00:00-07:00",
      "resource": {
        "id": "8767aeb3-6909-4db2-9927-3f51e9a9085e",
        "name": "Storage Admin",
        "category": "Storage",
        "subcategory": "Block Blob",
        "region": "Azure Stack"
      },
      "quantity": 0.217790327034891,
      "unit": "1 GB/Hr",
      "infoFields": {},
      "instanceData": {
        "resourceUri": "/subscriptions/bbbb1b1b-cc2c-dd3d-ee4e-ffffff5f5f5f/resourcegroups/system.local/providers/Microsoft.Storage/storageaccounts/srphealthaccount",
        "location": "azurestack",
        "partNumber": "",
        "orderNumber": "",
        "additionalInfo": {
          "azureStack.MeterId": "09F8879E-87E9-4305-A572-4B7BE209F857",
          "azureStack.SubscriptionId": "cccc2c2c-dd3d-ee4e-ff5f-aaaaaa6a6a6a",
          "azureStack.Location": "local",
          "azureStack.EventDateTime": "06/05/2017 06:00:00"
        },
        "attributes": {
          "objectType": "AzureUtilizationRecord"
        }
      },

      "links": {
        "self": {
          "uri": "customers/E499C962-9218-4DBA-8B83-8ADC94F47B9F/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/utilizations/azure?start_time=2017-06-10T00:00:00Z&end_time=2017-07-09T00:00:00Z&granularity=Daily&show_details=True&size=1000",
          "method": "GET",
          "headers": []
        }
      },
      "attributes": {
        "objectType": "Collection"
      }
    }
  ]
}