使用Azure计费API/SDK显示蔚蓝成本分析数据 [英] Show azure cost analysis data using Azure billing API/SDK

查看:108
本文介绍了使用Azure计费API/SDK显示蔚蓝成本分析数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure门户中,如果选择了一个订阅,则可以像下面的屏幕截图一样查看成本分析

我想以编程方式获取信息,例如上面显示的信息可能是使用某些python SDK API/REST API使用的信息. 如果有人对此有任何经验/想法,请帮助.

经过答复之后,我已经遍历了Azure Billing Rest API,现在可以调用与Usage Aggrgate和RateCard相关的Rest API.

以下是这些REST调用的结果. .

Azure Billing Ratecard Response

但是说实话,我仍然没有弄清楚如何像成本分析那样为我提供详细的视图,对于每种资源在何处可以显示多少相关成本.实际上,我对Azure还是很陌生,这就是为什么我在某些位置缺少链接.

有人可以在这里给出一些提示吗?

解决方案

如果您已经有了使用情况和价目表数据,则必须将它们组合在一起.取得使用数据的meterId,并获取相关的价目表数据.价目表数据包含您必须使用的MeterRates和IncludedQuantity.可能存在多个计费器费率和所包含的数量,因为每次使用的成本可能不同(例如,前10个免费通话,3 GB免费通话...).消费在每月的14号开始/重置.这就是为什么您必须从整个计费周期(每个月的14号开始)读取数据的原因,因为这是获取正确消费量的唯一方法.

因此,如果您使用的是Azure Functions,您每天的使用量为100.000个单位,并且您希望从20日到30日使用成本,那么计算方法如下: 从14号到30号读取数据.这是17天,因此它使用了1.700.000单位. 前400.000是免费的= IncludedQuantity(因此在此示例中,前4天).从400.001单位开始,您必须采用电表费率(0,0000134928€)并计算成本. 1.300.000 * 0,0000134928 =〜17,54€.幸运的是,天蓝色函数只有一种速率.如果速率发生变化,例如在5.000.000个单位之后,那么您还必须考虑到这一点. 如果您拥有全部费用,则可以按日期20.-30进行过滤.您将得到结果.

这是计算的简短说明.我在C#中实现了此计算,并将其发布为NuGet包.源代码在github上-可能会有所帮助.它还包含一个示例控制台,可用于导出数据.

In Azure portal ,if one subscription is selected ,the cost analysis can be viewed like the following screenshot

I want to programmatically fetch the information the like the one displayed above may be using using some python SDK API/REST API. If anybody has any experience/idea on this ,please help.

After going through replies ,I have gone through the Azure Billing Rest API and I am now able to call the Usage Aggrgate and RateCard related Rest APIs.

Following are the results of those REST Calls. .Azure Billing Usage Aggregate Response

Azure Billing Ratecard Response

But honestly speaking ,I still have not figured out how these to would give me detailed view like the cost analysis does where for each resource how much cost associated can be displayed.Actually I am very new to Azure probably that is why I am missing the link some where .

Can somebody give some hint here ?

解决方案

If you already have the usage and the ratecard data, then you must combine them. Take the meterId of the usage data and get the related ratecard data. The ratecard data contains the MeterRates and the IncludedQuantity which you must take. There are probably multiple meter rates and the included quantity because there are probably different costs per usage (e.g. first 10 calls for free, 3 GB for free, ...). The consumption starts/is reseted at the 14th of the month. That's the reason why you have to read the data from the whole billing period (begins with 14th of each month), because that's the only way how you get the correct consumption.

So, if you are using e.g. Azure Functions and you have a usage of 100.000 units per day and you want the costs from 20th - 30th, then the calculation works as follows: read data from 14th - 30th. These are 17 days and therefore it used 1.700.000 units. The first 400.000 are for free = IncludedQuantity (so in this sample the first 4 days). From the 400.001 unit on, you have to take the meter rate (0,0000134928 €) and calculate the costs. 1.300.000 * 0,0000134928 = ~17,54€. Fortunately, the azure functions have only one rate. If the rate changes e.g. after 5.000.000 units, then you also have to take this into account. If you have the whole costs, then you can filter on your date which is 20.-30. and you will get the result.

That's the short explanation of the calculation. I implemented this calculation in C# and published it as a NuGet package. The source code is on github - probably it helps. It also contains a sample console which you could use to export the data.

这篇关于使用Azure计费API/SDK显示蔚蓝成本分析数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆