提供商资源使用情况 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 资源管理器终结点。Azure Resource Manager endpoint of your Azure Stack Hub environment. 按 Azure Stack Hub 约定,Azure 资源管理器终结点名称的格式为 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” ,则资源管理器终结点为 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 进行调用的用户的订阅 ID。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 这是可选参数,它有两个截然不同的可能值:dailyhourlyOptional 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. 默认值为 daily 选项。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 使用情况聚合的唯一 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:更多关于所消耗资源的详细信息(例如 OS 版本或映像类型)。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 所消耗资源的唯一 ID(也称 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 市场中运行,请部署一个 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