提供者資源使用狀況 APIProvider resource usage API

「提供者」 一詞適用於服務管理員和任何委派的提供者。The term provider applies to the service administrator and to any delegated providers. Azure Stack Hub 操作員和委派的提供者可使用提供者使用狀況 API,檢視其直接租用戶的使用狀況。Azure Stack Hub operators and delegated providers can use the provider usage API to view the usage of their direct tenants. 例如,如下圖所示,P0 可以呼叫提供者 API,以在 P1 和 P2 上取得直接使用狀況資訊;而 P1 可呼叫以取得 P3 和 P4 的使用狀況資訊。For example, as shown in the following diagram, P0 can call the provider API to get direct usage information on P1 and P2, and P1 can call for usage information on P3 and P4.

提供者階層的概念模型

API 呼叫參考API call reference

要求Request

要求會取得所要求的訂用帳戶在要求的時間範圍內的耗用量詳細資料。The request gets consumption details for the requested subscriptions and for the requested time frame. 沒有要求主體。There's no request body.

此使用狀況 API 是提供者 API,因此必須將提供者訂用帳戶中的「擁有者」 、「參與者」 或「讀者」 角色指派給呼叫者。This usage API is a provider API, so the caller must be assigned an Owner , Contributor , or Reader role in the provider's subscription.

方法Method 要求 URIRequest URI
GETGET https://{armendpoint}/subscriptions/{subId}/providers/Microsoft.Commerce.Admin/subscriberUsageAggregates?reportedStartTime={reportedStartTime}&reportedEndTime={reportedEndTime}&aggregationGranularity={granularity}&subscriberId={sub1.1}&api-version=2015-06-01-preview&continuationToken={token-value}

引數Arguments

引數Argument 描述Description
armendpoint 您 Azure Stack Hub 環境的 Azure Resource Manager 端點。Azure Resource Manager endpoint of your Azure Stack Hub environment. 依 Azure Stack Hub 慣例,Azure Resource Manager 端點名稱的格式是 https://adminmanagement.{domain-name}The Azure Stack Hub convention is that the name of the Azure Resource Manager endpoint is in the format https://adminmanagement.{domain-name}. 例如,如果是 Azure Stack 開發套件 (ASDK),則網域名稱會是 local.azurestack.external ,而 Resource Manager 端點會是 https://adminmanagement.local.azurestack.externalFor example, for the Azure Stack Development Kit (ASDK), if the domain name is local.azurestack.external , then the Resource Manager endpoint is https://adminmanagement.local.azurestack.external.
subId 進行呼叫之使用者的訂用帳戶識別碼。Subscription ID of the user who makes the call.
reportedStartTime 查詢的開始時間。Start time of the query. DateTime 值應該以國際標準時間 (UTC) 格式及小時開始時的時間呈現,例如 13:00。The value for DateTime should be in Coordinated Universal Time (UTC) and at the beginning of the hour; for example, 13:00. 對於每日彙總,請將這個值設定為 UTC 午夜。For daily aggregation, set this value to UTC midnight. 格式是逸出的 ISO 8601,例如 2015-06-16T18%3a53%3a11%2b00%3a00Z,其中冒號會逸出為 %3a 而加號會逸出為 %2b,使其符合 URI 規範。The format is escaped ISO 8601; for example, 2015-06-16T18%3a53%3a11%2b00%3a00Z, where the colon is escaped to %3a and the plus is escaped to %2b so that it's URI-friendly.
reportedEndTime 查詢的結束時間。End time of the query. 適用於 reportedStartTime 的限制也適用於此引數。The constraints that apply to reportedStartTime also apply to this argument. reportedEndTime 的值不得為未來或目前的日期。The value for reportedEndTime can't be either in the future, or the current date. 如果是,結果會設為「處理未完成。」If it is, the result is set to "processing not complete."
aggregationGranularity 這是選擇性引數,它可以有兩個截然不同的可能值 ( 每日每小時 )。Optional parameter that has two discrete potential values: daily and hourly. 如同以上兩個值所暗示,一個會每日傳回資料,另一個則會每小時傳回資料。As the values suggest, one returns the data in daily granularity, and the other is an hourly resolution. 預設值為 [每日] 選項。The daily option is the default.
subscriberId 訂用帳戶 ID。Subscription ID. 若要取得篩選的資料,需要提供者的直接租用戶訂用帳戶 ID。To get filtered data, the subscription ID of a direct tenant of the provider is required. 如果未指定訂用帳戶 ID 參數,呼叫會傳回所有提供者直接租用戶的使用狀況資料。If no subscription ID parameter is specified, the call returns usage data for all the provider's direct tenants.
api-version 用來提出此要求的通訊協定版本。Version of the protocol that's used to make this request. 此值會設定為 2015-06-01-previewThis value is set to 2015-06-01-preview.
continuationToken 從上次呼叫使用情況 API 提供者所擷取的權杖。Token retrieved from the last call to the usage API provider. 回應大於 1,000 行時,就需要這個權杖。This token is needed when a response is greater than 1,000 lines. 這可作為進度的書籤使用。It acts as a bookmark for the progress. 若無此權杖,則會從一天或一小時的開始擷取資料,取決於所傳遞的細微性。If the token isn't present, the data is retrieved from the beginning of the day or hour, based on the granularity passed in.

回應Response

GET
/subscriptions/sub1/providers/Microsoft.Commerce.Admin/subscriberUsageAggregates?reportedStartTime=reportedStartTime=2014-05-01T00%3a00%3a00%2b00%3a00&reportedEndTime=2015-06-01T00%3a00%3a00%2b00%3a00&aggregationGranularity=Daily&subscriberId=sub1.1&api-version=1.0
{
"value": [
{

"id":
"/subscriptions/sub1.1/providers/Microsoft.Commerce.Admin/UsageAggregate/sub1.1-

meterID1",
"name": "sub1.1-meterID1",
"type": "Microsoft.Commerce.Admin/UsageAggregate",

"properties": {
"subscriptionId":"sub1.1",
"usageStartTime": "2015-03-03T00:00:00+00:00",
"usageEndTime": "2015-03-04T00:00:00+00:00",
"instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"resourceUri1\",\"location\":\"Alaska\",\"tags\":null,\"additionalInfo\":null}}",
"quantity":2.4000000000,
"meterId":"meterID1"

}
},

. . .

回應詳細資料Response details

引數Argument 描述Description
id 使用情況彙總的唯一識別碼。Unique ID of the usage aggregate.
name 使用情況彙總的名稱。Name of the usage aggregate.
type 資源定義。Resource definition.
subscriptionId Azure Stack Hub 使用者的訂用帳戶識別碼。Subscription identifier of the Azure Stack Hub user.
usageStartTime 此使用情況彙總所屬的使用情況貯體 UTC 開始時間。UTC start time of the usage bucket to which this usage aggregate belongs.
usageEndTime 此使用情況彙總所屬的使用情況貯體 UTC 結束時間。UTC end time of the usage bucket to which this usage aggregate belongs.
instanceData 執行個體詳細資料的機碼值組 (新格式):Key-value pairs of instance details (in a new format):
resourceUri:完整資源 ID,包含資源群組和執行個體名稱。resourceUri: Fully qualified resource ID, which includes the resource groups and the instance name.
location:此服務執行所在的區域。location: Region in which this service was run.
tags:使用者所指定的資源標記。tags: Resource tags that are specified by the user.
additionalInfo:更多關於所取用資源的詳細資料 (例如,作業系統版本或映像類型)。additionalInfo: More details about the resource that was consumed; for example, the OS version or image type.
quantity 此時間範圍內發生的資源取用數量。Amount of resource consumption that occurred in this time frame.
meterId 所取用資源的唯一識別碼 (亦稱為 ResourceID)。Unique ID for the resource that was consumed (also called ResourceID).

擷取使用量資訊Retrieve usage information

PowerShellPowerShell

若要產生使用量資料,您應該要有正在執行且積極地使用系統的資源,例如作用中的虛擬機器 (VM) 或包含某些資料的儲存體帳戶。To generate the usage data, you should have resources that are running and actively using the system; for example, an active virtual machine (VM), or a storage account containing some data. 如果不確定是否有任何資源正在 Azure Stack Hub Marketplace 中執行,請部署 VM,並檢查 VM 監控刀鋒視窗以確定它正在執行。If you're not sure whether you have any resources running in the Azure Stack Hub Marketplace, deploy a VM, and verify the VM monitoring blade to make sure it's running. 請使用下列 PowerShell Cmdlet 檢視使用量資料:Use the following PowerShell cmdlets to view the usage data:

  1. 安裝適用於 Azure Stack Hub 的 PowerShellInstall PowerShell for Azure Stack Hub.

  2. 設定 Azure Stack Hub 使用者Azure Stack Hub 操作員 的 PowerShell 環境。Configure the Azure Stack Hub user or the Azure Stack Hub operator PowerShell environment.

  3. 若要擷取使用量資料,請呼叫 Get-AzsSubscriberUsage PowerShell Cmdlet:To retrieve the usage data, call the Get-AzsSubscriberUsage PowerShell cmdlet:

    Get-AzsSubscriberUsage -ReportedStartTime "2017-09-06T00:00:00Z" -ReportedEndTime "2017-09-07T00:00:00Z"
    

REST APIREST API

您可呼叫 Microsoft.Commerce.Admin 服務,以收集已刪除訂用帳戶的使用量資訊。You can collect usage information for deleted subscriptions by calling the Microsoft.Commerce.Admin service.

傳回已刪除或作用中使用者的所有租用戶使用量Return all tenant usage for deleted for active users

方法Method 要求 URIRequest URI
GETGET https://{armendpoint}/subscriptions/{subId}/providersMicrosoft.Commerce.Admin/subscriberUsageAggregates?reportedStartTime={start-time}&reportedEndTime={end-endtime}&aggregationGranularity=Hourly&api-version=2015-06-01-preview

傳回已刪除或作用中使用者的使用量Return usage for deleted or active tenant

方法Method 要求 URIRequest URI
GETGET https://{armendpoint}/subscriptions/{subId}/providersMicrosoft.Commerce.Admin/subscriberUsageAggregates?reportedStartTime={start-time}&reportedEndTime={end-endtime}&aggregationGranularity=Hourly&subscriberId={subscriber-id}&api-version=2015-06-01-preview

後續步驟Next steps