手动重新生成 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 是否包含正确的信息。 可以从同一台计算机复制此文件以还原计数器。 此文件在计算机之间可能存在细微差异。 但是,如果发现大小存在巨大差异,则可能缺少信息。 始终在替换之前创建备份副本。 无法保证从另一台计算机复制此文件会还原所有计数器。 如果可能,请将文件与计算机的备份进行比较,以查看文件大小是否在某个时间点减小。

对于许多计数器,用于安装性能计数器的 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 已知问题的修补程序。 此修补程序已针对这些操作系统引入 Service Pack 2。 如果你使用的是 Service Pack 1 或更低版本,请应用修补程序961382。

References