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

Cloud Cruiser 和 Microsoft Azure 计费 API 集成Cloud Cruiser and Microsoft Azure Billing API Integration

本文介绍如何在 Cloud Cruiser 中使用从新的 Microsoft Azure 计费 API 中收集到的信息,以进行工作流成本模拟和分析。This article describes how the information collected from the new Microsoft Azure Billing APIs can be used in Cloud Cruiser for workflow cost simulation and analysis.

Azure RateCard APIAzure RateCard API

RateCard API 提供来自 Azure 的费率信息。The RateCard API provides rate information from Azure. 在使用正确的凭据进行身份验证之后,可以查询此 API 以收集关于 Azure 上可用服务的元数据以及与套餐 ID 相关联的费率。After authenticating with the proper credentials, you can query the API to collect metadata about the services available on Azure, along with the rates associated with your Offer ID.

以下是来自该 API 的示例响应,显示了 A0 (Windows) 实例的价格:The following sample response is from the API showing the prices for the A0 (Windows) instance:

{
    "MeterId": "0e59ad56-03e5-4c3d-90d4-6670874d7e29",
    "MeterName": "Compute Hours",
    "MeterCategory": "Virtual Machines",
    "MeterSubCategory": "A0 VM (Windows)",
    "Unit": "Hours",
    "MeterRates":
    {
        "0": 0.029
    },
    "EffectiveDate": "2014-08-01T00:00:00Z",
    "IncludedQuantity": 0.0,
    "MeterStatus": "Active"
},

Cloud Cruiser 到 Azure RateCard API 的接口Cloud Cruiser’s Interface to Azure RateCard API

Cloud Cruiser 可以通过多种方式利用 RateCard API 信息。Cloud Cruiser can use the RateCard API information in different ways. 在本文中,我们将展示如何使用它来进行 IaaS 工作负荷成本模拟和分析。For this article, we show how it can be used to make IaaS workload cost simulation and analysis.

为了演示此用例,设想了一个在 Microsoft Azure Pack (WAP) 上运行的多个实例的工作负荷。To demonstrate this use case, imagine a workload of several instances running on Microsoft Azure Pack (WAP). 目标是在 Azure 上模拟同样的工作负荷以及估计执行此类迁移的成本。The goal is to simulate this same workload on Azure, and estimate the costs of doing such migration. 要创建此模拟,需要执行两项主要任务:In order to create this simulation, there are two main tasks to be performed:

  1. 导入并处理从 RateCard API 收集的服务信息。Import and process the service information collected from the RateCard API. 在工作簿上也执行该任务,对从 RateCard API 提取的信息进行转换并发布到新的费率计划。This task is also performed on the workbooks, where the extract from the RateCard API is transformed and published to a new rate plan. 使用此新的费率计划进行模拟以估计 Azure 价格。This new rate plan is used on the simulations to estimate the Azure prices.
  2. 规范化 IaaS 的 WAP 服务和 Azure 服务。Normalize WAP services and Azure services for IaaS. 默认情况下,WAP 服务是基于各个资源(CPU、内存大小、磁盘大小等)的,而 Azure 服务是基于实例大小(A0、A1、A2 等)的。By default, WAP services are based on individual resources (CPU, Memory Size, Disk Size, etc.) while Azure services are based on instance size (A0, A1, A2, etc.). 可以由 Cloud Cruiser ETL 引擎(称作工作簿)执行第一个任务,其中可以按照实例尺寸对这些资源进行捆绑,类似于 Azure 实例服务。This first task can be performed by Cloud Cruiser’s ETL engine, called workbooks, where these resources can be bundled on instance sizes, analogous to Azure instance services.

从 RateCard API 导入数据Import data from the RateCard API

Cloud Cruiser 工作簿提供自动化的方式来从 RateCard API 收集信息并进行处理。Cloud Cruiser workbooks provide an automated way to collect and process information from the RateCard API. ETL(提取-转换-加载)工作簿允许对数据的收集、转换以及发布到 Cloud Cruiser 数据库进行配置。ETL (extract-transform-load) workbooks allow you to configure the collection, transformation, and publishing of data into the Cloud Cruiser database.

每个工作簿可以有一个或多个集合,这样可以关联来自不同源的信息以补充或增加使用数据。Each workbook can have one or multiple collections, allowing you to correlate information from different sources to complement or augment the usage data. 以下两个屏幕截图显示了如何在现有工作簿中创建新的集合,以及如何将信息从 RateCard API 导入到集合:The following two screenshots show how to create a new collection in an existing workbook, and importing information into the collection from the RateCard API:

图 1 - 创建新集合Figure 1 - Creating a new collection

图 2 - 从新集合导入数据Figure 2 - Import data from the new collection

将数据导入工作簿后,则可以创建多个步骤和转换过程,以对数据进行修改和建模。After importing the data into the workbook, it’s possible to create multiple steps and transformation processes, to modify and model the data. 在此示例中,由于我们只对服务架构 (IaaS) 感兴趣,因此可以使用转换步骤来删除与 IaaS 服务无关的不必要的行或记录。For this example, since we are only interested in infrastructure-as-a-Service (IaaS) we can use the transformation steps to remove unnecessary rows, or records, related to services other than IaaS.

如下的屏幕快照显示了对从 RateCard API 收集到的数据进行处理的转换步骤:The following screenshot shows the transformation steps used to process the data collected from RateCard API:

图 3 - 对从 RateCard API 收集的数据进行处理的转换步骤Figure 3 - Transformation steps to process collected data from RateCard API

定义新的服务和费率计划Defining New Services and Rate Plans

有多种方法可以定义 Cloud Cruiser 上的服务。There are different ways to define services on Cloud Cruiser. 其中一种选择是从使用数据导入服务。One of the options is to import the services from the usage data. 在使用提供商已经定义了服务的公有云的情况下,通常使用此方法。This method is commonly used when working with public clouds, where the services are already defined by the provider.

费率计划包括一组费率或价格。基于生效日期、客户群或其他因素,不同的费率适用于不同的服务。A Rate Plan is a set of rates or prices that can be applied to different services, based on effective dates, or group of customers, among other options. 也可在 Cloud Cruiser 上使用费率计划以创建模拟或“假设”情况,从而了解服务变化如何影响工作负荷的总成本。Rate Plans can also be used on Cloud Cruiser to create simulation or “What-if” scenarios, to understand how changes in services can affect the total cost of a workload.

在此示例中,我们使用来自 RateCard API 的服务信息在 Cloud Cruiser 中定义新的服务。In this example, we use the service information from the RateCard API to define new services in Cloud Cruiser. 同样地,我们可以使用与服务相关联的费率在 Cloud Cruiser 上创建新的费率计划。In the same way, we can use the rates associated to the services to create a new Rate Plan on Cloud Cruiser.

在转换过程结束时,就可以创建一个新的步骤,并将来自 RateCard API 的数据作为新服务和费率进行发布。At the end of the transformation process, it is possible to create a new step and publish the data from the RateCard API as new services and rates.

图 4 - 将来自 RateCard API 的数据作为新的服务和费率进行发布Figure 4 - Publishing the data from the RateCard API as new Services and Rates

验证 Azure 服务和费率Verify Azure Services and Rates

发布服务和费率后,可在 Cloud Cruiser 的服务选项卡中验证导入的服务列表:After publishing the services and rates, you can verify the list of imported services in Cloud Cruiser’s Services tab:

图 5 - 验证新的服务Figure 5 - Verifying the new Services

在“费率计划”选项卡上,可查看名为“AzureSimulation”的新费率计划,其费率从 RateCard API 导入。On the Rate Plans tab, you can check the new rate plan called “AzureSimulation” with the rates imported from the RateCard API.

图 6 - 验证新的费率计划和关联的费率Figure 6 - Verifying the new Rate Plan and associated rates

规范化 WAP 和 Azure 服务Normalize WAP and Azure Services

默认情况下,WAP 提供基于计算、内存和网络资源的使用信息。By default, WAP provides usage information based on the use of compute, memory, and network resources. 在 Cloud Cruiser 中,可以直接根据这些资源的分配情况或计费使用情况来定义服务。In Cloud Cruiser, you can define your services based directly on the allocation or metered usage of these resources. 例如,可以对每小时的 CPU 使用率设置一个基本费率,或根据分配给实例的内存 GB 数进行收费。For example, you can set a basic rate for each hour of CPU usage, or charge the GB of memory allocated to an instance.

在此示例中,为了对 WAP 和 Azure 的成本进行比较,我们需要汇集 WAP 上的资源使用数据并进行捆绑,然后将其映射到 Azure 服务。For this example, in order to compare costs between WAP and Azure, we need to aggregate the resource usage on WAP into bundles, which can then be mapped to Azure services. 在工作簿中可以轻松地实现这种转换:This transformation can be implemented easily in the workbooks:

图 7 - 对 WAP 数据进行转换以规范化服务Figure 7 - Transforming WAP data to normalize services

该工作簿的最后一步是将数据发布到 Cloud Cruiser 数据库。The last step at the workbook is to publish the data into the Cloud Cruiser database. 在此步骤中,使用数据现在捆绑到服务(即映射到 Azure 服务)并与默认费率绑定以创建费用。During this step, the usage data is now bundled into services (that map to the Azure Services) and tied to default rates to create the charges.

完成该工作簿后,可通过以下方法实现数据的自动化处理:在计划程序中添加一个任务,并指定工作簿要运行的频率和时间。After finishing the workbook, you can automate the processing of the data, by adding a task on the scheduler and specifying the frequency and time for the workbook to run.

图 8 - 工作簿计划Figure 8 - Workbook scheduling

为工作负荷成本模拟分析创建报表Create Reports for Workload Cost Simulation Analysis

在收集了使用数据以及将费用加载到 Cloud Cruiser 数据库后,就可以利用 Cloud Cruiser Insights 模块来创建所需的工作负荷成本模拟。After the usage is collected and charges are loaded into the Cloud Cruiser database, we can use the Cloud Cruiser Insights module to create the workload cost simulation that we desire.

要演示此情况,我们将创建下列报表:In order to demonstrate this scenario, we created the following report:

成本比较Cost Comparison

上面的图表显示了按服务的成本比较,对各个具体服务在 WAP(深蓝色)和 Azure(浅蓝色)上运行工作负荷的价格进行了比较。The top graph shows a cost comparison by services, comparing the price of running the workload for each specific service between WAP (dark blue) and Azure (light blue).

下面的图表显示相同的数据,但是按部门进行细分。The bottom graph shows the same data but broken down by department. 每个部门在 WAP 和 Azure 中运行工作负荷的成本,并在 Savings 柱(绿色)中显示两者之间的成本差额。The costs for each department to run their workload on WAP and Azure, along with the difference between them is displayed in the Savings bar (green).

Azure 使用情况 APIAzure Usage API

介绍Introduction

Microsoft 最近推出了 Azure 使用情况 API,允许订户以编程方式提取使用数据以深入了解其使用情况。Microsoft recently introduced the Azure Usage API, allowing subscribers to programmatically pull in usage data to gain insights into their consumption. Cloud Cruiser 客户可以充分利用此 API 提供的更丰富数据集。Cloud Cruiser customers can take advantage of the richer dataset available through this API.

Cloud Cruiser 可以通过多种方式利用与使用情况 API 的集成。Cloud Cruiser can use the integration with the Usage API in several ways. 通过 API 可用的粒度(每小时使用情况信息)和资源元数据信息提供了支持灵活的 Showback 或 Chargeback 模型所必需的数据集。The granularity (hourly usage information) and resource metadata information available through the API provides the necessary dataset to support flexible Showback or Chargeback models.

在本教程中,我们通过一个示例来说明 Cloud Cruiser 如何从使用情况 API 信息中获益。In this tutorial, we present one example of how Cloud Cruiser can benefit from the Usage API information. 更具体地说,我们会在 Azure 上创建一个资源组,对帐户结构的标记进行关联,然后描述向 Cloud Cruiser 中提取和处理标记信息的过程。More specifically, we will create a Resource Group on Azure, associate tags for the account structure, then describe the process of pulling and processing the tag information into Cloud Cruiser.

最终目标是能够创建如下报表,并基于由标记填充的帐户结构对成本和消耗数据进行分析。The final goal is to be able to create reports like the following one, and be able to analyze cost and consumption based on the account structure populated by the tags.

图 10 - 使用标记的明细报表Figure 10 - Report with breakdowns using tags

Microsoft Azure 标记Microsoft Azure Tags

通过 Azure 使用情况 API 不仅可获得消耗信息,还可以获得资源元数据(包括与之相关联的任何标记)。The data available through the Azure Usage API includes not only consumption information, but also resource metadata including any tags associated with it. 标记提供了一种简单的方法来组织资源,但是,为了使其行之有效,需要确保:Tags provide an easy way to organize your resources, but in order to be effective, you need to ensure that:

  • 在预配时,将标记正确地应用到资源Tags are correctly applied to the resources at provision time
  • 在 Showback/Chargeback 过程中,正确地使用标记以将使用数据连接到组织的帐户结构。Tags are properly used on the Showback/Chargeback process to tie the usage to the organization’s account structure.

这两个要求都很具有挑战性,当预配或计费方面存在手动过程时尤其如此。Both of these requirements can be challenging, especially when there is a manual process on the provision or charging side. 存在输入错误、不正确的标记甚至缺少标记都是客户在使用标记时的常见抱怨,这些错误给计费方造成困难。Mistyped, incorrect, or even missing tags are common complaints from customers when using tags and these errors can make life on the charging side difficult.

使用新的 Azure 使用情况 API,Cloud Cruiser 可以提取资源标记信息,并通过名为工作簿的高级 ETL 工具修复这些常见的标记错误。With the new Azure Usage API, Cloud Cruiser can pull resource tagging information, and through a sophisticated ETL tool called workbooks, fix these common tagging errors. 通过利用正则表达式和数据关联的转换步骤,Cloud Cruiser 能够识别错误标记的资源并应用正确的标记,从而确保将资源与用户正确关联。Through transformation using regular expressions and data correlation, Cloud Cruiser can identify incorrectly tagged resources and apply the correct tags, ensuring the correct association of the resources with the consumer.

在计费方,Cloud Cruiser 自动化了 Showback/Chargeback 过程,而且可以利用标记信息将使用数据连接到相应的使用者(部门、区域、项目等)。On the charging side, Cloud Cruiser automates the Showback/Chargeback process, and can use the tag information to tie the usage to the appropriate consumer (Department, Division, Project, etc.). 这种自动化实现了一个巨大的改进,可以确保计费过程具有一致性且可审核。This automation provides a huge improvement and can ensure a consistent and auditable charging process.

在 Microsoft Azure 上创建具有标记的资源组Creating a Resource Group with tags on Microsoft Azure

本教程的第一步是在 Azure 门户中创建资源组,并创建与资源相关联的新标记。The first step in this tutorial is to create a Resource Group in the Azure portal, then create new tags to associate to the resources. 在此示例中,我们创建以下标记:部门、环境、所有者和项目。For this example, we be creating the following tags: Department, Environment, Owner, Project.

以下屏幕截图显示了具有关联标记的资源组示例。The following screenshot shows a sample Resource Group with the associated tags.

图 11 - Azure 门户中具有关联标记的资源组Figure 11 - Resource Group with associated tags on Azure portal

下一步是将信息从使用情况 API 提取到 Cloud Cruiser 中。The next step is to pull the information from the Usage API into Cloud Cruiser. 使用情况 API 目前提供 JSON 格式的响应。The Usage API currently provides responses in JSON format. 下面是检索到的数据示例:Here is a sample of the data retrieved:

{
  "id": "/subscriptions/bb678b04-0e48-4b44-XXXX-XXXXXXX/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20150623_0000",
  "name": "Daily_BRSDT_20150623_0000",
  "type": "Microsoft.Commerce/UsageAggregate",
  "properties":
  {
    "subscriptionId": "bb678b04-0e48-4b44-XXXX-XXXXXXXXX",
    "usageStartTime": "2015-06-22T00:00:00+00:00",
    "usageEndTime": "2015-06-23T00:00:00+00:00",
    "meterName": "Compute Hours",
    "meterRegion": "",
    "meterCategory": "Virtual Machines",
    "meterSubCategory": "Standard_D1 VM (Non-Windows)",
    "unit": "Hours",
    "instanceData": "{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/bb678b04-0e48-4b44-XXXX-XXXXXXXX/resourceGroups/DEMOUSAGEAPI/providers/Microsoft.Compute/virtualMachines/MyDockerVM\",\"location\":\"eastus\",\"tags\":{\"Department\":\"Sales\",\"Project\":\"Demo Usage API\",\"Environment\":\"Test\",\"Owner\":\"RSE\"},\"additionalInfo\":{\"ImageType\":\"Canonical\",\"ServiceType\":\"Standard_D1\"}}}",
    "meterId": "e60caf26-9ba0-413d-a422-6141f58081d6",
    "infoFields": {},
    "quantity": 8

  },
},

将数据从使用情况 API 导入到 Cloud CruiserImport data from the Usage API into Cloud Cruiser

Cloud Cruiser 工作簿提供自动化的方式来从使用情况 API 收集信息并进行处理。Cloud Cruiser workbooks provide an automated way to collect and process information from the Usage API. ETL(提取-转换-加载)工作簿允许对数据的收集、转换以及发布到 Cloud Cruiser 数据库进行配置。An ETL (extract-transform-load) workbook allows you to configure the collection, transformation, and publishing of data into the Cloud Cruiser database.

每个工作簿可以有一个或多个集合。Each workbook can have one or multiple collections. 这样,可以关联来自不同源的信息以补充或增加使用数据。This allows you to correlate information from different sources to complement or augment the usage data. 在此示例中,我们在 Azure 模板工作簿 (UsageAPI) 中创建新工作表并设置新集合,从使用情况 API 导入信息。For this example, we create a new sheet in the Azure template workbook (UsageAPI) and set a new collection to import information from the Usage API.

图 3 - 导入到 UsageAPI 工作表的使用情况 API 数据Figure 3 - Usage API data imported into the UsageAPI sheet

请注意,此工作簿已有其他工作表要从 Azure 导入服务 (ImportServices),并处理计费 API (PublishData) 的消耗信息。Notice that this workbook already has other sheets to import services from Azure (ImportServices), and process the consumption information from the Billing API (PublishData).

接下来使用使用情况 API 来填充 UsageAPI 工作表,并在 PublishData 工作表上将该信息与来自计费 API 的消耗数据进行关联。Next, we use the Usage API to populate the UsageAPI sheet, and correlate the information with the consumption data from the Billing API on the PublishData sheet.

处理来自使用情况 API 的标记信息Processing the tag information from the Usage API

将数据导入工作簿后,在 UsageAPI 工作表中创建转换步骤,对来自该 API 的信息进行处理。After importing the data into the workbook, we create transformation steps in the UsageAPI sheet in order to process the information from the API. 第一步是使用“JSON 拆分”处理器从单个字段中提取标记,并为每个标记创建字段(部门、项目、所有者和环境)。First step is to use a “JSON split” processor to extract the tags from a single field, then create fields for each one of them (Department, Project, Owner, and Environment).

图 4 - 为标记信息创建新字段Figure 4 - Create new fields for the tag information

请注意,标记信息中缺少“网络”服务(黄色框),但通过查看 ResourceGroupName 字段,可以确认此服务属于相同的资源组。Notice the “Networking” service is missing the tag information (yellow box), but we can verify that it is part of the same Resource Group by looking at the ResourceGroupName field. 因为有此资源组中其他资源的标记,所以可以在以后的过程中使用此信息来将缺少的标记应用到该资源。Since we have the tags for the other resources from this Resource Group, we can use this information to apply the missing tags to this resource later in the process.

下一步是创建查找表,将标记中的信息关联到 ResourceGroupName。The next step is to create a lookup table associating the information from the tags to the ResourceGroupName. 接下来,使用此查找表为消耗数据扩充标记信息。This lookup table is used on the next step to enrich the consumption data with tag information.

将标记信息添加到消耗数据Adding the tag information to the consumption data

现可跳转到 PublishData 表,它对来自计费 API 的消耗信息进行处理,并添加从标记提取的字段。Now we can jump to the PublishData sheet, which processes the consumption information from the Billing API, and add the fields extracted from the tags. 通过查看在上一步中创建的查找表(使用 ResourceGroupName 作为查找关键字),就可以执行该过程。This process is performed by looking at the lookup table created on the previous step, using the ResourceGroupName as the key for the lookups.

图 5 - 使用查找到的信息填充帐户结构Figure 5 - Populating the account structure with the information from the lookups

请注意,已经对“网络”服务应用了相应的帐户结构字段,从而解决了缺少标记的问题。Notice that the appropriate account structure fields for the “Networking” service were applied, fixing the issue with the missing tags. 对不属于目标资源组的其他资源,我们还使用“其他”字段填充了其帐户结构字段,以在报表中进行区分。We also populated the account structure fields for resources other than our target Resource Group with “Other”, in order to differentiate them on the reports.

现在,只需再完成一个步骤即可发布使用数据。Now we just need to add a step to publish the usage data. 在此步骤中,把在费率计划中为每个服务定义的相应费率应用到使用情况信息中,然后将计算的费用加载到数据库。During this step, the appropriate rates for each service defined on our Rate Plan be applied to the usage information, with the resulting charge loaded into the database.

最值得称道的是,只需要执行该步骤一次。The best part is that you only have to go through this process once. 完成该工作簿后,只需将其添加到计划程序中,然后它将于计划时间以每小时或每日的频率运行。When the workbook is completed, you just need to add it to the scheduler and it runs hourly or daily at the scheduled time. 然后,为了分析数据,以便从云使用数据中获取有意义的信息,仅需要创建新的报表或自定义现有报表。Then it’s just a matter of creating new reports, or customizing existing ones, in order to analyze the data to get meaningful insights from your cloud usage.

后续步骤Next Steps

了解详细信息Learn More