將來賓 OS 計量傳送到 Windows 虛擬機器 (傳統) 的 Azure 監視器計量資料庫

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

Azure 監視器診斷擴充功能 (也稱為 "WAD" 或「診斷」) 可讓您從當作虛擬機器、雲端服務或 Service Fabric 叢集一部分執行的客體作業系統 (客體 OS) 收集計量與記錄。 擴充功能可以將遙測資料傳送到許多不同位置

本文說明將 Windows 虛擬機器 (傳統) 的來賓 OS 效能計量傳送至 Azure 監視器計量資料庫的流程。 從診斷 1.11 版開始,您可以直接將計量寫入到已收集標準平台計量的 Azure 監視器計量存放區。

將計量儲存在此位置,可讓您存取與您對平台計量執行的相同動作。 動作包括近乎即時的警示、圖表、路由、從 REST API 存取以及更多功能。 在過去,診斷擴充功能會寫入到 Azure 儲存體,而不是 Azure 監視器資料存放區。

本文所述的流程僅適用於執行 Windows 作業系統的傳統虛擬機器。

必要條件

建立傳統虛擬機器和儲存體帳戶

  1. 使用 Azure 入口網站建立傳統 VM。 Create Classic VM

  2. 建立此 VM 時,請選擇建立新傳統儲存體帳戶的選項。 我們會在稍後步驟中使用此儲存體帳戶。

  3. 在 Azure 入口網站中,移至 [儲存體帳戶] 資源窗格。 選取 [金鑰],並記下儲存體帳戶名稱和儲存體帳戶金鑰。 稍後的步驟將會需要這項資訊。 Storage access keys

建立服務主體

使用建立服務主體中的指示,在 Microsoft Entra 租用戶中建立服務主體。 進行此流程時,請注意下列事項:

  • 為此應用程式建立新用戶端密碼。
  • 儲存金鑰與用戶端識別碼,以便在稍後的步驟中使用。

將您希望發出計量的資源權限授予此應用程式「監視計量發行者」。 您可以使用資源群組或整個訂用帳戶。

注意

診斷擴充功能會使用服務主體,對 Azure 監視器進行驗證並對傳統 VM 發出計量。

製作診斷擴充功能組態

  1. 準備診斷擴充功能組態檔。 此檔案指定診斷擴充功能應為您傳統 VM 收集的記錄與效能計數器。 以下是一個範例:

    <?xml version="1.0" encoding="utf-8"?>
    <DiagnosticsConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
    <PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
        <WadCfg>
        <DiagnosticMonitorConfiguration overallQuotaInMB="4096" sinks="applicationInsights.errors">
            <DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Error" />
            <Directories scheduledTransferPeriod="PT1M">
                <IISLogs containerName="wad-iis-logfiles" />
                <FailedRequestLogs containerName="wad-failedrequestlogs" />
            </Directories>
            <PerformanceCounters scheduledTransferPeriod="PT1M">
                <PerformanceCounterConfiguration counterSpecifier="\Processor(*)\% Processor Time" sampleRate="PT15S" />
                <PerformanceCounterConfiguration counterSpecifier="\Memory\Available Bytes" sampleRate="PT15S" />
                <PerformanceCounterConfiguration counterSpecifier="\Memory\Committed Bytes" sampleRate="PT15S" />
                <PerformanceCounterConfiguration counterSpecifier="\Memory\% Committed Bytes" sampleRate="PT15S" />
                <PerformanceCounterConfiguration counterSpecifier="\LogicalDisk(*)\Disk Read Bytes/sec" sampleRate="PT15S" />
            </PerformanceCounters>
            <WindowsEventLog scheduledTransferPeriod="PT1M">
                <DataSource name="Application!*[System[(Level=1 or Level=2 or Level=3)]]" />
                <DataSource name="Windows Azure!*[System[(Level=1 or Level=2 or Level=3 or Level=4)]]" />
            </WindowsEventLog>
            <CrashDumps>
                <CrashDumpConfiguration processName="WaIISHost.exe" />
                <CrashDumpConfiguration processName="WaWorkerHost.exe" />
                <CrashDumpConfiguration processName="w3wp.exe" />
            </CrashDumps>
            <Logs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Error" />
            <Metrics resourceId="/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.ClassicCompute/virtualMachines/MyClassicVM">
                <MetricAggregation scheduledTransferPeriod="PT1M" />
                <MetricAggregation scheduledTransferPeriod="PT1H" />
            </Metrics>
        </DiagnosticMonitorConfiguration>
        <SinksConfig>
        </SinksConfig>
        </WadCfg>
        <StorageAccount />
    </PublicConfig>
    <PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
        <StorageAccount name="" endpoint="" />
    </PrivateConfig>
    <IsEnabled>true</IsEnabled>
    </DiagnosticsConfiguration>
    
  2. 在診斷檔案的 “SinksConfig” 區段中,定義新的 Azure 監視器接收,如下所示:

    <SinksConfig>
        <Sink name="AzMonSink">
            <AzureMonitor>
                <ResourceId>Provide the resource ID of your classic VM </ResourceId>
                <Region>The region your VM is deployed in</Region>
            </AzureMonitor>
        </Sink>
    </SinksConfig>
    
  3. 在組態檔列出所要收集效能計數器的區段中,將效能計數器路由傳送到 Azure 監視器接收 "AzMonSink"。

    <PerformanceCounters scheduledTransferPeriod="PT1M" sinks="AzMonSink">
        <PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT15S" />
    ...
    </PerformanceCounters>
    
  4. 在私人組態中,定義 Azure 監視器帳戶。 然後新增服務主體資訊,用於發出計量。

    <PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
    <StorageAccount name="" endpoint="" />
        <AzureMonitorAccount>
            <ServicePrincipalMeta>
                <PrincipalId>clientId for your service principal</PrincipalId>
                <Secret>client secret of your service principal</Secret>
            </ServicePrincipalMeta>
        </AzureMonitorAccount>
    </PrivateConfig>
    
  5. 將此檔案儲存在本機。

將診斷擴充功能部署到您的雲端服務

  1. 啟動 PowerShell 並登入。

    Login-AzAccount
    
  2. 首先針對傳統 VM 設定內容。

    $VM = Get-AzureVM -ServiceName <VM’s Service_Name> -Name <VM Name>
    
  3. 設定以 VM 建立的傳統儲存體帳戶的內容。

    $StorageContext = New-AzStorageContext -StorageAccountName <name of your storage account from earlier steps> -storageaccountkey "<storage account key from earlier steps>"
    
  4. 使用下列命令,將診斷檔案路徑設定為變數:

    $diagconfig = “<path of the diagnostics configuration file with the Azure Monitor sink configured>”
    
  5. 使用已設定 Azure 監視器接收的診斷檔案,為傳統 VM 準備更新。

    $VM_Update = Set-AzureVMDiagnosticsExtension -DiagnosticsConfigurationPath $diagconfig -VM $VM -StorageContext $Storage_Context
    
  6. 執行下列命令,將更新部署至您的 VM:

    Update-AzureVM -ServiceName "ClassicVMWAD7216" -Name "ClassicVMWAD" -VM $VM_Update.VM
    

注意

在安裝診斷擴充功能期間,仍會強制您提供儲存體帳戶。 診斷組態檔中指定的任何記錄或效能計數器,都會寫入指定的儲存體帳戶。

在 Azure 入口網站中繪製計量

  1. 前往 Azure 入口網站。

  2. 在左側功能表上,選取 [監視]

  3. 在左側的 [監視] 窗格上,選取 [計量]

    Navigate metrics

  4. 在 [資源] 下拉式功能表中,選取您的傳統 VM。

  5. 在 [命名空間] 下拉式功能表中,選取 azure.vm.windows.guest

  6. 在 [計量] 下拉式功能表中,選取 [記憶體\認可的位元組 (使用中)]Plot metrics

下一步