【发布时间】:2021-01-15 06:41:30
【问题描述】:
谁能告诉我如何以编程方式从 Azure 网站获取 Azure 服务定价详细信息(计算、数据服务、应用服务、网络服务的定价)?
Azure 是否以 JSON 格式提供定价详细信息?
【问题讨论】:
标签: azure
谁能告诉我如何以编程方式从 Azure 网站获取 Azure 服务定价详细信息(计算、数据服务、应用服务、网络服务的定价)?
Azure 是否以 JSON 格式提供定价详细信息?
【问题讨论】:
标签: azure
到目前为止,Windows Azure 不提供任何此类 API,尽管它是一项备受追捧的功能,并且希望他们正在开发它。
目前唯一的方法可能是使用此处提到的详细信息构建您自己的数据存储:http://azure.microsoft.com/en-us/pricing/calculator/
使用数据 csv 中会提到单位价格,但不幸的是,目前唯一的方法是在此处下载此 csv 以供订阅:https://account.windowsazure.com/Subscriptions
【讨论】:
Azure 现在提供 API 来获取使用情况和计费数据。您可以查看this blog,它提供了这些 API 的概述,以及 the feedback form here,其中包含一些有用页面的链接。
总而言之,使用以下 API 获取使用情况和计费数据:
【讨论】:
不确定,如果我来不及回答。
我在寻找同样的东西,偶然发现这篇关于堆栈溢出的帖子:Azure pricing calculator api。我能够使用这个 git hub repo 生成 JSON 字符串:https://github.com/Azure-Samples/billing-dotnet-ratecard-api。
希望这会有所帮助!
【讨论】:
派对迟到了,但我发现自己正在寻找这个,但这里没有任何东西能满足我的需求。然后我发现了这个https://docs.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices
这很简单。将 Json.NET .NET 4.0 的引用添加到您的项目中它在您的引用中显示为 Newtonsoft.Json
//You will need to add these usings
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http;
private void btnGetRates_Click(object sender, EventArgs e)
{
string strUrl = "https://prices.azure.com/api/retail/prices?$filter=serviceName eq 'Virtual Machines' and skuName eq 'E64 v4' and reservationTerm eq '3 Years'";
string response = GetDataFromAPI(strUrl);
// Here is am turning the Json response into a datatable and then loading that into a DataGridView.
//You can use the Json response any way you wish
DataTable dt = Tabulate(response);
dgvAzureSKU.DataSource = null;
dgvAzureSKU.DataSource = dt;
}
public string GetDataFromAPI(string url)
{
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
var response = httpClient.GetStringAsync(new Uri(url)).Result;
return response;
}
}
public static DataTable Tabulate(string json)
{
var jsonLinq = JObject.Parse(json);
// Find the first array using Linq
var srcArray = jsonLinq.Descendants().Where(d => d is JArray).First();
var trgArray = new JArray();
foreach (JObject row in srcArray.Children<JObject>())
{
var cleanRow = new JObject();
foreach (JProperty column in row.Properties())
{
if (column.Value is JValue) // Only include JValue types
{
cleanRow.Add(column.Name, column.Value);
}
}
trgArray.Add(cleanRow);
}
return JsonConvert.DeserializeObject<DataTable>(trgArray.ToString()); //This is what loads the data into the table
}
【讨论】:
您可以在https://docs.microsoft.com/en-us/azure/billing/billing-usage-rate-card-overview 找到一些示例。 Azure 提供发票、使用情况和费率卡 API,可以帮助您执行以下操作:
【讨论】: