2016-07-15 31 views
1

我想設置我的Azure Web應用程序以包含使用第三方軟件,這似乎需要訪問PerformanceCounters。本地這工作得很好,但是當我在Azure上運行它,我得到以下錯誤:Azure應用服務:使用PerformanceCounters

[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應用程序是可能的。有沒有辦法讓性能計數器在我的情況下工作?

+0

嘗試將緩存客戶端應用程序帳戶添加到以下組:Performance Monitor Users組和Performance Log Users組,然後重新啓動緩存客戶端應用程序。 – Thennarasan

+0

嘗試wbemtest「Win + R」並鍵入wbemtest並檢查錯誤。 –

回答

1

在Windows上,性能計數器訪問通過WMI:
https://msdn.microsoft.com/en-us/library/aa392397(v=vs.85).aspx

WMI是在App服務沙盒限制。
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)) 

如果你絕對必須使用第三方軟件,看一下Azure的雲服務(與Web角色)。您仍可以完全控制操作系統,同時仍然是PaaS。

+0

這就是我所害怕的。我以前使用Cloud Service中的工作者角色運行該軟件,但爲了測試它是過度殺毒,所以我想要一些成本更低的東西。似乎我運氣不好。 –