473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can not read custom PerformanceCounter Instances

I am implimenting Performance counters into a web application.

I use the following code to create the counters during setup:
private void SetupPerfCntrs()
{
System.Diagnostics.CounterCreationDataCollection CounterDatas = null;
System.Diagnostics.CounterCreationData cdCounter4 = null;
try
{
if(System.Diagnostics.PerformanceCounterCategory.E xists("LogisOnline"))
{
System.Diagnostics.PerformanceCounterCategory.Dele te("LogisOnline");
}
// Create a collection of type CounterCreationDataCollection.
CounterDatas = new System.Diagnostics.CounterCreationDataCollection() ;
// Create the counters and set their properties.
cdCounter4 = new System.Diagnostics.CounterCreationData();
cdCounter4.CounterName = "PaymentsView Response";
cdCounter4.CounterHelp = "Time in millisecods for Payment View call to
respond";
cdCounter4.CounterType =
System.Diagnostics.PerformanceCounterType.NumberOf Items32;
// Add both counters to the collection.
CounterDatas.Add(cdCounter4);
// Create the category and pass the collection to it.
System.Diagnostics.PerformanceCounterCategory.Crea te("LogisOnline", "Logis
Online Web Application Metrics", CounterDatas);
}
catch(Exception ex)
{
throw ex;
}
finally
{
CounterDatas = null;
cdCounter4 = null;
}
}

The code used to write to the performance counters are as follows:
Dim PCPaymentView As System.Diagnostics.PerformanceCounter = New
System.Diagnostics.PerformanceCounter("LogisOnline ", "PaymentsView Response",
"_Total", False)
Dim StartTime As DateTime = DateTime.Now
Nov 16 '05 #1
1 1783
I found the problem. A Counter becomes a single instance counter if you write
to it the first time as a single instance.

Using the following constructor creates a single instance counter:
PerformanceCounter pc = new PerformanceCounter("Catagory", "Counter", false)

After you have done this, setting InstanceNames and calling RawValue has no
effect.

To create multi instance counters always use the Constructor with Instamce
Names as below:
PerformanceCounter pc = new PerformanceCounter("Catagory", "Counter",
"_Total", false)

After this, any number of instances can be created as required and
documented everywhere by setting the instance name and setting a rawvalue;

In my case, I was attemting to add instances to counters that have already
been created and where being used by other Performance Counter Instances in
the system.

David B. Taylor

"W1ld0ne74" wrote:
I am implimenting Performance counters into a web application.

I use the following code to create the counters during setup:
private void SetupPerfCntrs()
{
System.Diagnostics.CounterCreationDataCollection CounterDatas = null;
System.Diagnostics.CounterCreationData cdCounter4 = null;
try
{
if(System.Diagnostics.PerformanceCounterCategory.E xists("LogisOnline"))
{
System.Diagnostics.PerformanceCounterCategory.Dele te("LogisOnline");
}
// Create a collection of type CounterCreationDataCollection.
CounterDatas = new System.Diagnostics.CounterCreationDataCollection() ;
// Create the counters and set their properties.
cdCounter4 = new System.Diagnostics.CounterCreationData();
cdCounter4.CounterName = "PaymentsView Response";
cdCounter4.CounterHelp = "Time in millisecods for Payment View call to
respond";
cdCounter4.CounterType =
System.Diagnostics.PerformanceCounterType.NumberOf Items32;
// Add both counters to the collection.
CounterDatas.Add(cdCounter4);
// Create the category and pass the collection to it.
System.Diagnostics.PerformanceCounterCategory.Crea te("LogisOnline", "Logis
Online Web Application Metrics", CounterDatas);
}
catch(Exception ex)
{
throw ex;
}
finally
{
CounterDatas = null;
cdCounter4 = null;
}
}

The code used to write to the performance counters are as follows:
Dim PCPaymentView As System.Diagnostics.PerformanceCounter = New
System.Diagnostics.PerformanceCounter("LogisOnline ", "PaymentsView Response",
"_Total", False)
Dim StartTime As DateTime = DateTime.Now
.
.
.
Dim TimeTaken As Int32 = DateTime.Now.Subtract(StartTime).TotalMilliseconds
Dim StoreNumber As String = "Some Store"
PCPaymentView.RawValue = TimeTaken
PCPaymentView.InstanceName = StoreNumber
PCPaymentView.RawValue = TimeTaken
PCPaymentView.Dispose()

A third application reads the performance counters by using the following
code:
PerformanceCounter pc = null;
try
{
pc = new PerformanceCounter("LogisOnline","PaymentsView Response","_Total");
Messagebox.show(pc.RawValue)
}

All works well except for the final peice of code which throws an exception
stating the the counter is of single instance type. Actual Exception is as
follows:
Counter is single instance, instance name '_Total' is not valid for this
counter category.

Any help would be VERY MUCH Apreciated

Thanks
David Taylor

Nov 16 '05 #2

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

Similar topics

1
3279
by: W1ld0ne74 | last post by:
I am implimenting Performance counters into a web application. I use the following code to create the counters during setup: private void SetupPerfCntrs() {...
0
1097
by: Navin Mishra | last post by:
Hi, I'm having problem adding custom performance counter INSTANCE in an ASP.NET web service whose miltiple instances could run hosted by different IIS AppPools on same machine. I can update my...
1
7231
by: Chris | last post by:
I'm trying to do something really easy: just get the % CPU load. However, I just get mostly 0's sprinkled with an occasional 100. I poked around on the web for info, but all the stuff I found (I...
1
4192
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...
0
1521
by: Christopher Attard | last post by:
Hi, I'm using the PerformanceCounter .NET class to obtain the "% Processor Time" for processes that are running on a remote host. These processes are obtained using the...
0
1269
by: BuddyWork | last post by:
Hello, Can someone please explain why my Instances are not appearing in Perfmon. Here is my code to create the counters. CounterCreationDataCollection CCDC = new...
0
1116
by: Henning Krause [MVP] | last post by:
Hello, I've created a simple website which instantiates a PerformanceCounter object on any existing counter. On the Page_Load() event I set a label to the value of the performancecounter (via...
3
2867
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As...
0
1530
by: supreeth.bhat | last post by:
I created a new Performance Counter Category and added three new counters. Used InstallUtil.exe to create them on remote production server. I can see the custom counter category and counters. ...
5
8224
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... I've got some custom performance counters that can have multiple instances. I use the PerformanceCounter() constructor with the instance name parameter. The thing that puzzles me, though,...
0
7018
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...
0
7182
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
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7397
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...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
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
1430
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 ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
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.