使用本地用量计量分析 Azure Stack 使用情况Analyze Azure Stack usage with local usage meters

有关哪些订阅使用哪些资源存储在本地使用情况数据库中的信息。Information about which subscriptions use which resources is stored in a local usage database. 管理员可以检索此数据以分析哪些用户正在使用资源。Administrators can retrieve this data to analyze which users are consuming resources.

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 环境的 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}.
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 用户的订阅标识符。Subscription identifier of the Azure Stack 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 所消耗资源的唯一 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 市场中运行,请部署一个 VM,并验证“VM 监视”边栏选项卡以确保它正在运行。If you're not sure whether you have any resources running in the Azure Stack 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 安装 PowerShellInstall PowerShell for Azure Stack.

  2. 配置 Azure Stack 用户Azure Stack 操作员 PowerShell 环境。Configure the Azure Stack user or the Azure Stack 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