2008-09-11 4 views
2

CalculationsCounterManager (아래 코드)라는 클래스를 구현 한 .NET 3.5 웹 응용 프로그램이 있습니다. 이 클래스에는 SQL Server 데이터베이스에 대한 데이터 호출을 모니터링하는 두 개의 사용자 지정 성능 카운터를 만들고 증가시키는 일부 공유/정적 멤버가 있습니다. 이러한 데이터 호출을 실행하면 카운터가 생성되지 않습니다. 물론,이 클래스의 nUnit GUI를 통해 실행되는 단위 테스트를 통해 모든 것이 잘 작동합니다. 카운터가 생성되고 잘 증가합니다.웹 응용 프로그램을 통한 사용자 지정 카운터 생성

그러나 같은 코드가 ASPNET 작업자 프로세스를 통해 실행될 때 "요청 된 레지스트리 액세스가 허용되지 않습니다."라는 오류 메시지가 발생합니다. 이 오류는 카운터 카테고리가 이미 있는지 확인하기 위해 읽기가 완료되면 CalculationsCounterManager 클래스의 44 행에서 발생합니다.

보안 문제까지 서버를 열지 않고도 프로덕션 환경에서 카운터를 만들 수 있도록 충분한 권한을 직원 프로세스 계정에 제공하는 방법을 아는 사람이 있습니까?

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 

답변

3

예, 그것은 가능하지 입니다. 프로덕션 환경에서 잠재적 인 보안/DOS 문제까지 서버를 열지 않고도 작업자 프로세스에 권한을 추가 할 수 없습니다. 설치 관리자 (예 : MSI)는 일반적으로 상승 된 사용 권한으로 실행되며 성능 카운터 범주 및 카운터는 물론 기타 잠긴 개체도 설치/제거합니다.

예 : Windows Installer XML (WiX) has support for Performance Counters ...

관련 문제