手動重建 Windows Server 2008 64 位或 Windows Server 2008 R2 系統的性能計數器

本文有助於解決某些性能計數器連結庫損毀且需要重建的問題。

適用:Windows Server 2012 R2
原始 KB 編號: 2554336

徵狀

當您使用 效能監視器 工具時,某些計數器可能會遺失或不包含計數器數據。 性能計數器連結庫可能會損毀,而且需要重建。

您可能會在應用程式記錄檔中看到下列錯誤:

Log Name: Application  
Source: Microsoft-Windows-IIS-W3SVC-PerfCounters  
Event ID: 2002  
Level: Error  
Keywords: Classic  
Description:  
Setting up Web Service counters failed, please make sure your Web Service counters are registered correctly.
Log Name: Application  
Source: IISInfoCtrs  
Event ID: 1001  
Level: Error  
Keywords: Classic  
Description:  
Unable to read the first counter index value from the registry. The error code returned by the registry is data DWORD 0.

原因

如果某些可延伸的計數器損毀登錄,或 Windows Management Instrumentation (WMI) 型程式修改登錄,可能會發生此行為。

解決方案

若要解決此問題,請使用下列方法。

確定登錄中未停用計數器

您可以透過登錄設定停用計數器。 檢查下列登入位置,以確保計數器尚未停用:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\%servicename%\Performance

注意事項

%servicename% 表示具有性能計數器的任何服務。 例如:PerfDisk、PerfOS 等。

在這些位置中,可能會有 DisablePerformanceCounters 的登錄機碼。 根據停 用性能計數器一文,此值應設定為 0。 如果值不是 0,則計數器可能會停用。

  • 值為 1 表示計數器已停用。
  • 值為 2 表示 32 位計數器已停用。
  • 值為 4 表示 64 位計數器已停用。

重建所有性能計數器,包括可延伸和第三方計數器

若要重建所有性能計數器,包括可延伸和第三方計數器,請在系統管理命令提示字元中輸入下列命令。 在每個命令之後按 ENTER 鍵。

  1. 重建計數器:

    cd c:\windows\system32
    lodctr /R
    cd c:\windows\sysWOW64
    lodctr /R
    
  2. 使用 Windows Management Instrumentation (WMI) 重新同步處理計數器:

    WINMGMT.EXE /RESYNCPERF
    
  3. 停止並重新啟動效能記錄和警示服務。

    Get-Service -Name "pla" | Restart-Service -Verbose
    
  4. 停止並重新啟動 Windows Management Instrumentation 服務。

    Get-Service -Name "winmgmt" | Restart-Service -Force -Verbose
    
  5. 建立新的數據收集器集合 (不要使用現有的數據收集器集) 。

有時候,執行 lodctr /R 可能不會復原所有計數器。 如果您發現發生這種情況,請確認檔案 c:\windows\system32\PerfStringBackup.INI 包含適當的資訊。 您可以從相同的電腦複製此檔案來還原計數器。 此檔案從電腦到電腦可能有些許差異。 但是,如果您發現大小有大幅差異,則可能遺漏資訊。 請先建立備份複本,再取代 。 不保證從另一部計算機複製此檔案會還原所有計數器。 可能的話,請將檔案與計算機的備份進行比較,以查看檔案大小是否已在某個時間點減少。

對於許多計數器,要安裝perf計數器的ini檔案位置是在 windows\winsxs之下,例如IIS的ini檔案。

如果您看到下列錯誤:

Log Name: Application  
Source: Microsoft-Windows-IIS-W3SVC-PerfCounters  
Event ID: 2002  
Level: Error  
Keywords: Classic  
Description:  
Setting up Web Service counters failed, please make sure your Web Service counters are registered correctly.
Log Name: Application  
Source: IISInfoCtrs  
Event ID: 1001  
Level: Error  
Keywords: Classic  
Description:  
Unable to read the first counter index value from the registry. The error code returned by the registry is data DWORD 0.

您必須在目錄 c:\Windows\winsxs中使用計數器安裝 ini 檔案。

您可能需要修復的計數器可能會有多個資料夾。 在這些情況下,您可能需要使用試用版和錯誤來尋找正確的 ini 檔案。

例如:

Dir C:\Windows\winsxs\amd64_microsoft-windows-iis-metabase*

在此範例中,請嘗試使用下列方法從每個資料夾安裝 infoctrs.ini:

Lodtr infoctrs.ini

成功時,您會在應用程式記錄檔中看到下列專案:

Log Name: Application  
Source: Microsoft-Windows-LoadPerf  
Event ID: 1000  
Level: Information  
Description:  
Performance counters for the inetinfo (inetinfo) service were loaded successfully. The Record Data in the data section contains the new index values assigned to this service.

您需要針對下列計數器執行相同的動作:

amd64_microsoft-windows-iis-w3svc*

lodctr w3ctrs.ini

之後,您會看到:

Log Name: Application  
Source: Microsoft-Windows-LoadPerf  
Event ID: 1000  
Level: Information  
Description:  
Performance counters for the W3SVC (World Wide Web Publishing Service) service were loaded successfully. The Record Data in the data section contains the new index values assigned to this service.

遵循下列步驟,重新執行 WINMGMT /RESYNCPERF

其他相關資訊

Windows Server 2008 和 Vista 系統上 PerfDisk.dll 的已知問題有一個 Hotfix。 此 Hotfix 已針對這些操作系統推出 Service Pack 2。 如果您在 Service Pack 1 或以下版本,請套用 Hotfix 961382。

參考資料