473,624 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can not read custom PerformanceCoun ter 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.Diagnost ics.CounterCrea tionDataCollect ion CounterDatas = null;
System.Diagnost ics.CounterCrea tionData cdCounter4 = null;
try
{
if(System.Diagn ostics.Performa nceCounterCateg ory.Exists("Log isOnline"))
{
System.Diagnost ics.Performance CounterCategory .Delete("LogisO nline");
}
// Create a collection of type CounterCreation DataCollection.
CounterDatas = new System.Diagnost ics.CounterCrea tionDataCollect ion();
// Create the counters and set their properties.
cdCounter4 = new System.Diagnost ics.CounterCrea tionData();
cdCounter4.Coun terName = "PaymentsVi ew Response";
cdCounter4.Coun terHelp = "Time in millisecods for Payment View call to
respond";
cdCounter4.Coun terType =
System.Diagnost ics.Performance CounterType.Num berOfItems32;
// Add both counters to the collection.
CounterDatas.Ad d(cdCounter4);
// Create the category and pass the collection to it.
System.Diagnost ics.Performance CounterCategory .Create("LogisO nline", "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.Diagnost ics.Performance Counter = New
System.Diagnost ics.Performance Counter("LogisO nline", "PaymentsVi ew Response",
"_Total", False)
Dim StartTime As DateTime = DateTime.Now
Jul 21 '05 #1
1 3289
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:
PerformanceCoun ter pc = new PerformanceCoun ter("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:
PerformanceCoun ter pc = new PerformanceCoun ter("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.Diagnost ics.CounterCrea tionDataCollect ion CounterDatas = null;
System.Diagnost ics.CounterCrea tionData cdCounter4 = null;
try
{
if(System.Diagn ostics.Performa nceCounterCateg ory.Exists("Log isOnline"))
{
System.Diagnost ics.Performance CounterCategory .Delete("LogisO nline");
}
// Create a collection of type CounterCreation DataCollection.
CounterDatas = new System.Diagnost ics.CounterCrea tionDataCollect ion();
// Create the counters and set their properties.
cdCounter4 = new System.Diagnost ics.CounterCrea tionData();
cdCounter4.Coun terName = "PaymentsVi ew Response";
cdCounter4.Coun terHelp = "Time in millisecods for Payment View call to
respond";
cdCounter4.Coun terType =
System.Diagnost ics.Performance CounterType.Num berOfItems32;
// Add both counters to the collection.
CounterDatas.Ad d(cdCounter4);
// Create the category and pass the collection to it.
System.Diagnost ics.Performance CounterCategory .Create("LogisO nline", "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.Diagnost ics.Performance Counter = New
System.Diagnost ics.Performance Counter("LogisO nline", "PaymentsVi ew Response",
"_Total", False)
Dim StartTime As DateTime = DateTime.Now
.
.
.
Dim TimeTaken As Int32 = DateTime.Now.Su btract(StartTim e).TotalMillise conds
Dim StoreNumber As String = "Some Store"
PCPaymentView.R awValue = TimeTaken
PCPaymentView.I nstanceName = StoreNumber
PCPaymentView.R awValue = TimeTaken
PCPaymentView.D ispose()

A third application reads the performance counters by using the following
code:
PerformanceCoun ter pc = null;
try
{
pc = new PerformanceCoun ter("LogisOnlin e","PaymentsVie w Response","_Tot al");
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
1105
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 custom performance counters WITHOUT instances just fine but when I try to specify instance name then the counter is not updated at all and there is no error thrown also. I've followed MSDN example to specify instance name: // Assumes category...
1
4217
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 Instrumentation class will be used by a variety of "services", so the Categories and Counters to be used within the object must be set during object construction. So I created a class variable array of: private static PerformanceCounter...
0
1529
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 System.Diagnostics.Process.GetProcesses(host) method. I'm noticing that for some running processes, the program is throwing out an exception "Cannot read instance :<processname>". Is this a known issue or could it be solved? For e.g. on getting "% Processor Time"...
1
1793
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() { System.Diagnostics.CounterCreationDataCollection CounterDatas = null; System.Diagnostics.CounterCreationData cdCounter4 = null; try { if(System.Diagnostics.PerformanceCounterCategory.Exists("LogisOnline"))
0
1277
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 CounterCreationDataCollection();
0
1127
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 counter.NextValue()). My testmachine is a Windows 2000 SP4, IE6 SP1, .NET Framework 1.1 SP 1. When I open the Page, the Performance Counter value is displayes as
3
2880
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 PerformanceCounter
0
1534
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. I have a web site built with Commerce Server 2002 and .NET 1.1. I am trying to increment and/or decrement counter values for every session start and
5
8238
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, is that when I look in Perfmon for those counters, the instance name I've passed in has been lowercased. Why would that be? If you look at the Processes counter, it has mixed case instances. Thanks _Mark
0
8233
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8619
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4078
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2604
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 we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.