# [.net] Using EXISTING performance counters???

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have looked all over for somewhere that tells me how to use windows existing performance counters in .NET but I can only find tutorials of how to add a custom performance counter whitch is not what I whant. I whant to be able to create and read the existing performance counters values. Does anyone know how to do this?

##### Share on other sites
I'll show you a snippet of my code. It was a web for showing a server's perfomance.

I had to remove all the irrelevant pices of code, but I'll hope you still get the point.
The first function shows all the performance categories, the second show the counters (name, value etc.) within a category.

Please let me know if I'm not clear enough.

Imports System.DiagnosticsPrivate Sub ShowPerfCat()  Dim loPerfCat() As PerformanceCounterCategory  Dim lsTextCat() As String  loPerfCat = PerformanceCounterCategory.GetCategories()  ' sort performance categories  ReDim lsTextCat(loPerfCat.Length - 1)  For i As Int32 = 0 To loPerfCat.Length - 1    lsTextCat(i) = loPerfCat(i).CategoryName  Next i  lsTextCat.Sort(lsTextCat)	  ' here we have an perfomance counter category  For i As Int32 = 0 To loPerfCat.Length - 1    Response.Write(lsTextCat(i))  Next iEnd SubPrivate Sub ShowPerfCtr(ByVal CatName As String)  Dim loPerfCat As New PerformanceCounterCategory(CatName)  Dim loPerfCtr() As PerformanceCounter  Dim lsPerfInt() As String = loPerfCat.GetInstanceNames  For j As Int32 = 0 To lsPerfInt.Length - 1    loPerfCtr = loPerfCat.GetCounters(lsPerfInt(j))    For i As Int32 = 0 To loPerfCtr.Length - 1		  ' perfomance counter's name		  Response.Write(loPerfCtr(i).CounterName)		  ' perfomance counter's value      Response.Write(loPerfCtr(i).NextValue.ToString)		  ' perfomance counter's type      Response.Write(loPerfCtr(i).CounterType.ToString)      ' perfomance counter's description      Response.Write(loPerfCtr(i).CounterHelp    Next i  Next jEnd Sub

##### Share on other sites
If you want to update the counter: counters are opened readonly by default.

##### Share on other sites
thx that was what I was looking for.