A
alien2_51
I'm having issues getting some custom performance counters to work.. Here's
what I'm trying to do...
I want to create one category with two CountPerTimeInterval32 counters,
which represent an interface.. For each implementation I want to add a new
instance for both counters so each implementation can be tracked
seperately.. The category and counters (minus the instances) show up in the
in the performance object, although the bases do not. When I try to
increment the counters nothing shows up, here is my implementation, please
help...
TIA,
Dan B
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics
Imports MNCAppServices
Public Class Collector
Private pcCategory As PerformanceCounterCategory
Private pcBDOGet As PerformanceCounter
Private pcBDOGetBase As PerformanceCounter
Private pcBDOSave As PerformanceCounter
Private pcBDOSaveBase As PerformanceCounter
Sub New()
SetupCategory()
End Sub
Private Function SetupCategory() As Boolean
Try
If Not PerformanceCounterCategory.Exists("MNC BDO Statistics") Then
Dim CCDC As New CounterCreationDataCollection
'create counters
Dim cptBDOGet As New CounterCreationData("BDOGet", "Tracks calls to BDOGet
by time interval.", PerformanceCounterType.CountPerTimeInterval32)
CCDC.Add(cptBDOGet)
Dim cptBDOGetBase As New CounterCreationData("BDOGetBase", "Tracks calls to
BDOGet by time interval.", PerformanceCounterType.AverageBase)
CCDC.Add(cptBDOGetBase)
Dim cptBDOSave As New CounterCreationData("BDOSave", "Tracks calls to
BDOSave by time interval.", PerformanceCounterType.CountPerTimeInterval32)
CCDC.Add(cptBDOSave)
Dim cptBDOSaveBase As New CounterCreationData("BDOSaveBase", "Tracks calls
to BDOGet by time interval.", PerformanceCounterType.AverageBase)
CCDC.Add(cptBDOSaveBase)
' Create the category.
PerformanceCounterCategory.Create("MNC BDO Statistics", "Collects statistics
about Business Data Object Usage.", CCDC)
CreateCounters()
Return True
Else
GetCategoryRef()
GetCountersRef()
Return True
End If
Catch ex As Exception
Utility.LogException(ex)
Return False
End Try
End Function 'SetupCategory
Private Sub CreateCounters()
' Create the counters.
pcBDOGet = New PerformanceCounter("MNC BDO Statistics", "BDOGet",
"CustomerContact", False)
pcBDOGet.ReadOnly = False
pcBDOGet.RawValue = 0
pcBDOGetBase = New PerformanceCounter("MNC BDO Statistics", "BDOGetBase",
"CustomerContact", False)
pcBDOGetBase.ReadOnly = False
pcBDOGetBase.RawValue = 0
pcBDOSave = New PerformanceCounter("MNC BDO Statistics", "BDOSave",
"CustomerContact", False)
pcBDOSave.ReadOnly = False
pcBDOSave.RawValue = 0
pcBDOSaveBase = New PerformanceCounter("MNC BDO Statistics", "BDOSaveBase",
"CustomerContact", False)
pcBDOSaveBase.ReadOnly = False
pcBDOSaveBase.RawValue = 0
End Sub 'CreateCounters
Private Sub GetCountersRef()
' Create references to counters.
Dim objCnt As PerformanceCounter
For Each objCnt In pcCategory.GetCounters
Select Case objCnt.CounterName
Case Is = "BDOGet"
pcBDOGet = objCnt
pcBDOGet.ReadOnly = False
Case Is = "BDOGetBase"
pcBDOGetBase = objCnt
pcBDOGetBase.ReadOnly = False
Case Is = "BDOSave"
pcBDOSave = objCnt
pcBDOSave.ReadOnly = False
Case Is = "BDOSaveBase"
pcBDOSaveBase = objCnt
pcBDOSaveBase.ReadOnly = False
End Select
Next
End Sub 'CreateCounters
Private Sub GetCountersRef(ByVal InstanceName As String)
' Create references to counters.
Dim objCnt As PerformanceCounter
For Each objCnt In pcCategory.GetCounters(InstanceName)
Select Case objCnt.CounterName
Case Is = "BDOGet"
pcBDOGet = objCnt
pcBDOGet.ReadOnly = False
Case Is = "BDOGetBase"
pcBDOGetBase = objCnt
pcBDOGetBase.ReadOnly = False
Case Is = "BDOSave"
pcBDOSave = objCnt
pcBDOSave.ReadOnly = False
Case Is = "BDOSaveBase"
pcBDOSaveBase = objCnt
pcBDOSaveBase.ReadOnly = False
End Select
Next
End Sub
Private Sub GetCategoryRef()
Dim objCategory As PerformanceCounterCategory
For Each objCategory In PerformanceCounterCategory.GetCategories
If objCategory.CategoryName = "MNC BDO Statistics" Then
pcCategory = objCategory
End If
Next
End Sub
Public Sub IncrementSaveCounter(ByVal InstanceName As String)
If pcCategory.InstanceExists(InstanceName) Then
GetCountersRef(InstanceName)
pcBDOSave.Increment()
End If
End Sub
Public Sub IncrementGetCounter(ByVal InstanceName As String)
If pcCategory.InstanceExists(InstanceName) Then
GetCountersRef(InstanceName)
pcBDOGet.Increment()
End If
End Sub
End Class 'App
what I'm trying to do...
I want to create one category with two CountPerTimeInterval32 counters,
which represent an interface.. For each implementation I want to add a new
instance for both counters so each implementation can be tracked
seperately.. The category and counters (minus the instances) show up in the
in the performance object, although the bases do not. When I try to
increment the counters nothing shows up, here is my implementation, please
help...
TIA,
Dan B
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics
Imports MNCAppServices
Public Class Collector
Private pcCategory As PerformanceCounterCategory
Private pcBDOGet As PerformanceCounter
Private pcBDOGetBase As PerformanceCounter
Private pcBDOSave As PerformanceCounter
Private pcBDOSaveBase As PerformanceCounter
Sub New()
SetupCategory()
End Sub
Private Function SetupCategory() As Boolean
Try
If Not PerformanceCounterCategory.Exists("MNC BDO Statistics") Then
Dim CCDC As New CounterCreationDataCollection
'create counters
Dim cptBDOGet As New CounterCreationData("BDOGet", "Tracks calls to BDOGet
by time interval.", PerformanceCounterType.CountPerTimeInterval32)
CCDC.Add(cptBDOGet)
Dim cptBDOGetBase As New CounterCreationData("BDOGetBase", "Tracks calls to
BDOGet by time interval.", PerformanceCounterType.AverageBase)
CCDC.Add(cptBDOGetBase)
Dim cptBDOSave As New CounterCreationData("BDOSave", "Tracks calls to
BDOSave by time interval.", PerformanceCounterType.CountPerTimeInterval32)
CCDC.Add(cptBDOSave)
Dim cptBDOSaveBase As New CounterCreationData("BDOSaveBase", "Tracks calls
to BDOGet by time interval.", PerformanceCounterType.AverageBase)
CCDC.Add(cptBDOSaveBase)
' Create the category.
PerformanceCounterCategory.Create("MNC BDO Statistics", "Collects statistics
about Business Data Object Usage.", CCDC)
CreateCounters()
Return True
Else
GetCategoryRef()
GetCountersRef()
Return True
End If
Catch ex As Exception
Utility.LogException(ex)
Return False
End Try
End Function 'SetupCategory
Private Sub CreateCounters()
' Create the counters.
pcBDOGet = New PerformanceCounter("MNC BDO Statistics", "BDOGet",
"CustomerContact", False)
pcBDOGet.ReadOnly = False
pcBDOGet.RawValue = 0
pcBDOGetBase = New PerformanceCounter("MNC BDO Statistics", "BDOGetBase",
"CustomerContact", False)
pcBDOGetBase.ReadOnly = False
pcBDOGetBase.RawValue = 0
pcBDOSave = New PerformanceCounter("MNC BDO Statistics", "BDOSave",
"CustomerContact", False)
pcBDOSave.ReadOnly = False
pcBDOSave.RawValue = 0
pcBDOSaveBase = New PerformanceCounter("MNC BDO Statistics", "BDOSaveBase",
"CustomerContact", False)
pcBDOSaveBase.ReadOnly = False
pcBDOSaveBase.RawValue = 0
End Sub 'CreateCounters
Private Sub GetCountersRef()
' Create references to counters.
Dim objCnt As PerformanceCounter
For Each objCnt In pcCategory.GetCounters
Select Case objCnt.CounterName
Case Is = "BDOGet"
pcBDOGet = objCnt
pcBDOGet.ReadOnly = False
Case Is = "BDOGetBase"
pcBDOGetBase = objCnt
pcBDOGetBase.ReadOnly = False
Case Is = "BDOSave"
pcBDOSave = objCnt
pcBDOSave.ReadOnly = False
Case Is = "BDOSaveBase"
pcBDOSaveBase = objCnt
pcBDOSaveBase.ReadOnly = False
End Select
Next
End Sub 'CreateCounters
Private Sub GetCountersRef(ByVal InstanceName As String)
' Create references to counters.
Dim objCnt As PerformanceCounter
For Each objCnt In pcCategory.GetCounters(InstanceName)
Select Case objCnt.CounterName
Case Is = "BDOGet"
pcBDOGet = objCnt
pcBDOGet.ReadOnly = False
Case Is = "BDOGetBase"
pcBDOGetBase = objCnt
pcBDOGetBase.ReadOnly = False
Case Is = "BDOSave"
pcBDOSave = objCnt
pcBDOSave.ReadOnly = False
Case Is = "BDOSaveBase"
pcBDOSaveBase = objCnt
pcBDOSaveBase.ReadOnly = False
End Select
Next
End Sub
Private Sub GetCategoryRef()
Dim objCategory As PerformanceCounterCategory
For Each objCategory In PerformanceCounterCategory.GetCategories
If objCategory.CategoryName = "MNC BDO Statistics" Then
pcCategory = objCategory
End If
Next
End Sub
Public Sub IncrementSaveCounter(ByVal InstanceName As String)
If pcCategory.InstanceExists(InstanceName) Then
GetCountersRef(InstanceName)
pcBDOSave.Increment()
End If
End Sub
Public Sub IncrementGetCounter(ByVal InstanceName As String)
If pcCategory.InstanceExists(InstanceName) Then
GetCountersRef(InstanceName)
pcBDOGet.Increment()
End If
End Sub
End Class 'App