我在通过Azure虚拟机收款方面遇到了一些困难。
例如,有一些度量用于接收CPU使用量消耗和CPU消耗量消耗。
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmname}/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=Percentage%20CPU,CPU%20Credits%20Consumed×pan=2019-05-20T00:00:00Z/2019-05-21T00:00:00Z
所以我收到这样的信息:
{"cost"=>0.04, "timestamp"=>"2019-05-20T00:26:00Z"}},
{"cost"=>0.03, "timestamp"=>"2019-05-20T00:27:00Z"}},
{"cost"=>0.03, "timestamp"=>"2019-05-20T00:28:00Z"}}
如果我将1440个结果全部加起来,则整天可以得到 57 个单位(很重要)。
但是,还有诸如用法详细信息之类的东西。当我使用它时:
https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?api-version=2019-01-01
此请求的响应如下:
"properties"=>
{"billingPeriodId"=>"/subscriptions/subscription_id/providers/Microsoft.Billing/billingPeriods/201906",
"usageStart"=>"2019-05-20T00:00:00.0000000Z",
"usageEnd"=>"2019-05-20T23:59:59.0000000Z",
"instanceId"=>"/subscriptions/subscription_id/resourceGroups/CLOUD-SHELL-STORAGE-EASTUS/providers/Microsoft.Compute/virtualMachines/name",
"instanceName"=>"name",
"instanceLocation"=>"AP East",
"meterId"=>"some_id",
"usageQuantity"=>24,
"pretaxCost"=>24.75,
"currency"=>"RUB",
"subscriptionGuid"=>"some guid",
"subscriptionName"=>"MSDN",
因此它显示了5月20日的24.75 RUB。
我想知道什么是正确的方法来获得虚拟机消耗的适当成本。预先感谢
答案 0 :(得分:1)
What resources are charged when deploying a VM?
要了解VM的成本,我们需要了解在使用任何VM时正在使用的资源是什么。虚拟机会为虚拟机本身,在虚拟机上运行的所有高级软件,与虚拟机关联的存储帐户\托管磁盘以及从虚拟机转移的网络带宽获取成本。
我们可以使用资源价目表API获取天蓝色订阅中使用的资源的价格和元数据信息。
这是示例价目表api URL。
https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/RateCard?api-version={api-version}&$filter=OfferDurableId eq ’{OfferDurableId}’ and Currency eq ’{Currency}’ and Locale eq ’{Locale}’ and RegionInfo eq ’{RegionInfo}’’
将{OfferDurableId}设置为有效的商品ID代码(例如,MS-AZR-0026P)。有关可用商品ID,国家/地区可用性和计费货币列表的更多信息,请参见Microsoft Azure商品详细信息。优惠ID参数由“ MS-AZR-”前缀和优惠ID号组成。
将{Currency}设置为需要提供资源费率的货币。
将{Locale}设置为需要对资源元数据进行本地化的区域性。
将{RegionInfo}设置为购买要约的2个字母的ISO代码。
https://management.azure.com/subscriptions/ {subscription-Id} /providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&$filter=OfferDurableId eq'MS-AZR-0003p'和货币eq'USD '和Locale eq'en-US'和RegionInfo eq'US'
样本响应:
{
"OfferTerms": [],
"Meters": [
{
"MeterId": "1822fcc4-6059-4cbb-a132-54a187aaac46",
"MeterName": "Compute Hours",
"MeterCategory": "Virtual Machines",
"MeterSubCategory": "Basic_D6 VM (Non-Windows)",
"Unit": "Hours",
"MeterTags": [],
"MeterRates": {
"0": 3.136
},
"EffectiveDate": "2015-02-01T00:00:00Z",
"IncludedQuantity": 0.0
},
{
"MeterId": "3c5324ad-eb8c-44c6-af9a-6741ae75fc90",
"MeterName": "Data Transfer Out at 500 Mbps (GB)",
"MeterCategory": "Networking",
"MeterSubCategory": "ExpressRoute (IXP)",
"Unit": "GB",
"MeterTags": [],
"MeterRates": {
"0": 0.1
},
"EffectiveDate": "2014-08-01T00:00:00Z",
"IncludedQuantity": 2048.0
},
{
"MeterId": "9ee077eb-c902-46ef-b7f9-2caeade852e0",
"MeterName": "Compute Hours",
"MeterCategory": "Cloud Services",
"MeterSubCategory": "A6 Cloud Services",
"Unit": "Hours",
"MeterTags": [],
"MeterRates": {
"0": 0.71
},
"EffectiveDate": "2013-12-01T00:00:00Z",
"IncludedQuantity": 0.0
},
…
]
"Currency": "USD",
"Locale": "en-US",
"IsTaxIncluded": false,
"MeterRegion": "US West",
"Tags": []
}
希望有帮助。