適用於 Node.js 的 Azure Commerce 模組Azure Commerce modules for Node.js

概觀Overview

使用 Azure Commerce API 將使用情況和資源資料提取到您慣用的資料分析工具。Use Azure Commerce APIs to pull usage and resource data into your preferred data analysis tools. Azure 資源使用情況和 RateCard API 可協助您準確地預測並管理成本。The Azure Resource Usage and RateCard APIs can help you accurately predict and manage your costs. 這些 API 會實作為資源提供者,並成為 Azure Resource Manager 所公開之 API 系列的一部分。The APIs are implemented as a Resource Provider and part of the family of APIs exposed by the Azure Resource Manager.

管理封裝Management package

安裝 npm 模組Install the npm module

安裝 Azure Commerce npm 模組Install the Azure Commerce npm module

npm install azure-arm-commerce

範例Example

此範例會擷取您上個月估計的 Azure 取用資料。This example retrieves your estimated Azure consumption data for the last month.

const msRestAzure = require('ms-rest-azure');
const CommerceManagement = require('azure-arm-commerce');

const endDate = new Date();
endDate.setUTCHours(0, 0, 0, 0);
const startDate = new Date();
startDate.setMonth(startDate.getMonth() - 1);
startDate.setUTCHours(0, 0, 0, 0);

const subscriptionId = 'your-subscription-id';
const usageOptions = {
  showDetails: true,
  granularity: 'Daily'
};

msRestAzure
  .interactiveLogin()
  .then(credentials => {
    const client = new CommerceManagement(credentials, subscriptionId);
    return client.usageAggregates.list(startDate, endDate, usageOptions);
  })
  .then(usage => {
    console.dir(usage, { depth: null, colors: true });
  });

範例Samples

深入探索可在應用程式中使用的 Node.js 程式碼範例Explore more sample Node.js code you can use in your apps.