.NET CLR Networking PerformanceCounter

A

Alain Dekker

Hi,

I'm trying to get some diagnostic information about the number of threads in
the system and the bytes sent / received. The number of threads work, but
not the "Bytes Received" (or sent).

// Number of threads in the computer
PerformanceCounter1.CategoryName = "System";
PerformanceCounter1.CounterName = "Threads";

// Bytes received
PerformanceCounter2.CategoryName = ".NET CLR Networking";
PerformanceCounter2.CounterName = "Bytes Received";
PerformanceCounter2.InstanceName = "_global_";

Both PerformanceCounter classes get called with "RawValue". Threads works
fine. Open and close processes, and you can see the number move nicely.
Bytes received is always 0, no exception occurs. Any idea why the bytes
received does not work? Is there a better PerformanceCounter to use (after
discovering these PerformanceCounter classes this week, I've been trying a
lot of them out!).

Thanks,
Alain

PS: The full code if you wanted to try it out, with my variable names - no
comment on those required - is given below:

using System.Diagnostics;

// ...

private PerformanceCounter m_pcSys_Threads;
private PerformanceCounter m_pcSys_BytesReceived;

// ...


// Threads
// Number of threads in the computer
m_pcSys_Threads = new System.Diagnostics.PerformanceCounter();
((ISupportInitialize)(this.m_pcSys_Threads)).BeginInit();
m_pcSys_Threads.CategoryName = "System";
m_pcSys_Threads.CounterName = "Threads";
((ISupportInitialize)(this.m_pcSys_Threads)).EndInit();

// Bytes received
// Cumulative total bytes received over all open socket connections
m_pcSys_BytesReceived = new System.Diagnostics.PerformanceCounter();
((ISupportInitialize)(this.m_pcSys_BytesReceived)).BeginInit();
m_pcSys_BytesReceived.CategoryName = ".NET CLR Networking";
m_pcSys_BytesReceived.CounterName = "Bytes Received";
m_pcSys_BytesReceived.InstanceName = "_global_";
((ISupportInitialize)(this.m_pcSys_BytesReceived)).EndInit();

// ...

lblThreads.Text = m_pcSys_Threads.RawValue.ToString();
lblBytesReceived.Text = m_pcSys_BytesReceived.RawValue.ToString();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top