快速入门:使用 Azure CLI 创建 Azure 门户仪表板Quickstart: Create an Azure portal dashboard with Azure CLI

Azure 门户中的仪表板可以集中且有组织地呈现你的云资源。A dashboard in the Azure portal is a focused and organized view of your cloud resources. 本文重点介绍使用 Azure CLI 创建仪表板的过程。This article focuses on the process of using Azure CLI to create a dashboard. 仪表板会显示虚拟机 (VM) 的性能以及一些静态信息和链接。The dashboard shows the performance of a virtual machine (VM), as well as some static information and links.

先决条件Prerequisites

  • 如果需要,请安装 Azure CLI 来运行 CLI 参考命令。If you prefer, install the Azure CLI to run CLI reference commands.

    • 如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。If you're using a local installation, sign in to the Azure CLI by using the az login command. 若要完成身份验证过程,请遵循终端中显示的步骤。To finish the authentication process, follow the steps displayed in your terminal. 有关其他登录选项,请参阅登录 Azure CLIFor additional sign-in options, see Sign in with the Azure CLI.

    • 出现提示时,请在首次使用时安装 Azure CLI 扩展。When you're prompted, install Azure CLI extensions on first use. 有关扩展详细信息,请参阅使用 Azure CLI 的扩展For more information about extensions, see Use extensions with the Azure CLI.

    • 运行 az version 以查找安装的版本和依赖库。Run az version to find the version and dependent libraries that are installed. 若要升级到最新版本,请运行 az upgradeTo upgrade to the latest version, run az upgrade.

  • 如果有多个 Azure 订阅,请选择在其中对资源进行计费的相应订阅。If you have multiple Azure subscriptions, choose the appropriate subscription in which to bill the resources. 使用 az account set 命令选择订阅:Select a subscription by using the az account set command:

    az account set --subscription 00000000-0000-0000-0000-000000000000
    
  • 使用 az group create 命令或使用现有资源组创建 Azure 资源组Create an Azure resource group by using the az group create command or use an existing resource group:

    az group create --name myResourceGroup --location chinaeast
    

    资源组是在其中以组的形式部署和管理 Azure 资源的逻辑容器。A resource group is a logical container in which Azure resources are deployed and managed as a group.

创建虚拟机Create a virtual machine

使用 az vm create 命令创建虚拟机:Create a virtual machine by using the az vm create command:

az vm create --resource-group myResourceGroup --name SimpleWinVM --image win2016datacenter \
   --admin-username azureuser --admin-password 1StrongPassword$

备注

密码必须是复杂密码。The password must be complex. 这是新的用户名和密码。This is a new user name and password. 它不是用于登录 Azure 的帐户。It's not, for example, the account you use to sign in to Azure. 有关详细信息,请参阅用户名要求密码要求For more information, see username requirements and password requirements.

部署开始进行,通常需要几分钟才能完成。The deployment starts and typically takes a few minutes to complete. 部署完成后,请转到下一部分。After deployment completes, move on to the next section.

下载仪表板模板Download the dashboard template

由于 Azure 仪表板是资源,所以它们可以表示为 JSON。Since Azure dashboards are resources, they can be represented as JSON. 有关详细信息,请参阅 Azure 仪表板结构For more information, see The structure of Azure Dashboards.

下载以下文件:portal-dashboard-template-testvm.jsonDownload the following file: portal-dashboard-template-testvm.json.

通过将以下值更改为你的值来自定义下载的模板:Customize the downloaded template by changing the following values to your values:

  • <subscriptionID>:订阅<subscriptionID>: Your subscription
  • <rgName>:资源组,例如 myResourceGroup<rgName>: Resource group, for example myResourceGroup
  • <vmName>:虚拟机名称,例如 SimpleWinVM<vmName>: Virtual machine name, for example SimpleWinVM
  • <dashboardTitle>:仪表板标题,例如 Simple VM Dashboard<dashboardTitle>: Dashboard title, for example Simple VM Dashboard
  • <location>:Azure 区域,例如 chinaeast<location>: Your Azure region, for example, chinaeast

有关详细信息,请参阅 Microsoft 门户仪表板模板参考For more information, see Microsoft portal dashboards template reference.

部署仪表板模板Deploy the dashboard template

现在可以从 Azure CLI 中部署模板。You can now deploy the template from within Azure CLI.

  1. 运行 az portal dashboard create 命令来部署模板:Run the az portal dashboard create command to deploy the template:

    az portal dashboard create --resource-group myResourceGroup --name 'Simple VM Dashboard' \
       --input-path portal-dashboard-template-testvm.json --location chinaeast
    
  2. 通过运行 az portal dashboard show 命令检查是否已成功创建仪表板:Check that the dashboard was created successfully by running the az portal dashboard show command:

    az portal dashboard show --resource-group myResourceGroup --name 'Simple VM Dashboard'
    

若要查看当前订阅的所有仪表板,请使用 az portal dashboard listTo see all the dashboards for the current subscription, use az portal dashboard list:

az portal dashboard list

还可以查看资源组的所有仪表板:You can also see all the dashboards for a resource group:

az portal dashboard list --resource-group myResourceGroup

可以使用 az portal dashboard update 命令更新仪表板:You can update a dashboard by using the az portal dashboard update command:

az portal dashboard update --resource-group myResourceGroup --name 'Simple VM Dashboard' \
   --input-path portal-dashboard-template-testvm.json --location chinaeast

验证是否可以从 Azure 门户中查看有关虚拟机的数据。Verify that you can see data about the virtual machine from within the Azure portal.

  1. 在 Azure 门户中,选择“仪表板”。In the Azure portal, select Dashboard.

    Azure 门户导航到仪表板

  2. 在仪表板页面上,选择“简单的 VM 仪表板”。On the dashboard page, select Simple VM Dashboard.

    导航到“简单的 VM 仪表板”

  3. 查看仪表板。Review the dashboard. 你可以看到某些内容是静态的,但也有一些图表显示 VM 的性能。You can see that some of the content is static, but there are also charts that show the performance of the VM.

    查看简单的 VM 仪表板

清理资源Clean up resources

若要删除虚拟机和关联仪表板,请删除包含它们的资源组。To remove the virtual machine and associated dashboard, delete the resource group that contains them.

注意

以下示例删除指定的资源组及其包含的所有资源。The following example deletes the specified resource group and all resources contained within it. 如果指定的资源组中存在本文范围外的资源,这些资源也会被删除。If resources outside the scope of this article exist in the specified resource group, they will also be deleted.

az group delete --name myResourceGroup

如需仅删除仪表板,请使用 az portal dashboard delete 命令:To remove only the dashboard, use the az portal dashboard delete command:

az portal dashboard delete --resource-group myResourceGroup --name "Simple VM Dashboard"

后续步骤Next steps

有关对仪表板的 Azure CLI 支持的详细信息,请参阅 az portal dashboardFor more information about Azure CLI support for dashboards, see az portal dashboard.