提供商资源使用情况 APIProvider resource usage API

“提供者” 一词适用于服务管理员和任何委派的提供者。The term provider applies to the service administrator and to any delegated providers. Azure Stack 操作员和委派的提供者可使用提供者使用情况 API,查看其直接租户的使用情况。Azure Stack 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 diagram, P0 can call the provider API to get usage information on P1's and P2's direct usage, 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 is 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}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
armendpointarmendpoint Azure Stack 环境的 Azure 资源管理器终结点。Azure Resource Manager endpoint of your Azure Stack environment. 按 Azure Stack 约定,Azure 资源管理器终结点名称的格式为 https://adminmanagement.{domain-name}The Azure Stack convention is that the name of the Azure Resource Manager endpoint is in the format https://adminmanagement.{domain-name}. 例如,对于开发工具包,如果域名为 local.azurestack.external,则资源管理器终结点是 https://adminmanagement.local.azurestack.externalFor example, for the development kit, if the domain name is local.azurestack.external, then the Resource Manager endpoint is https://adminmanagement.local.azurestack.external.
subIdsubId 进行调用的用户的订阅 ID。Subscription ID of the user who makes the call.
reportedStartTimereportedStartTime 查询的开始时间。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。The format is escaped ISO 8601. 例如,2015-06-16T18%3a53%3a11%2b00%3a00Z,其中冒号会转义为 %3a,而加号会转义为 %2b,使其符合 URI 规范。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.
reportedEndTimereportedEndTime 查询的结束时间。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 in the future or the current date. 如果是,结果会设为“处理未完成”。If it is, the result is set to "processing not complete."
aggregationGranularityaggregationGranularity 这是可选参数,它有两个截然不同的可能值:daily 和 hourly。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.
subscriberIdsubscriberId 订阅 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-versionapi-version 用于发出此请求的协议版本。Version of the protocol that's used to make this request. 此值设置为 2015-06-01-previewThis value is set to 2015-06-01-preview.
continuationTokencontinuationToken 从上次调用使用情况 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 and it acts as a bookmark for the progress. 若无此标记,则会从一天或小时开始时的时间检索数据,取决于所传入的粒度。If the token is not 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.0GET /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
idid 使用情况聚合的唯一 ID。Unique ID of the usage aggregate.
namename 使用情况聚合的名称。Name of the usage aggregate.
typetype 资源定义。Resource definition.
subscriptionIdsubscriptionId Azure Stack 用户的订阅标识符。Subscription identifier of the Azure Stack user.
usageStartTimeusageStartTime 此使用情况聚合所属的使用情况存储桶 UTC 开始时间。UTC start time of the usage bucket to which this usage aggregate belongs.
usageEndTimeusageEndTime 此使用情况聚合所属的使用情况存储桶 UTC 结束时间。UTC end time of the usage bucket to which this usage aggregate belongs.
instanceDatainstanceData 实例详细信息的键/值对(采用新格式):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.
quantityquantity 此时间范围内发生的资源消耗数量。Amount of resource consumption that occurred in this time frame.
meterIdmeterId 所消耗资源的唯一 ID(也称为 ResourceID)。Unique ID for the resource that was consumed (also called ResourceID).

检索使用情况信息Retrieve usage information

PowerShellPowerShell

若要生成使用情况数据,你应当有正在运行且在主动使用系统的资源,例如,活动虚拟机或包含某些数据的存储帐户,等等。如果不确定你是否有任何资源在 Azure Stack 市场中运行,请部署一个虚拟机 (VM),并验证 VM 监视边栏选项卡以确保它正在运行。To generate the usage data, you should have resources that are running and actively using the system, For example, an active virtual machine, or a storage account containing some data etc. If you're not sure whether you have any resources running in Azure Stack Marketplace, deploy a virtual machine (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 的 PowerShell。Install PowerShell for Azure Stack.
  2. 配置 Azure Stack 用户的Azure Stack 操作员的 PowerShell 环境Configure the Azure Stack user's or the Azure Stack operator's PowerShell environment
  3. 若要检索使用情况数据,请使用 Get-UsageAggregates PowerShell cmdlet:To retrieve the usage data, use the Get-UsageAggregates PowerShell cmdlet:
    Get-UsageAggregates -ReportedStartTime "<Start time for usage reporting>" -ReportedEndTime "<end time for usage reporting>" -AggregationGranularity <Hourly or Daily>
    

REST APIREST API

可以通过调用 Microsoft.Commerce.Admin 服务来收集已删除订阅的使用信息。You can collect usage information for deleted subscriptions by calling the Microsoft.Commerce.Admin service.

若要为活动用户返回已删除的所有租户使用情况:To 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-previewhttps://{armendpoint}/subscriptions/{subId}/providersMicrosoft.Commerce.Admin/subscriberUsageAggregates?reportedStartTime={start-time}&reportedEndTime={end-endtime}&aggregationGranularity=Hourly&api-version=2015-06-01-preview

若要返回已删除或活动租户的使用情况:To return the 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-previewhttps://{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

租户资源使用情况 API 参考Tenant resource usage API reference

有关使用情况的常见问题解答Usage-related FAQ