您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:通过成本分析了解和分析成本Quickstart: Explore and analyze costs with cost analysis

需要知道你组织中哪些方面产生了成本,然后才能正确地控制和优化 Azure 成本。Before you can properly control and optimize your Azure costs, you need to understand where costs originated within your organization. 这还有助于了解服务的成本及其支持的环境和系统。It's also useful to know how much money your services cost, and in support of which environments and systems. 要准确地了解组织的支出模式,必须了解成本的方方面面。Visibility into the full spectrum of costs is critical to accurately understand organizational spending patterns. 可在强制实施成本控制机制(如预算)时使用支出模式。You can use spending patterns to enforce cost control mechanisms, like budgets.

在本快速入门中,你将通过成本分析了解和分析组织成本。In this quickstart, you use cost analysis to explore and analyze your organizational costs. 可以按组织查看合计成本,了解哪些方面持续产生成本并确定支出趋势。You can view aggregated costs by organization to understand where costs occur over time and identify spending trends. 可以查看一段时间的累计成本,根据预算预估每月、每季度甚至每年的成本趋势。You can view accumulated costs over time to estimate monthly, quarterly, or even yearly cost trends against a budget. 预算可帮助你遵守财务约束。A budget helps to provide adherence to financial constraints. 并且预算用于查看每日或每月成本,以隔离异常支出行为。And a budget is used to view daily or monthly costs to isolate spending irregularities. 你还可下载当前报表的数据进行深入分析或在外部系统中使用。And, you can download the current report's data for further analysis or to use in an external system.

此快速入门介绍如何:In this quickstart, you learn how to:

  • 通过成本分析查看成本Review costs in cost analysis
  • 自定义成本视图Customize cost views
  • 下载成本分析数据Download cost analysis data

先决条件Prerequisites

成本分析支持各种 Azure 帐户类型。Cost analysis supports different kinds of Azure account types. 若要查看支持的帐户类型的完整列表,请参阅了解成本管理数据To view the full list of supported account types, see Understand Cost Management data. 若要查看成本数据,你至少需要对 Azure 帐户具有读取访问权限。To view cost data, you need at least read access for your Azure account.

若要了解如何分配对 Azure 成本管理数据的访问权限,请参阅分配对数据的访问权限For information about assigning access to Azure Cost Management data, see Assign access to data.

登录 AzureSign in to Azure

通过成本分析查看成本Review costs in cost analysis

若要通过成本分析查看成本,请在 Azure 门户打开范围并在菜单中选择“成本分析” 。To review your costs in cost analysis, open the scope in the Azure portal and select Cost analysis in the menu. 例如,转到“订阅”,从列表中选择订阅,然后在菜单中选择“成本分析” 。For example, go to Subscriptions, select a subscription from the list, and then select Cost analysis in the menu. 使用“范围” 框可在成本分析中切换到不同的范围。Use the Scope pill to switch to a different scope in cost analysis. 有关范围的详细信息,请参阅了解并使用范围For more information about scopes, see Understand and work with scopes.

所选的范围将用于整个成本管理,以提供数据整合和控制对成本信息的访问。The scope you select is used throughout Cost Management to provide data consolidation and control access to cost information. 使用范围时,不要多选它们。When you use scopes, you don't multi-select them. 而应先选择一个汇总了其他范围的较大范围,然后筛选出所需的嵌套范围。Instead, you select a larger scope, which others roll up to, and then filter down to the nested scopes you need. 了解此方法很重要,因为某些用户可能无法访问单个涵盖多个嵌套范围的父范围。This approach is important to understand because some people may not have access to a single parent scope, which covers multiple nested scopes.

初始成本分析视图包括以下方面。The initial cost analysis view includes the following areas.

累计成本视图:表示预定义的成本分析视图配置。Accumulated cost view: Represents the predefined cost analysis view configuration. 每个视图包含日期范围、粒度、分组依据和筛选器设置。Each view includes date range, granularity, group by, and filter settings. 默认视图显示当前计费周期的聚合成本,但可以更改为其他内置视图。The default view shows accumulated costs for the current billing period, but you can change to other built-in views. 有关详细信息,请参阅自定义成本视图For more information, see Customize cost views.

实际成本:显示当前月份的总使用量和购买成本。这些购买成本是应记成本,会显示在账单上。Actual cost: Shows the total usage and purchase costs for the current month, as they're accrued and will show on your bill.

预测:显示所选时间段的预测成本总计。Forecast: Shows the total forecasted costs for time period you choose. (预测为预览版。)(Forecast is in preview.)

预算:显示所选范围的计划支出限额(如可用)。Budget: Shows the planned spending limit for the selected scope, if available.

累计粒度:显示从计费周期开始算起的累计每日成本总额。Accumulated granularity: Shows the total aggregate daily costs, from the beginning of the billing period. 为计费帐户或订阅创建预算后,可快速查看对预算而言的支出趋势。After you create a budget for your billing account or subscription, you can quickly see your spending trend against the budget. 将鼠标悬停某个日期上以查看该天的累计成本。Hover over a date to view the accumulated cost for that day.

透视图(圆环图) :提供动态透视,按一组常见标准属性分解总成本。Pivot (donut) charts: Provide dynamic pivots, breaking down the total cost by a common set of standard properties. 它们显示当前月成本(从最大到最小排列)。They show the largest to smallest costs for the current month. 通过选择不同的透视,可以随时更改透视图。You can change pivot charts at any time by selecting a different pivot. 成本按服务(计量类别)、位置(区域)和子范围(默认)分类。Costs are categorized by service (meter category), location (region), and child scope by default. 例如,注册帐户在计费帐户之下,资源组在订阅之下,资源在资源组之下。For example, enrollment accounts are under billing accounts, resource groups are under subscriptions, and resources are under resource groups.

Azure 门户中成本分析的初始视图

自定义成本视图Customize cost views

成本分析有四个内置视图,这些视图已针对最常见的目标进行优化:Cost analysis has four built-in views, optimized for the most common goals:

查看View 回答各种问题,例如Answer questions like
累计成本Accumulated cost 这个月目前的支出是多少?How much have I spent so far this month? 在预算范围内吗?Will I stay within my budget?
每日成本Daily cost 过去 30 天的每日成本是否有增加?Have there been any increases in the costs per day for the last 30 days?
按服务划分的成本Cost by service 过去 3 张发票的每月使用情况是否有变化?How has my monthly usage vary over the past three invoices?
按资源划分的成本Cost by resource 从这个月目前的情况来看,哪些资源的成本最高?Which resources cost the most so far this month?

视图选择器,显示本月的示例选择

但是,在很多情况下需要更深入的分析。However, there are many cases where you need deeper analysis. 在页面顶部通过数据选择进行自定义。Customization starts at the top of the page, with the date selection.

默认情况下,成本分析显示当前月份的数据。Cost analysis shows data for the current month by default. 使用日期选择器,快速切换到常用的日期范围。Use the date selector to switch to common date ranges quickly. 例如:过去七天、上个月、本年度或自定义日期范围。Examples include the last seven days, the last month, the current year, or a custom date range. 即用即付订阅还包括基于计费周期的日期范围,该周期并未与日历月绑定,例如当前的计费周期或上一张发票。Pay-as-you-go subscriptions also include date ranges based on your billing period, which isn't bound to the calendar month, like the current billing period or last invoice. 使用菜单顶部的 <上一周期下一周期> 链接分别跳至上一周期或下一周期。Use the <PREVIOUS and NEXT> links at the top of the menu to jump to the previous or next period, respectively. 例如,“<上一周期”会从“过去七天”切换到“8-14 天之前”,或切换到“15-21 天之前” 。For example, <PREVIOUS will switch from the Last 7 days to 8-14 days ago or 15-21 days ago.

显示本月示例选择的日期选择器

默认情况下,成本分析显示“累计”成本 。Cost analysis shows accumulated costs by default. 累计成本显示包括前几天在内的每日费用总额,显示每日应计成本不断变化的情况。Accumulated costs include all costs for each day plus the previous days, for a constantly growing view of your daily aggregate costs. 此视图已进行优化,可显示对预算而言所选日期范围的支出趋势。This view is optimized to show how you're trending against a budget for the selected time range.

使用预测图表视图时,可以确定潜在的预算违规情况。Use the forecast chart view to identify potential budget breaches. 如果有可能的预算违规情况,则会以红色显示预计的超支。When there's a potential budget breach, projected overspending is shown in red. 另外还会在图表中显示一个指示符。An indicator symbol is also shown in the chart. 将鼠标悬停在该符号上会显示估计的预算违规日期。Hovering over the symbol shows the estimated date of the budget breach.

一个示例,显示潜在的预算违规

此外,还有每日 视图显示每日成本。There's also the daily view showing costs for each day. 每日视图不会显示增长趋势。The daily view doesn't show a growth trend. 该视图旨在显示异常,如每日的成本峰值或 dip。The view is designed to show irregularities as cost spikes or dips from day to day. 如果选择了预算,则每日视图还会显示每日预算的估算值。If you've selected a budget, the daily view also shows an estimate of your daily budget.

如果每日成本不断高于估算的每日预算,可能会超出每月预算。When your daily costs are consistently above the estimated daily budget, you can expect you'll surpass your monthly budget. 估算的每日预算是一种可在较浅显的层面上帮助你直观查看预算的方式。The estimated daily budget is a means to help you visualize your budget at a lower level. 如果每日成本出现波动,则与每月预算比较,估算的每日预算不太准确。When you have fluctuations in daily costs, then the estimated daily budget comparison to your monthly budget is less precise.

下面是一个已启用支出预测功能的每日视图,显示了最近的支出。Here's a daily view of recent spending with spending forecast turned on. 显示当月的示例性每日成本的每日视图Daily view showing example daily costs for the current month

关闭支出预测功能以后,会看不到将来日期的预计支出。When turn off the spending forecast, you don't see projected spending for future dates. 另外,当你查看过去时间段的成本时,成本预测不显示成本。Also, when you look at costs for past time periods, cost forecast doesn't show costs.

通常情况下,有望在 8 到 12 小时内看到所用资源的数据或者通知。Generally, you can expect to see data or notifications for consumed resources within 8 to 12 hours.

“分组依据”通用属性,用于细分成本并确定排名靠前的贡献因素。Group by common properties to break down costs and identify top contributors. 例如,若要按资源标记分组,请选择要按其分组的标记键。To group by resource tags, for example, select the tag key you want to group by. 成本按每个标记值进行细分,并且有一个额外的段,用于未应用该标记的资源。Costs are broken down by each tag value, with an extra segment for resources that don't have that tag applied.

大部分Azure 资源都支持标记Most Azure resources support tagging. 但某些标记在“成本管理”和“计费”中不可用。However, some tags aren't available in Cost Management and billing. 此外,不支持资源组标记。Additionally, resource group tags aren't supported. 成本管理仅自标记直接应用到资源之日起支持资源标记。Cost Management only supports resource tags from the date the tags are applied directly to the resource. 观看 How to review tag policies with Azure Cost Management(如何通过 Azure 成本管理查看标记策略)视频,了解如何使用 Azure 标记策略来改进成本数据可见性。Watch the How to review tag policies with Azure Cost Management video to learn about using Azure tag policy to improve cost data visibility.

下面是当前月份的 Azure 服务成本视图。Here's a view of Azure service costs for the current month.

显示上个月示例 Azure 服务成本的分组的每日汇总视图

默认情况下,成本分析会显示所有使用情况和应记购买成本(也称“实际成本”),并会将其显示在发票上。 By default, cost analysis shows all usage and purchase costs as they are accrued and will show on your invoice, also known as Actual cost. 查看实际成本适用于发票对帐。Viewing actual cost is ideal for reconciling your invoice. 但是,在观察成本中的支出异常和其他变化时,需警觉成本中的购买峰值。However, purchase spikes in cost can be alarming when you're keeping an eye out for spending anomalies and other changes in cost. 若要抹平因预留购买成本导致的峰值,请切换到“摊销成本”。 To flatten out spikes caused by reservation purchase costs, switch to Amortized cost.

在实际成本和摊销成本之间进行切换即可看到整个期间的预留购买,以及分配给那些使用了预留的资源的预留购买

摊销成本会将预留购买细分成每日区块,将其平摊到整个预留期间。Amortized cost breaks down reservation purchases into daily chunks and spreads them over the duration of the reservation term. 例如,你会看到从 1 月 1 日到 12 月 31 日这段时间每天都有一个 1 美元的购买项,而不是在 1 月 1 日有一个 365 美元的购买项。For example, instead of seeing a $365 purchase on January 1, you'll see a $1 purchase every day from January 1 to December 31. 除了基本摊销,系统还会将这些成本重新分配并与使用了预留的特定资源相关联。In addition to basic amortization, these costs are also reallocated and associated by using the specific resources that used the reservation. 例如,如果将那个 1 美元的每日费用分摊到两个虚拟机,则会看到该日有两个 0.50 美元的费用。For example, if that $1 daily charge was split between two virtual machines, you'd see two $0.50 charges for the day. 如果该日的部分预留未使用,则会看到一个与相应的虚拟机关联的 0.50 美元费用,以及另一个费用类型为 UnusedReservation 的 0.50 美元费用。If part of the reservation isn't utilized for the day, you'd see one $0.50 charge associated with the applicable virtual machine and another $0.50 charge with a charge type of UnusedReservation. 请注意,未使用的预留成本只能在查看摊销成本时看到。Note that unused reservation costs can be seen only when viewing amortized cost.

必须指出,由于成本表示方式的变化,实际成本和摊销成本视图会显示不同的总计数字。Due to the change in how costs are represented, it's important to note that actual cost and amortized cost views will show different total numbers. 通常情况下,在查看摊销成本时,有预留购买的月份的总成本会下降,而预留购买之后的月份的总成本会上升。In general, the total cost of months with a reservation purchase will decrease when viewing amortized costs, and months following a reservation purchase will increase. 目前,摊销仅适用于预留购买,不适用于 Azure 市场购买。Amortization is available only for reservation purchases and doesn't apply to Azure Marketplace purchases at this time.

下图显示了资源组名称。The following image shows resource group names. 可以按标记分组,以便按标记查看总成本;也可以使用“按资源分类的成本”视图,查看特定资源的所有标记的总成本。 You can group by tag to view total costs per tag or use the Cost by resource view to see all tags for a particular resource.

显示资源组名称的当前视图的完整数据

当按特定的属性对成本进行分组时,将按从最高到最低的顺序显示排名前 10 的成本贡献因素。When you're grouping costs by a specific attribute, the top 10 cost contributors are shown from highest to lowest. 如果成本贡献因素超过 10 个,则会显示排名前九的成本贡献因素和一个“其他” 组,该组表示合并的所有剩余组。If there are more than 10, the top nine cost contributors are shown with an Others group that represents all remaining groups combined. 按标记分组时,将显示“无标记”组,用于表示未应用标记键的成本 。When you're grouping by tags, an Untagged group appears for costs that don't have the tag key applied. 非标记总是位于最后,即使非标记成本高于标记成本。Untagged is always last, even if untagged costs are higher than tagged costs. 如果存在 10 个或更多个标记值,则非标记成本将会列在“其他”中。 Untagged costs will be part of Others, if 10 or more tag values exist. 切换到表视图并将粒度更改为“无” ,以查看成本从最高到最低排名的所有值。Switch to the table view and change granularity to None to see all values ranked from highest to lowest cost.

经典虚拟机、网络和存储资源不共享详细的计费数据。Classic virtual machines, networking, and storage resources don't share detailed billing data. 当对成本进行分组时,它们合并为经典服务They're merged as Classic services when grouping costs.

主图下的透视图显示了不同的分组,让你在更大范围内了解所选时段和筛选器对应的总体成本。Pivot charts under the main chart show different groupings, which give you a broader picture of your overall costs for the selected time period and filters. 选择一个属性或标记即可按任意维度查看聚合的成本。Select a property or tag to view aggregated costs by any dimension.

显示透视图的示例

你可以查看任何视图的完整数据集。You can view the full dataset for any view. 你应用的选择或筛选器会影响所显示的数据。Whichever selections or filters that you apply affect the data presented. 若要查看完整的数据集,请选择“图表类型” 列表,然后选择“表” 视图。To see the full dataset, select the chart type list and then select Table view.

表视图中的当前视图的数据

了解分组和筛选选项Understanding grouping and filtering options

下表列出了一些最常见的分组和筛选选项以及使用它们的时机。The following table lists some of the most common grouping and filtering options and when you should use them.

属性Property 使用时机When to use
计费周期Billing period 按发票月份细分成本。Break down costs by invoice month. 该选项对于未绑定到日历月份的即用即付和开发/测试订阅很重要。This option is important for pay-as-you-go and development/test subscriptions, which aren't bound to calendar months. EA/MCA 帐户可以使用日期选取器中的日历月份或每月粒度来完成同一目标。EA/MCA accounts can use calendar months in the date picker or monthly granularity to accomplish the same goal.
费用类型Charge type 细分使用量、购买、退款和未使用预留成本。Break down usage, purchase, refund, and unused reservation costs. 只有在使用操作成本而不使用摊销成本时,预留购买和退款才适用。Reservation purchases and refunds are available only when using action costs and not when using amortized costs. 只有在查看摊销成本时,未使用预留成本才适用。Unused reservation costs are available only when looking at amortized costs.
Cloud 按 AWS 和 Azure 细分成本。Break down costs by AWS and Azure. 仅管理组、外部计费帐户和外部订阅提供 AWS 成本。AWS costs are available only from management groups, external billing accounts, and external subscriptions.
部门 / 发票部分Department / Invoice section 按 EA 部门或 MCA 发票部分细分成本。Break down costs by EA department or MCA invoice section. 此选项仅适用于 EA/MCA 计费帐户和 MCA 计费对象信息。This option is available only for EA/MCA billing accounts and MCA billing profiles.
注册帐户Enrollment account 按 EA 帐户所有者细分成本。Break down costs by EA account owner. 此选项仅适用于 EA 计费帐户和部门。This option is available only for EA billing accounts and departments.
频率Frequency 细分基于使用情况的一次性定期成本。Break down usage-based, one-time, and recurring costs.
计量Meter 按 Azure 使用情况计量细分成本。Break down costs by Azure usage meter. 此选项仅适用于 Azure 使用情况。This option is available only for Azure usage. 所有购买和 Azure 市场使用情况都会显示为“未指定”或“未分配” 。All purchases and Marketplace usage will show as Not specified or unassigned.
发布者类型Publisher type 细分 AWS、Azure 和 Azure 市场成本。Break down AWS, Azure, and Marketplace costs.
预留Reservation 按预留细分成本。Break down costs by reservation. 任何不包含预留的使用情况都会显示为“未指定” 。Any usage that doesn't include a reservation will show as Not specified.
资源Resource 按资源细分成本。Break down costs by resource. 所有购买都会显示为“未指定”,因为它们是在 EA/PAYG 计费帐户或 MCA 计费对象信息级别应用的 。All purchases will show as Not specified, because they're applied at an EA/PAYG billing account or MCA billing profile level.
资源组Resource group 按资源组细分成本。Break down costs by resource group. 此选项仅适用于非经典使用情况。This option is available only for non-classic usage. 经典资源使用情况会显示为“其他”,购买会显示为“未指定” 。Classic resource usage will show as other, and purchases will show as Not specified.
资源类型Resource type 按资源类型细分成本。Break down costs by resource type. 此选项仅适用于非经典使用情况。This option is available only for non-classic usage. 经典资源使用情况会显示为“其他”,购买会显示为“未指定” 。Classic resource usage will show as other, and purchases will show as Not specified.
服务名称计量类别Service name or Meter category 按 Azure 服务细分成本。Break down cost by Azure service. 此选项仅适用于 Azure 使用情况。This option is available only for Azure usage. 所有购买和 Azure 市场使用情况都会显示为“未指定”或“未分配” 。All purchases and Marketplace usage will show as Not specified or unassigned.
服务层级计量子类别Service tier or Meter subcategory 按 Azure 使用情况计量子分类细分成本。Break down cost by Azure usage meter subclassification. 此选项仅适用于 Azure 使用情况。This option is available only for Azure usage. 所有购买和 Azure 市场使用情况都会显示为“未指定”或“未分配” 。All purchases and Marketplace usage will show as Not specified or unassigned.
订阅Subscription 按订阅细分成本。Break down costs by subscription. 所有购买都会显示为“未指定” 。All purchases show as Not specified.
标记Tag 按特定标记键的标记值细分成本。Break down costs by tag values for a specific tag key.

有关术语的详细信息,请参阅了解在 Azure 使用情况和费用文件中使用的术语For more information about terms, see Understand the terms used in the Azure usage and charges file.

保存和共享自定义视图Saving and sharing customized views

保存自定义视图并将其与他人共享,方法是将成本分析固定到 Azure 门户仪表板或复制成本分析的链接。Save and share customized views with others by pinning cost analysis to the Azure portal dashboard or by copying a link to cost analysis.

若要固定成本分析,请选择右上角的图钉图标。To pin cost analysis, select the pin icon in the upper-right corner. 固定成本分析只会保存主图表或表视图。Pinning cost analysis will save only the main chart or table view. 共享仪表板,允许他人访问此磁贴。Share the dashboard to give others access to the tile. 请注意,这只共享仪表板配置,并不授予他人访问基础数据的权限。Note that this shares only the dashboard configuration and doesn't grant others access to the underlying data. 如果你没有成本访问权限但有共享仪表板的访问权限,将会看到“拒绝访问”消息。If you don't have access to costs but do have access to a shared dashboard, you'll see an "access denied" message.

若要共享成本分析链接,请选择边栏选项卡顶部的“共享” 。To share a link to cost analysis, select Share at the top of the blade. 随即会显示一个自定义 URL,单击此 URL 会打开针对此特定范围的特定视图。A custom URL will show, which opens this specific view for this specific scope. 如果你没有成本访问权限也没有获取此 URL,你将看到“拒绝访问”消息。If you don't have cost access and get this URL, you'll see an "access denied" message.

若要详细了解如何针对每个受支持的范围授予成本访问权限,请参阅了解并使用范围To learn more about granting access to costs for each supported scope, review Understand and work with scopes.

自动化和脱机分析Automation and offline analysis

有时候,需要下载数据进行进一步的分析、将其与你自己的数据合并,或者将其集成到你自己的系统中。There are times when you need to download the data for further analysis, merge it with your own data, or integrate it into your own systems. 成本管理提供一些不同选项。Cost Management offers a few different options. 如果需要临时高级摘要(例如成本分析中的内容),请首先生成所需的视图。As a starting point, if you need an ad hoc high-level summary, like what you get within cost analysis, build the view you need. 然后通过依次选择“导出”和“将数据下载到 CSV”或“将数据下载到 Excel”进行下载 。Then download it by selecting Export and selecting Download data to CSV or Download data to Excel. Excel 下载提供用于生成下载的视图的其他上下文,例如范围、查询配置、总计以及生成日期。The Excel download provides additional context on the view you used to generate the download, like scope, query configuration, total, and date generated.

如果需要完整的非聚合数据集,请从计费帐户下载。If you need the full, unaggregated dataset, download it from the billing account. 然后从门户左侧导航窗格中的服务列表中转到“成本管理 + 计费” 。Then, from the list of services in the portal's left navigation pane, go to Cost Management + Billing. 如果适用,请选择你的计费帐户。Select your billing account, if applicable. 转到“使用情况 + 费用”,然后选择所需计费周期的“下载”图标 。Go to Usage + charges, and then select the Download icon for the desired billing period.

采用类似的方法自动接收成本数据。Take a similar approach to automate receiving cost data. 使用查询 API 进行较丰富的分析,包括动态筛选、分组和聚合,或者使用 UsageDetails API 获取完整的非聚合数据集。Use the Query API for richer analysis with dynamic filtering, grouping, and aggregation, or use the UsageDetails API for the full, unaggregated dataset. 这些 API 的正式发布版 (GA) 是 2019-01-01。The general availability (GA) version of these APIs is 2019-01-01. 使用 2019-04-01-preview 可以在这些 API 中访问预览版预留和 Azure 市场购买。Use 2019-04-01-preview to get access to the preview of reservation and Marketplace purchases within these APIs.

例如,以下是一个按费用类型(使用情况、购买或退款)、发布者类型(Azure 或 Azure 市场)、资源组(如果是购买,则此项为空)和预留(如果不适用,则此项为空)细分的摊销成本的聚合视图。For example, following is an aggregated view of amortized costs broken down by charge type (usage, purchase, or refund), publisher type (Azure or Marketplace), resource group (empty for purchases), and reservation (empty if not applicable).

POST https://management.azure.com/{scope}/providers/Microsoft.CostManagement/query?api-version=2019-04-01-preview
Content-Type: application/json

{
  "type": "AmortizedCost",
  "timeframe": "Custom",
  "timePeriod": { "from": "2019-04-01", "to": "2019-04-30" },
  "dataset": {
    "granularity": "None",
    "aggregation": {
      "totalCost": { "name": "PreTaxCost", "function": "Sum" }
    },
    "grouping": [
      { "type": "dimension", "name": "ChargeType" },
      { "type": "dimension", "name": "PublisherType" },
      { "type": "dimension", "name": "Frequency" },
      { "type": "dimension", "name": "ResourceGroup" },
      { "type": "dimension", "name": "SubscriptionName" },
      { "type": "dimension", "name": "SubscriptionId" },
      { "type": "dimension", "name": "ReservationName" },
      { "type": "dimension", "name": "ReservationId" },
    ]
  },
}

如果不需聚合而首选完整的原始数据集,则请执行以下操作:And if you don't need the aggregation and prefer the full, raw dataset:

GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?metric=AmortizedCost&$filter=properties/usageStart+ge+'2019-04-01'+AND+properties/usageEnd+le+'2019-04-30'&api-version=2019-04-01-preview

如果需要实际成本,以便将购买显示为应记项,则请将 type/metric 更改为 ActualCostIf you need actual costs to show purchases as they are accrued, change type/metric to ActualCost. 有关这些 API 的详细信息,请参阅查询UsageDetails API 文档。For more information about these APIs, see the Query and UsageDetails API documentation. 请注意,这两个已发布的文档均适用于 GA 版本。Note that the published docs are for the GA version. 但也适用于新的 type/metric 特性和已更改属性名称范围之外的“2019-04-01-preview”API 版本 。However, they both work the same for the 2019-04-01-preview API version outside of the new type/metric attribute and changed property names. (阅读下面有关属性名称的更多内容。)(Read more about the property names below.)

成本管理 API 可跨资源的所有范围:通过 Azure RBAC 访问权限获取的资源组、订阅和管理组,通过 EA 门户访问权限获取的 EA 计费帐户(注册)、部门和注册帐户。Cost Management APIs work across all scopes above resources: resource group, subscription, and management group via Azure RBAC access, EA billing accounts (enrollments), departments, and enrollment accounts via EA portal access. 有关详细信息,包括如何确定范围 ID 或者如何管理访问权限,请参阅了解并使用范围Learn more about scopes, including how to determine your scope ID or manage access, in Understand and work with scopes.

后续步骤Next steps

转到第一个教程,了解如何创建并管理预算。Advance to the first tutorial to learn how to create and manage budgets.