473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 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

Jul 21 '05 #1
2 12741
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
PerformanceCounterCategory.Create()
by this:

!! A first chance exception of type 'System.InvalidOperationException'
!! occurred in system.dll
!!
!! Additional information: The Counter layout for the Category specified is
!! invalid, a counter of the type: AverageCount64, AverageTimer32,
!! CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns,
!! CounterMultiTimer100NsInverse, 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
Jul 21 '05 #2
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 CounterCreationData("BDOGet", "Tracks calls to BDOGet
by time interval.", PerformanceCounterType.CountPerTimeInterval32)

CCDC.Add(cptBDOGet)

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

Dim cptBDOGetBase As New CounterCreationData("BDOGetBase", "Tracks calls to
BDOGet by time interval.", PerformanceCounterType.AverageBase)

CCDC.Add(cptBDOGetBase)

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" <fi******@tesco.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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
PerformanceCounterCategory.Create()
by this:

!! A first chance exception of type 'System.InvalidOperationException'
!! occurred in system.dll
!!
!! Additional information: The Counter layout for the Category specified is !! invalid, a counter of the type: AverageCount64, AverageTimer32,
!! CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns,
!! CounterMultiTimer100NsInverse, 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

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: alien2_51 | last post by:
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...
8
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the...
3
by: john | last post by:
I don't want to know what the CPU utilization is right now. I want to get the average utilization over the last, for example, hour. So I came up with a method where I would get a Process object...
1
by: jimbo | last post by:
Here is my problem. I'm creating an Instrumentation class that will use previously created Performance Categories and Counters in order to time various processes (ie. query duration etc.). This...
2
by: Peter Kirk | last post by:
Hi I would like some general pointers about monitoring some performance parameters of an application we have written. For example: how many threads it has currently running, how long the threads...
2
by: Michiel | last post by:
Hello, I'm creating an application which uses PerformanceCounters, and when I specify a machinename in my domain that isn't connected yet ("Access is denied"), I want to connect to it at that...
2
by: Brad B. | last post by:
I am trying to enforce a licence for my web application based on the number of active sessions. Each time a new user accesses the app, I want to check this to see if over the limit. ...
21
by: Willie jan | last post by:
place this behind a button that fills a listbox. as you will see the time is now and then 0 or filled in???????????? by hitting the button. is there a way to determine the real elapsed time? ...
1
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Hi, I am creating an array of performancecounter objects and wondering if it is possible to sort this array according to category Names. I tried Array.Sort(AllCountersCategories) but it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.