快速入門:使用 Azure CLI 建立 Azure 入口網站儀表板

Azure 入口網站中的儀表板是雲端資源的聚焦及經過組織的檢視。 此快速入門會說明如何使用 Azure CLI 來建立儀表板。 範例儀表板會顯示虛擬機器 (VM) 的效能,以及一些靜態資訊和連結。

除了下列必要條件之外,您還需要具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶

必要條件

  • 如果您有多個 Azure 訂用帳戶,請選擇為資源計費的適當訂用帳戶。 使用 az account set 命令來選取訂用帳戶:

    az account set --subscription 00000000-0000-0000-0000-000000000000
    
  • 使用 az group create 命令 (或使用現有的資源群組建立 Azure 資源群組):

    az group create --name myResourceGroup --location centralus
    

建立虛擬機器

使用 az vm create 命令來建立虛擬機器:

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

注意

這是新的使用者名稱和密碼 (不是您用來登入 Azure) 的帳戶。 必須使用複雜密碼。 如需詳細資訊,請參閱使用者名稱需求密碼需求

部署開始後,通常需要數分鐘才能完成。

下載儀表板範本

因為 Azure 儀表板屬於資源,所以能夠以 JSON 的形式呈現。 如需詳細資訊,請參閱 Azure 儀表板的結構

下載檔案:portal-dashboard-template-testvm.json

然後,以您的值取代下列內容以自訂已下載的範本:

  • <subscriptionID>:您的訂用帳戶
  • <rgName>:資源群組,例如 myResourceGroup
  • <vmName>:虛擬機器名稱,例如 myVM1
  • <dashboardTitle>:儀表板標題,例如 Simple VM Dashboard
  • <location>:Azure 區域,例如 centralus

如需詳細資訊,請參閱 Microsoft 入口網站儀表板範本參考

部署儀表板範本

您現在可以在 Azure CLI 中部署範本。

  1. 執行 az portal dashboard create 命令以部署範本:

    az portal dashboard create --resource-group myResourceGroup --name 'Simple VM Dashboard' \
       --input-path portal-dashboard-template-testvm.json --location centralus
    
  2. 執行 az portal dashboard show 命令,檢查是否已成功建立儀表板:

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

若要查看目前訂用帳戶的所有儀表板,請使用 az portal dashboard list

az portal dashboard list

您也可以查看特定資源群組的所有儀表板:

az portal dashboard list --resource-group myResourceGroup

若要更新儀表板,請使用 az portal dashboard update 命令:

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

檢閱已部署的資源

驗證您可以在 Azure 入口網站儀表板中查看虛擬機器的相關資料。

  1. 在 Azure 入口網站功能表中,選取 [儀表板]

    Screenshot of the Dashboard item on the Azure portal menu.

  2. 在儀表板頁面上,選取 [簡單的 VM 儀表板]

    Screenshot of the dashboard selection option in the Azure portal.

  3. 請檢閱儀表板,看起來應該類似這裡所示。 雖然某些內容是靜態的,但也有圖表顯示您在一開始建立的 VM 效能。

    Screenshot of an example dashboard in the Azure portal.

清除資源

若要移除虛擬機器和您建立的相關聯儀表板,請刪除包含上述項目的資源群組。

警告

當您刪除資源群組,即會刪除群組內含的所有資源。 如果資源群組包含虛擬機器和儀表板以外的其他資源,該資源也會一併刪除。

az group delete --name myResourceGroup

若只要移除儀表板,請使用 az portal dashboard delete 命令:

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

下一步

如需儀表板 Azure CLI 命令的詳細資訊,請參閱: