Jump to content
  • Advertisement
Sign in to follow this  
kappa

[.net] Using EXISTING performance counters???

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.Diagnostics

Private 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 i

End Sub

Private 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 j
End Sub


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!