Azure 应用服务:使用 PerformanceCounters
Azure App Service: using 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 以允许访问应用程序 pool/user,但我认为这对于 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 角色)。您可以完全控制那里的 OS,同时仍然是 PaaS。
我正在尝试设置我的 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 以允许访问应用程序 pool/user,但我认为这对于 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 角色)。您可以完全控制那里的 OS,同时仍然是 PaaS。