共用方式為


瞭解 VHD 磁碟壓縮使用量和效能

您可以使用 Windows 事件記錄檔來瞭解使用 VHD 磁碟壓縮的頻率、儲存的空間,以及執行所花費的時間。 以下是一些範例 PowerShell 腳本和 Azure Log Analytics 查詢,可用來協助您解譯事件。

PowerShell

VHD 磁碟壓縮計量腳本

此範例會使用 PowerShell 來取得過去 30 天內的 VHD 磁碟壓縮事件,格式化為方格。 從提升權限的 PowerShell 提示字元中,執行下列程式代碼區塊:

# Set startTime to number of days to search the event logs
$startTime = (Get-Date).AddDays(-30)

# Query Event Log using Get-WinEvent filtered to the VHD Disk Compaction metric events
$diskCompactionEvents = Get-WinEvent -FilterHashtable @{
    StartTime       = $startTime
    ProviderName    = 'Microsoft-FSLogix-Apps'
    ID         = 57
}

# Format event properties
$compactionMetrics = $diskCompactionEvents | Select-Object `
    @{l="Timestamp";e={$_.TimeCreated}},`
    @{l="ComputerName";e={$_.MachineName}},`
    @{l="Path";e={$_.Properties[0].Value}},`
    @{l="WasCompacted";e={$_.Properties[1].Value}},`
    @{l="TimeSpent(sec)";e={[math]::round($_.Properties[7].Value / 1000,2)}},`
    @{l="MaxSize(GB)";e={[math]::round($_.Properties[2].Value / 1024,2)}},`
    @{l="MinSize(GB)";e={[math]::round($_.Properties[3].Value / 1024,2)}},`
    @{l="InitialSize(GB)";e={[math]::round($_.Properties[4].Value / 1024,2)}},`
    @{l="FinalSize(GB)";e={[math]::round($_.Properties[5].Value / 1024,2)}},`
    @{l="SavedSpace(GB)";e={[math]::round($_.Properties[6].Value / 1024,2)}}

# Display metrics in Out-GridView
$compactionMetrics | Out-GridView

Azure Log Analytics 查詢

重要

若要使用下列查詢,您必須先設定虛擬機,將其事件記錄檔傳送至 Log Analytics 工作區。 如需詳細資訊,請參閱 使用Log Analytics代理程式收集 Windows 事件記錄數據源。 VHD 磁碟壓縮的記錄如下:

  • Microsoft-FSLogix-Apps/Operational
  • Microsoft-FSLogix-Apps/管理員

VHD 磁碟壓縮計量查詢

VHD 磁碟壓縮作業期間所花費的時間

顯示壓縮作業期間所花費的平均、最小和最大時間。 如果磁碟能夠壓縮,則會根據數據摘要。

Event
| where EventLog == 'Microsoft-FSLogix-Apps/Operational' and EventID == 57
| parse kind=relaxed EventData with *
    "<Data Name=\"Path\">" Path
    "</Data><Data Name=\"WasCompacted\">" DiskCompaction
    "</Data><Data Name=\"MaxSupportedSizeMB\">" MaxSupportedSizeMB
    "</Data><Data Name=\"MinSupportedSizeMB\">" MinSupportedSizeMB
    "</Data><Data Name=\"SizeBeforeMB\">" SizeBeforeMB
    "</Data><Data Name=\"SizeAfterMB\">" SizeAfterMB
    "</Data><Data Name=\"SavedSpaceMB\">" SavedSpaceMB
    "</Data><Data Name=\"TimeSpentMillis\">" TimeSpentMillis "</Data>" *
| extend TimeSpent = todecimal(TimeSpentMillis) / 1024
| where DiskCompaction <> ""
| summarize Average=round(avg(TimeSpent),2), Max=round(max(TimeSpent),2), Min=round(min(TimeSpent),2) by DiskCompaction

以下是輸出的範例:

A bar chart showing the result of running the Time Spent query

壓縮的容器 VHD(x) 檔案數目

顯示已根據臨界值選取多少個容器 VHD(x) 檔案以進行壓縮。

Event
| where EventLog == 'Microsoft-FSLogix-Apps/Operational' and EventID == 57
| parse kind=relaxed EventData with *
    "<Data Name=\"Path\">" Path
    "</Data><Data Name=\"WasCompacted\">" DiskCompaction
    "</Data><Data Name=\"MaxSupportedSizeMB\">" MaxSupportedSizeMB
    "</Data><Data Name=\"MinSupportedSizeMB\">" MinSupportedSizeMB
    "</Data><Data Name=\"SizeBeforeMB\">" SizeBeforeMB
    "</Data><Data Name=\"SizeAfterMB\">" SizeAfterMB
    "</Data><Data Name=\"SavedSpaceMB\">" SavedSpaceMB
    "</Data><Data Name=\"TimeSpentMillis\">" TimeSpentMillis "</Data>" *
| where DiskCompaction <> ""
| summarize NumberOfVhdContainers=count() by DiskCompaction

以下是輸出的範例:

A pie chart showing the number of V H D files (containers) compacted

儲存空間總計

顯示 VHD 磁碟壓縮作業期間回收的 GB 記憶體數量。

Event
| where EventLog == 'Microsoft-FSLogix-Apps/Operational' and EventID == 57
| parse kind=relaxed EventData with *
    "<Data Name=\"Path\">" Path
    "</Data><Data Name=\"WasCompacted\">" DiskCompaction
    "</Data><Data Name=\"MaxSupportedSizeMB\">" MaxSupportedSizeMB
    "</Data><Data Name=\"MinSupportedSizeMB\">" MinSupportedSizeMB
    "</Data><Data Name=\"SizeBeforeMB\">" SizeBeforeMB
    "</Data><Data Name=\"SizeAfterMB\">" SizeAfterMB
    "</Data><Data Name=\"SavedSpaceMB\">" SavedSpaceMB
    "</Data><Data Name=\"TimeSpentMillis\">" TimeSpentMillis "</Data>" *
| extend Storage = todecimal(SavedSpaceMB)
| summarize StorageSavings = (format_bytes(sum(Storage * 1024 * 1024),2,"GB"))

Winlogon (註銷) 延遲警告

顯示導致 Winlogon 超過 60 秒閾值的任何服務。 顯示出現的次數,以及花費的平均和最大時間。

Event
| where Source == 'Microsoft-Windows-Winlogon' and EventID == 6006
| parse kind=relaxed ParameterXml with "<Param>" ServiceName "</Param><Param>" Duration "</Param><Param>" EventType "</Param><Param>-</Param>"
| extend TimeInSeconds = todecimal(Duration)
| where EventType == "Logoff"
| summarize Occurrences=count(),Average=round(avg(TimeInSeconds),2), Minimum=round(min(TimeInSeconds),2), Maximum=round(max(TimeInSeconds),2) by ServiceName

以下是輸出的範例:

A table showing the services which exceeded the Winlogon threshold