473,465 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Create 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
Jul 21 '05 #1
1 3275
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

Jul 21 '05 #2

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

Similar topics

0
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
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
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...
1
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
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
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
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
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
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,...
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
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...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.