你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 Azure CLI 获取使用情况数据

本文介绍如何使用 Azure CLI 获取成本和使用情况数据。 若要使用 Azure 门户获取使用情况数据,请参阅查看和下载 Azure 使用情况和费用

设置 Azure CLI

首先为 Azure CLI 准备环境。

配置导出作业以将成本数据导出到 Azure 存储

登录后,使用 export 命令将使用情况数据导出到 Azure 存储帐户。 可从此处下载数据。

  1. 创建一个资源组或使用现有资源组。 要创建资源组,请运行 group create 命令:

    az group create --name TreyNetwork --location "East US"
    
  2. 可以创建一个存储帐户或使用现有存储账户来接收导出。 要创建账户,使用 storage account create 命令:

    az storage account create --resource-group TreyNetwork --name cmdemo
    
  3. 运行 export create 命令以创建导出:

    az costmanagement export create --name DemoExport --type Usage \--scope "subscriptions/00000000-0000-0000-0000-000000000000" --storage-account-id cmdemo \--storage-container democontainer --timeframe MonthToDate --storage-directory demodirectory