Solved

PerformanceCounter CategoryName CounterName

Posted on 2004-08-16
7
3,757 Views
Last Modified: 2012-05-05
QUESTION 1.) BEGIN
The System.Diagnostics.PerformanceCounter has two properties one called CategoryName and one called CounterName.  I can not seem to find a list on the web or else where as to all the possible strings that I may use for CategoryName as well as all the possible strings that I may use for CounterName with each specified CategoryName.

I know that this is valid
performanceCounter1.CategoryName = "Network Interface";
performanceCounter1.CounterName = "Bytes Received/sec";

Can someone provide a link or other resource as to where I can obtain a list and description for all the possible CategoryNames and CounterNames?

QUESTION 1.) END



Question 2.) BEGIN

//I understand this have no question about it...it is a private variable of a form
private System.Diagnostics.PerformanceCounter performanceCounter1;

//This is contained in the private void InitializeComponent() which is
//Windows Form Designer generated code
this.performanceCounter1 = new System.Diagnostics.PerformanceCounter();

//I don't understand this line...also contained in InitializeComponent()
//Can you explain it?
((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).BeginInit();

//I understand this...also contained in InitializeComponent()
this.performanceCounter1.CategoryName = "Network Interface";
this.performanceCounter1.CounterName = "Bytes Received/sec";

//I don't understand this
///can you explain it?...also contained in InitializeComponent()
((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).EndInit();

QUESTION 2.) END

QUESTION 3.) BEGIN
I was looking at the above code which I found on the internet and was a little confused.  It seems as though someone dropped a PerformanceCounter onto the mainform but I don't seem to have it in my component list.  How can I go about adding that component to my list?

If I am not using a form...for instance I am just using a class is a PerfomanceCounter declared and initialized in the same way?
QUESTION 3.) END


Questions 2 and Questions 3 may be newbiew questions but I'm in the process of converting from C++ to C# and have been overwhelmed but very pleased as to the large number of classes.  By the way I love the properties and indexer features.

Also this is somewhat related to
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21094139.html

Maybe someone that knows the answer to this question can also answer it...it is also 500 points.
0
Comment
Question by:PerryDK
  • 4
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
ErikPhilips earned 400 total points
ID: 11817845
(I have not coded these classes for myself, I'm not 100% sure)
Answer 1:  
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsPerformanceCounterClassTopic.asp
I'm pretty sure these values can be anything you want.  They are used to lookup values when a PerformanceCounter is reading data to understand what the data is associated with.
You can find some of these values in the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib

Answer 2:
It appears that whoever wrote that code is making sure that the BeginInit() and EndInit() methods are called to the ISupportInitialize inherited class.  I believe this would work as well, HOWEVER, if IComponent in the future had the methods BeginInit() and EndInit() created, I would imagine the runtime engine would not know which methord to run (This should be possible, but I'm not sure).
this.performanceCounter1.BeginInit();

Because this class can both read counters and publish counters, if you want to become a publisher, you need to create the class (i would recommend reading the constructor and creating your performance counters appropriately), tell it you need to initialize some of the published information, update this information, and end the initialization, reassociating the performance counters with the system with the correct information.

Answer 3: I don't know.  I'm not a fan of using non visual components on "forms".
0
 
LVL 4

Author Comment

by:PerryDK
ID: 11817907
ErikPhilips:

Answer 1...yes you can create your own categorys and your own counternames but I was looking for a list of categories and counternames that would be specific to the .NET articheture.  If there is nothing specific I would at least like all available categories for windows xp specific machines.  The link you specified mentions some of the categories but I would really like a list of all categories that can be used on windows machines.

Answer 2...?

Answer 3...?

I don't care so much about questions 2 and 3, but question 1 is my biggest concern...if you can answer that one and nothing else I will award all the points.
0
 
LVL 4

Expert Comment

by:ErikPhilips
ID: 11817930
I'm not actually looking for the points, and I would rather see this here for 3-4 days before I was awarded the points.  Did you look at the registry entry I posted in my previous post?  (i might be in a subkey)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib
within a subkey (mine was 009, i don't know why)
should be two String Values [Counter] and [Help].  Each are CRLF delmited with and ID the text.  Counter containing the Counter Name, and the Help being the description of the name.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 4

Expert Comment

by:ErikPhilips
ID: 11817963
Answer 2 more detail:

If you look at the help for System.Diagnostics.PerformanceCounter, you'll notice that it is inheriting properties from two "classes" (Component, ISupportInitialize).  I guess if its possible for these two classes had overlapping methods (methods with the same name), then how would you call that method (with the same name) for that inherited class?  That answer is scoping your variable as the class you want to call the method for.

Answer 3 more detail:

When you build a Windows Application, it will most of the time have controls/components (Form, Button, Textbox), these are visual components.  In other languages I use, it's possible to create a component that is not visual, its has no user interaction, but can be instantiated on executing by dropping a component onto the form.

My personal preferance is not to place non-visual components onto visual components.
0
 
LVL 3

Assisted Solution

by:bigjim2000
bigjim2000 earned 100 total points
ID: 11818211
Here is a link to get all categories/counters on your machine:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskretrievingallcountersincategory.asp

I don't think I can answer your question 2.

As for question 3, yes, you can create these performance counters programmatically and they will work just fine.

-Eric
0
 
LVL 4

Author Comment

by:PerryDK
ID: 11825957
I still could not find a link with all the information that I had wanted.  The registery does contain some of these values but I'm not sure if it contains all of them.  At any rate I decided to write a program that retrieved all of the information for me.  It does contain a lot of redudent data but was the only way I could figure out how to get all information.  Maybe I could clean it up and post it in xml formation...maybe someday.  

At any rate I have included the code and a "very very small" snippet of the output

***CODE***
StringBuilder sb = new StringBuilder();
foreach(PerformanceCounterCategory category
    in
    PerformanceCounterCategory.GetCategories()
)
{
  sb.Append(category.CategoryName + "\r\n");

  sb.Append("\t***COUNTERS***\r\n");
  try
  {
    foreach(PerformanceCounter counter in category.GetCounters())
    {
      sb.Append("\t\t" + counter.CounterName + "\r\n");
      if(counter.CounterHelp != "")
      {
        sb.Append("\t\t\tDescription: " + counter.CounterHelp + "\r\n");
      }
    }
  }
  catch{}

  sb.Append("\t***INSTANCES***\r\n");
  try
  {
    foreach(string instanceName in category.GetInstanceNames())
    {
      sb.Append("\t\t" + instanceName + "\r\n");

      sb.Append("\t\t***COUNTERS FOR THIS INSTANCE***\r\n");
      try
      {
        foreach(PerformanceCounter counter in category.GetCounters(instanceName))
        {
          sb.Append("\t\t\t" + counter.CounterName + "\r\n");
          if(counter.CounterHelp != "")
          {
            sb.Append("\t\t\t\tDescription: " + counter.CounterHelp + "\r\n");
          }
        }
      }
      catch{}
    }
  }
  catch{}
  sb.Append("\r\n");
}
richTextBox1.Text = sb.ToString();
***END CODE***

***OUTPUT SNIPPET***
Network Interface
      ***COUNTERS***
      ***INSTANCES***
            MS TCP Loopback interface
            ***COUNTERS FOR THIS INSTANCE***
                  Bytes Total/sec
                        Description: Bytes Total/sec is the rate at which bytes are sent and received over each network adapter, including framing characters. Network Interface\\Bytes Received/sec is a sum of Network Interface\\Bytes Received/sec and Network Interface\\Bytes Sent/sec.
                  Packets/sec
                        Description: Packets/sec is the rate at which packets are sent and received on the network interface.
                  Packets Received/sec
                        Description: Packets Received/sec is the rate at which packets are received on the network interface.
                  Packets Sent/sec
                        Description: Packets Sent/sec is the rate at which packets are sent on the network interface.
                  Current Bandwidth
                        Description: Current Bandwidth is an estimate of the current bandwidth of the network interface in bits per second (BPS).  For interfaces that do not vary in bandwidth or for those where no accurate estimation can be made, this value is the nominal bandwidth.
                  Bytes Received/sec
                        Description: Bytes Received/sec is the rate at which bytes are received over each network adapter, including framing characters. Network Interface\\Bytes Received/sec is a subset of Network Interface\\Bytes Total/sec.
                  Packets Received Unicast/sec
                        Description: Packets Received Unicast/sec is the rate at which (subnet) unicast packets are delivered to a higher-layer protocol.
                  Packets Received Non-Unicast/sec
                        Description: Packets Received Non-Unicast/sec is the rate at which non-unicast (subnet broadcast or subnet multicast) packets are delivered to a higher-layer protocol.
                  Packets Received Discarded
                        Description: Packets Received Discarded is the number of inbound packets that were chosen to be discarded even though no errors had been detected to prevent their delivery to a higher-layer protocol.  One possible reason for discarding packets could be to free up buffer space.
                  Packets Received Errors
                        Description: Packets Received Errors is the number of inbound packets that contained errors preventing them from being deliverable to a higher-layer protocol.
                  Packets Received Unknown
                        Description: Packets Received Unknown is the number of packets received through the interface that were discarded because of an unknown or unsupported protocol.
                  Bytes Sent/sec
                        Description: Bytes Sent/sec is the rate at which bytes are sent over each each network adapter, including framing characters. Network Interface\\Bytes Sent/sec is a subset of Network Interface\\Bytes Total/sec.
                  Packets Sent Unicast/sec
                        Description: Packets Sent Unicast/sec is the rate at which packets are requested to be transmitted to subnet-unicast addresses by higher-level protocols.  The rate includes the packets that were discarded or not sent.
                  Packets Sent Non-Unicast/sec
                        Description: Packets Sent Non-Unicast/sec is the rate at which packets are requested to be transmitted to non-unicast (subnet broadcast or subnet multicast) addresses by higher-level protocols.  The rate includes the packets that were discarded or not sent.
                  Packets Outbound Discarded
                        Description: Packets Outbound Discarded is the number of outbound packets that were chosen to be discarded even though no errors had been detected to prevent transmission. One possible reason for discarding packets could be to free up buffer space.
                  Packets Outbound Errors
                        Description: Packets Outbound Errors is the number of outbound packets that could not be transmitted because of errors.
                  Output Queue Length
                        Description: Output Queue Length is the length of the output packet queue (in packets). If this is longer than two, there are delays and the bottleneck should be found and eliminated, if possible. Since the requests are queued by the Network Driver Interface Specification (NDIS) in this implementation, this will always be 0.
***END OUTPUT SNIPPET***
0
 
LVL 4

Expert Comment

by:ErikPhilips
ID: 11826040
SHOOOOT!!! Wouldn't you know I'd find the answer!!!

[The procedures in this walkthrough take you through the process of creating and configuring PerformanceCounter component instances and using them to retrieve lists of performance counter categories and counters on your system.]

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughinstrumentingperformancethreshholds.asp

(also contains C# examples)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now