Azure 应用服务:使用性能计数器

2023-12-24

我正在尝试设置我的 Azure Web 应用程序以包含第三方软件的使用,这似乎需要访问 PerformanceCounters。在本地,这工作正常,但是当我在 Azure 中运行它时,出现以下错误:

[UnauthorizedAccessException: Access to the registry key 'Global' is denied.]
Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) +5230217
Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object defaultValue, Boolean doNotExpand, Boolean checkSecurity) +11769029
Microsoft.Win32.RegistryKey.GetValue(String name) +40
System.Diagnostics.PerformanceMonitor.GetData(String item) +102
System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item) +186
System.Diagnostics.PerformanceCounterLib.get_CategoryTable() +105
System.Diagnostics.PerformanceCounterLib.GetCategorySample(String category) +17
System.Diagnostics.PerformanceCounterLib.GetCategorySample(String machine, String category) +61
System.Diagnostics.PerformanceCounterCategory.GetCounterInstances(String categoryName, String machineName) +70
System.Diagnostics.PerformanceCounterCategory.GetInstanceNames() +25

根据这个答案 https://stackoverflow.com/questions/17301640/access-to-the-registry-key-global-is-denied-when-accessing-performance-count,我应该配置 IIS 以允许访问应用程序池/用户,但我认为这对于 Azure Web 应用程序来说是不可能的。有没有办法让性能计数器在我的情况下工作?


在 Windows 上,可以通过 WMI 访问性能计数器:
https://msdn.microsoft.com/en-us/library/aa392397(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/aa392397(v=vs.85).aspx

WMI 在应用服务沙箱中受到限制。
From https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#access-to-out-of-process-com-servers https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#access-to-out-of-process-com-servers:

访问进程外 COM 服务器

Windows 服务器配置了一堆 COM 服务器,默认情况下可供使用;然而,沙箱阻止访问所有进程外 COM 服务器。例如,沙盒应用程序无法调用 WMI 或 MSIServer。

来自库杜:

PS D:\home> Get-Counter -Counter "\processor(_total)\% processor time"
Get-Counter : The specified object was not found on the computer.


PS D:\home> Get-WmiObject -Class WIN32_OperatingSystem
Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 
(E_ACCESSDENIED))

如果您绝对必须使用第 3 方软件,请查看 Azure 云服务(带有 Web 角色)。您可以完全控制那里的操作系统,同时仍然是 PaaS。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Azure 应用服务:使用性能计数器 的相关文章

随机推荐