手动重新生成 Windows Server 2008 64 位或 Windows Server 2008 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存在已知问题的修补程序。 此修补程序已针对这些操作系统引入 Service Pack 2。 如果使用的是 Service Pack 1 或更低版本,请应用修补程序961382。

参考