Frage

I would like to monitor the following system information in my ASP.NET solution:

  • current cpu usage (percent)
  • available memory* (free/total)
  • available disk space (free/total)

*note that I mean overall memory available to the whole system

I tried with windows perfmon (run --> perfmon.msc ) but it seems not to be what I'm searching for. I need something that can tell me the resources load for every function or method called into my application.

Any suggestions are much appreciated.

EDIT: Maybe it could be useful to know how to monitor, with perfmon, the % Process Time cosumed by a single process (for istance w3wp)

EDIT EDIT: I found it! Add new counter --> Process --> % Processor Time on w3wp! THANKS

War es hilfreich?

Lösung

Perfomance counters is my advice. Check out Setting up performance counters for ASP.NET

Beyond performance counters, if you really want to get an 'inside' look at your code, then you can try a memory profiler, such as the following:

Andere Tipps

Performance Counter is the choice if you are wanting it for profiling your application.

However, if you want it as a general purpose system info, then you may want to look at WMI. Here is a sample which I used previously for getting disk info:

Note: You will need a reference to System.Management

Dim scope As ManagementScope = New ManagementScope("\\.\root\CIMV2")
scope.Options.Impersonation = ImpersonationLevel.Impersonate
scope.Options.EnablePrivileges = True

Dim wmiQuery = "SELECT SystemName, Name, VolumeName, Size, FreeSpace FROM Win32_LogicalDisk WHERE DriveType = 3 "
Dim query As ObjectQuery = New ObjectQuery(wmiQuery)
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)

Dim result As New List(Of MyDrive)
For Each systemDrive As ManagementObject In searcher.Get
    Dim diskDrive = New MyDrive
    diskDrive.SystemName = systemDrive("SystemName").ToString
    diskDrive.Name = systemDrive("Name").ToString
    diskDrive.Size = CDec(systemDrive("Size")) / 1073741824
    diskDrive.FreeSpace = CDec(systemDrive("FreeSpace")) / 1073741824
    diskDrive.VolumeName = systemDrive("VolumeName").ToString
    result.Add(diskDrive)
Next

Public Class MyDrive
    Public Property SystemName As String
    Public Property Name As String
    Public Property VolumeName As String
    Public Property Size As Decimal
    Public Property FreeSpace As Decimal
    Public ReadOnly Property PercentFree As Decimal
        Get
            Dim percent As Decimal = 0
            If Size > 0 Then percent = FreeSpace / Size
            Return percent
        End Get
    End Property
End Class

Notice that I have divided the disk space to convert it into GB.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top