Azure应用服务: using PerformanceCounters

标签 azure azure-web-app-service azure-performancecounters

我正在尝试设置我的 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

根据this answer ,我应该配置 IIS 以允许访问应用程序池/用户,但我认为这对于 Azure Web 应用程序来说是不可能的。有没有办法让性能计数器在我的情况下工作?

最佳答案

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

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

Access to out-of-process COM servers

Windows Servers have a bunch of COM servers configured and available for consumption by default; however the sandbox prevents access to all out-of-proc COM servers. For example, a sandboxed application cannot call into WMI, or into 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。

关于Azure应用服务: using PerformanceCounters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38393394/

相关文章:

Microsoft 托管代理和并行作业上的 Azure 计费

.net - 在azure网站(应用服务)上添加部署后脚本

wordpress - 如何将 Nginx 配置为仅为 Azure 应用服务上的 WordPress 提供 https 服务

c# - Azure Web App 中的 nuget 更新后 Web API 返回 HttpResponseMessage 对象

azure 。应用见解。 AI日志中莫名其妙的错误信息

azure - 如何获取Azure中虚拟机的性能?

azure - 是否可以在本地环境中通过 azure bot 服务使用 Direct Line API 协议(protocol)?

bash - 如何在不手动配置的情况下使用databricks-cli

azure - 应用服务 VNet 与 Azure 存储服务端点集成