PerformanceCounters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alien2_51

    PerformanceCounters

    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 CountPerTimeInt erval32 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.Collecti ons

    Imports System.Collecti ons.Specialized

    Imports System.Diagnost ics

    Imports MNCAppServices

    Public Class Collector

    Private pcCategory As PerformanceCoun terCategory

    Private pcBDOGet As PerformanceCoun ter

    Private pcBDOGetBase As PerformanceCoun ter

    Private pcBDOSave As PerformanceCoun ter

    Private pcBDOSaveBase As PerformanceCoun ter

    Sub New()

    SetupCategory()

    End Sub

    Private Function SetupCategory() As Boolean

    Try

    If Not PerformanceCoun terCategory.Exi sts("MNC BDO Statistics") Then

    Dim CCDC As New CounterCreation DataCollection

    'create counters

    Dim cptBDOGet As New CounterCreation Data("BDOGet", "Tracks calls to BDOGet
    by time interval.", PerformanceCoun terType.CountPe rTimeInterval32 )

    CCDC.Add(cptBDO Get)

    Dim cptBDOGetBase As New CounterCreation Data("BDOGetBas e", "Tracks calls to
    BDOGet by time interval.", PerformanceCoun terType.Average Base)

    CCDC.Add(cptBDO GetBase)

    Dim cptBDOSave As New CounterCreation Data("BDOSave", "Tracks calls to
    BDOSave by time interval.", PerformanceCoun terType.CountPe rTimeInterval32 )

    CCDC.Add(cptBDO Save)

    Dim cptBDOSaveBase As New CounterCreation Data("BDOSaveBa se", "Tracks calls
    to BDOGet by time interval.", PerformanceCoun terType.Average Base)

    CCDC.Add(cptBDO SaveBase)

    ' Create the category.

    PerformanceCoun terCategory.Cre ate("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.LogExce ption(ex)

    Return False

    End Try

    End Function 'SetupCategory

    Private Sub CreateCounters( )

    ' Create the counters.

    pcBDOGet = New PerformanceCoun ter("MNC BDO Statistics", "BDOGet",
    "CustomerContac t", False)

    pcBDOGet.ReadOn ly = False

    pcBDOGet.RawVal ue = 0

    pcBDOGetBase = New PerformanceCoun ter("MNC BDO Statistics", "BDOGetBase ",
    "CustomerContac t", False)

    pcBDOGetBase.Re adOnly = False

    pcBDOGetBase.Ra wValue = 0

    pcBDOSave = New PerformanceCoun ter("MNC BDO Statistics", "BDOSave",
    "CustomerContac t", False)

    pcBDOSave.ReadO nly = False

    pcBDOSave.RawVa lue = 0

    pcBDOSaveBase = New PerformanceCoun ter("MNC BDO Statistics", "BDOSaveBas e",
    "CustomerContac t", False)

    pcBDOSaveBase.R eadOnly = False

    pcBDOSaveBase.R awValue = 0

    End Sub 'CreateCounters

    Private Sub GetCountersRef( )

    ' Create references to counters.

    Dim objCnt As PerformanceCoun ter

    For Each objCnt In pcCategory.GetC ounters

    Select Case objCnt.CounterN ame

    Case Is = "BDOGet"

    pcBDOGet = objCnt

    pcBDOGet.ReadOn ly = False

    Case Is = "BDOGetBase "

    pcBDOGetBase = objCnt

    pcBDOGetBase.Re adOnly = False

    Case Is = "BDOSave"

    pcBDOSave = objCnt

    pcBDOSave.ReadO nly = False

    Case Is = "BDOSaveBas e"

    pcBDOSaveBase = objCnt

    pcBDOSaveBase.R eadOnly = False

    End Select

    Next

    End Sub 'CreateCounters

    Private Sub GetCountersRef( ByVal InstanceName As String)

    ' Create references to counters.

    Dim objCnt As PerformanceCoun ter

    For Each objCnt In pcCategory.GetC ounters(Instanc eName)

    Select Case objCnt.CounterN ame

    Case Is = "BDOGet"

    pcBDOGet = objCnt

    pcBDOGet.ReadOn ly = False

    Case Is = "BDOGetBase "

    pcBDOGetBase = objCnt

    pcBDOGetBase.Re adOnly = False

    Case Is = "BDOSave"

    pcBDOSave = objCnt

    pcBDOSave.ReadO nly = False

    Case Is = "BDOSaveBas e"

    pcBDOSaveBase = objCnt

    pcBDOSaveBase.R eadOnly = False

    End Select

    Next

    End Sub

    Private Sub GetCategoryRef( )

    Dim objCategory As PerformanceCoun terCategory

    For Each objCategory In PerformanceCoun terCategory.Get Categories

    If objCategory.Cat egoryName = "MNC BDO Statistics" Then

    pcCategory = objCategory

    End If

    Next

    End Sub

    Public Sub IncrementSaveCo unter(ByVal InstanceName As String)

    If pcCategory.Inst anceExists(Inst anceName) Then

    GetCountersRef( InstanceName)

    pcBDOSave.Incre ment()

    End If

    End Sub

    Public Sub IncrementGetCou nter(ByVal InstanceName As String)

    If pcCategory.Inst anceExists(Inst anceName) Then

    GetCountersRef( InstanceName)

    pcBDOGet.Increm ent()

    End If

    End Sub

    End Class 'App



  • Fergus Cooney

    #2
    Re: PerformanceCoun ters

    Hi Dan,

    I've left this for a couple of days hoping that someone would come through
    for you.

    I tried your code on my system but got stopped at
    PerformanceCoun terCategory.Cre ate()
    by this:

    !! A first chance exception of type 'System.Invalid OperationExcept ion'
    !! occurred in system.dll
    !!
    !! Additional information: The Counter layout for the Category specified is
    !! invalid, a counter of the type: AverageCount64, AverageTimer32,
    !! CounterMultiTim er, CounterMultiTim erInverse, CounterMultiTim er100Ns,
    !! CounterMultiTim er100NsInverse, RawFraction, SampleFraction or
    !! SampleCounter has to be immediately followed by any of the base counter
    !! types : AverageBase, MultiBase, RawBase or SampleBase.

    That prevented me from any further investigation, I'm afraid.

    Did you set anything up manually beforehand ? What does your system know
    that mine doesn't, I wonder. (I'm running v2002, .NET 1.0.)

    Regards,
    Fergus


    Comment

    • alien2_51

      #3
      Re: PerformanceCoun ters

      Thanks for your reply,

      I too recieved that same error I was able to rectify the problem by adding a
      call like so:

      This call sets up the counter:
      Dim cptBDOGet As New CounterCreation Data("BDOGet", "Tracks calls to BDOGet
      by time interval.", PerformanceCoun terType.CountPe rTimeInterval32 )

      CCDC.Add(cptBDO Get)

      This call sets up the base counter, whatever that is...

      Dim cptBDOGetBase As New CounterCreation Data("BDOGetBas e", "Tracks calls to
      BDOGet by time interval.", PerformanceCoun terType.Average Base)

      CCDC.Add(cptBDO GetBase)

      After doing this it seemed to setup the counter correctly....

      I think my main problem here was I was always creating new counter rather
      than getting a reference to the existing ones, this is why I figured my
      counters never had data, because the were always new...



      "Fergus Cooney" <filter-1@tesco.net> wrote in message
      news:%23LZHt7Al DHA.2364@TK2MSF TNGP11.phx.gbl. ..[color=blue]
      > Hi Dan,
      >
      > I've left this for a couple of days hoping that someone would come[/color]
      through[color=blue]
      > for you.
      >
      > I tried your code on my system but got stopped at
      > PerformanceCoun terCategory.Cre ate()
      > by this:
      >
      > !! A first chance exception of type 'System.Invalid OperationExcept ion'
      > !! occurred in system.dll
      > !!
      > !! Additional information: The Counter layout for the Category specified[/color]
      is[color=blue]
      > !! invalid, a counter of the type: AverageCount64, AverageTimer32,
      > !! CounterMultiTim er, CounterMultiTim erInverse, CounterMultiTim er100Ns,
      > !! CounterMultiTim er100NsInverse, RawFraction, SampleFraction or
      > !! SampleCounter has to be immediately followed by any of the base[/color]
      counter[color=blue]
      > !! types : AverageBase, MultiBase, RawBase or SampleBase.
      >
      > That prevented me from any further investigation, I'm afraid.
      >
      > Did you set anything up manually beforehand ? What does your system[/color]
      know[color=blue]
      > that mine doesn't, I wonder. (I'm running v2002, .NET 1.0.)
      >
      > Regards,
      > Fergus
      >
      >[/color]


      Comment

      Working...