私はCalculationsCounterManager(以下のコード)というクラスを実装した.NET 3.5 Webアプリケーションを持っています。このクラスには、SQL Serverデータベースへのデータ呼び出しを監視する2つのカスタムパフォーマンスカウンターの作成と増分を管理する共有/静的メンバーがいくつかあります。これらのデータ呼び出しを実行すると、カウンターが存在しない場合は作成されます。もちろん、このクラスのnUnit GUIを通して実行される単体テストでも、すべて正常に動作します。カウンターが作成され、細かくインクリメントされます。Webアプリケーションによるカスタムカウンター作成
ただし、同じコードがASPNETワーカープロセスを通じて実行されると、次のエラーメッセージが表示されます。 "要求されたレジストリアクセスは許可されていません。"このエラーは、カウンターカテゴリが既に存在するかどうかを確認するために読み取りが完了したときに、CalculationsCounterManagerクラスの44行目で発生します。
ワーカープロセスアカウントに十分なpriveledgeを提供して、セキュリティ上の問題が発生するまでサーバーを開かずに運用環境でカウンタを作成できる方法を知っている人はいますか?
Namespace eA.Analytics.DataLayer.PerformanceMetrics
''' <summary>
''' Manages performance counters for the calculatioins data layer assembly
''' </summary>
''' <remarks>GAJ 09/10/08 - Initial coding and testing</remarks>
Public Class CalculationCounterManager
Private Shared _AvgRetrieval As PerformanceCounter
Private Shared _TotalRequests As PerformanceCounter
Private Shared _ManagerInitialized As Boolean
Private Shared _SW As Stopwatch
''' <summary>
''' Creates/recreates the perf. counters if they don't exist
''' </summary>
''' <param name="recreate"></param>
''' <remarks></remarks>
Public Shared Sub SetupCalculationsCounters(ByVal recreate As Boolean)
If PerformanceCounterCategory.Exists(CollectionSettings.CalculationMetricsCollectionName) = False Or recreate = True Then
Dim AvgCalcsProductRetrieval As New CounterCreationData(CounterSettings.AvgProductRetrievalTimeCounterName, _
CounterSettings.AvgProductRetrievalTimeCounterHelp, _
CounterSettings.AvgProductRetrievalTimeCounterType)
Dim TotalCalcsProductRetrievalRequests As New CounterCreationData(CounterSettings.TotalRequestsCounterName, _
CounterSettings.AvgProductRetrievalTimeCounterHelp, _
CounterSettings.TotalRequestsCounterType)
Dim CounterData As New CounterCreationDataCollection()
' Add counters to the collection.
CounterData.Add(AvgCalcsProductRetrieval)
CounterData.Add(TotalCalcsProductRetrievalRequests)
If recreate = True Then
If PerformanceCounterCategory.Exists(CollectionSettings.CalculationMetricsCollectionName) = True Then
PerformanceCounterCategory.Delete(CollectionSettings.CalculationMetricsCollectionName)
End If
End If
If PerformanceCounterCategory.Exists(CollectionSettings.CalculationMetricsCollectionName) = False Then
PerformanceCounterCategory.Create(CollectionSettings.CalculationMetricsCollectionName, CollectionSettings.CalculationMetricsDescription, _
PerformanceCounterCategoryType.SingleInstance, CounterData)
End If
End If
_AvgRetrieval = New PerformanceCounter(CollectionSettings.CalculationMetricsCollectionName, CounterSettings.AvgProductRetrievalTimeCounterName, False)
_TotalRequests = New PerformanceCounter(CollectionSettings.CalculationMetricsCollectionName, CounterSettings.TotalRequestsCounterName, False)
_ManagerInitialized = True
End Sub
Public Shared ReadOnly Property CategoryName() As String
Get
Return CollectionSettings.CalculationMetricsCollectionName
End Get
End Property
''' <summary>
''' Determines if the performance counters have been initialized
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Shared ReadOnly Property ManagerInitializaed() As Boolean
Get
Return _ManagerInitialized
End Get
End Property
Public Shared ReadOnly Property AvgRetrieval() As PerformanceCounter
Get
Return _AvgRetrieval
End Get
End Property
Public Shared ReadOnly Property TotalRequests() As PerformanceCounter
Get
Return _TotalRequests
End Get
End Property
''' <summary>
''' Initializes the Average Retrieval Time counter by starting a stopwatch
''' </summary>
''' <remarks></remarks>
Public Shared Sub BeginIncrementAvgRetrieval()
If _SW Is Nothing Then
_SW = New Stopwatch
End If
_SW.Start()
End Sub
''' <summary>
''' Increments the Average Retrieval Time counter by stopping the stopwatch and changing the
''' raw value of the perf counter.
''' </summary>
''' <remarks></remarks>
Public Shared Sub EndIncrementAvgRetrieval(ByVal resetStopwatch As Boolean, ByVal outputToTrace As Boolean)
_SW.Stop()
_AvgRetrieval.RawValue = CLng(_SW.ElapsedMilliseconds)
If outPutToTrace = True Then
Trace.WriteLine(_AvgRetrieval.NextValue.ToString)
End If
If resetStopwatch = True Then
_SW.Reset()
End If
End Sub
''' <summary>
''' Increments the total requests counter
''' </summary>
''' <remarks></remarks>
Public Shared Sub IncrementTotalRequests()
_TotalRequests.IncrementBy(1)
End Sub
Public Shared Sub DeleteAll()
If PerformanceCounterCategory.Exists(CollectionSettings.CalculationMetricsCollectionName) = True Then
PerformanceCounterCategory.Delete(CollectionSettings.CalculationMetricsCollectionName)
End If
End Sub
End Class
End Namespace