Azure:资源使用 API 问题

Azure : Resource usage API issue

我尝试提取 Azure 资源使用数据以获取计费指标。我按照博客中提到的步骤获取了资源的使用数据。

https://msdn.microsoft.com/en-us/library/azure/mt219001.aspx

即使我在URL中设置了"start and endtime"参数,它也不会生效。它 return 的整个输出 [ 来自资源 created/added 时间 ]。

例如: https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Commerce/UsageAggregates?api-version=2015-06-01-preview&reportedStartTime=2017-03-03T00%3a00%3a00%2b00%3a00&reportedEndTime=2017-03-04T00%3a00%3a00%2b00%3a00&aggregationGranularity=Hourly&showDetails=true"

按照上面的URL,应该是return“2017-03-03到2017-03-04”之间的数据。但它显示了 3 月 2 日 [2017-03-02] 的数据。不知道为什么 return 整个输出和时间过滤器部分不起作用。

注意:结束时间参数值生效,表示它显示输出直到结束时间中提到的。但是没有考虑开始时间。

任何人对此有建议。

所以有几点需要考虑:

  • usage date/time,然后有reported date/time。 前者告诉您 date/time 何时使用资源,而 后者告诉您 date/time 收到此信息的时间 计费子系统。时间会有一些延迟 使用的资源与报告时间的对比。从这个 link:

Set {dateTimeOffset-value} for reportedStartTime and reportedEndTime to valid dateTime values. Please note that this dateTimeOffset value represents the timestamp at which the resource usage was recorded within the Azure billing system. As Azure is a distributed system, spanning across 19 datacenters around the world, there is bound to be a delay between the resource usage time (when the resource was actually consumed) and the resource usage reported time (when the usage event reached the billing system) and callers need a predictable way to get all usage events for a subscription for a given time period.

  • 该查询只允许您搜索已报告的 date/time,没有提供使用 date/time。但是,返回给您的数据包含使用情况 date/time 而不是报告的 date/time.

长话短说,由于将使用信息传播到计费子系统的延迟,您看到的行为是正确的。根据我的经验,所有使用信息大约需要 24 小时才能显示在计费子系统中。

我们在应用程序中处理这种情况的方式是,我们获取数据的时间更长,然后仅获取我们感兴趣的数据。因此,例如,如果我需要查看 3 月 1 日的数据,那么我们查询从 3 月 1 日到 3 月 4 日(即今天的日期)报告的 date/time 的数据,然后丢弃使用日期不是 1 日的所有数据三月。

如果我们没有找到任何数据(这很可能发生在您的情况下),我们只是告诉用户使用信息尚不可用。