473,503 Members | 5,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Nov 20 '05 #1
2 1469
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
Nov 20 '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

Nov 20 '05 #3

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

Similar topics

2
12754
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
2767
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
2449
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
4193
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
3127
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
1056
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
1409
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. ...
9
2873
by: pmcguire | last post by:
I have a vb.NET solution with a Windows Application project that contains my user interface and a Class Library project that contains (among other things) a class I call DataAccessComponent. This...
21
4351
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
1263
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
7193
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
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6975
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
7449
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...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.